esc_html__( 'This will clear the local font cache.', 'olympus-google-fonts' ), 'nonce' => wp_create_nonce( 'ogf_clear_cache' ), ) ); } /** * Store a reference to `WP_Customize_Manager` instance * * @param Object $wp_customize Global $wp_customize object. */ public function customize_register( $wp_customize ) { $this->wp_customize = $wp_customize; $wp_customize->add_control( 'ogf_clear_cache', array( 'type' => 'button', 'label' => __( 'Clear Font Cache', 'olympus-google-fonts' ), 'description' => __( 'This will clear the local font cache.', 'olympus-google-fonts' ), 'settings' => array(), 'priority' => 100, 'section' => 'ogf_debugging', 'input_attrs' => array( 'value' => __( 'Clear Cache', 'olympus-google-fonts' ), 'class' => 'button button-link-delete', ), ) ); } /** * The Clear Cache AJAX request handler. */ public function ajax_customizer_clear_cache() { if ( ! $this->wp_customize->is_preview() ) { wp_send_json_error( 'not_preview' ); } if ( ! check_ajax_referer( 'ogf_clear_cache', 'security' ) ) { wp_send_json_error( 'invalid_nonce' ); } $this->clear(); wp_send_json_success(); } /** * Perform the Cache Clear. */ public function clear() { $fonts = new OGF_Fonts(); if ( $fonts->has_google_fonts() ) { $url = $fonts->build_url(); $url_to_id = md5( $url ); delete_transient( 'ogf_external_font_css_' . $url_to_id ); } if ( class_exists( 'FPP_Host_Google_Fonts_Locally' ) ) { $loader = new FPP_Host_Google_Fonts_Locally(); $loader->delete_fonts_folder(); } } } endif; /* * Instantiate the OGF_Clear_Cache class. */ new OGF_Clear_Cache();