wp_customize = $wp_customize; $wp_customize->add_section( 'customizer_reset', array( 'title' => __( 'Customizer Reset', 'blossom-floral-pro' ), 'priority' => 1999, 'capability' => 'edit_theme_options', ) ); $wp_customize->add_setting( 'theme_reset', array( 'default' => '', 'sanitize_callback' => 'wp_kses_post', ) ); $description = __( '

ATTENTION!!!

', 'blossom-floral-pro' ); $description .= __( '

Please read carefully before you proceed. Please DO NOT use this option on LIVE site.

', 'blossom-floral-pro' ); $description .= __( '

Use this option to reset customizer settings to default value.

', 'blossom-floral-pro' ); $description .= __( '

This process is IRREVERSIBLE and will remove all customizations ever made via customizer till now.

', 'blossom-floral-pro' ); $wp_customize->add_control( new Blossom_Floral_Pro_Customizer_Reset_Control( $wp_customize, 'theme_reset', array( 'label' => __( 'Customizer Reset', 'blossom-floral-pro' ), 'section' => 'customizer_reset', 'description' => $description, ) ) ); } public function ajax_customizer_reset() { if ( ! $this->wp_customize->is_preview() ) { wp_send_json_error( 'not_preview' ); } if ( ! check_ajax_referer( 'blossom-floral-pro-customizer-reset', 'nonce', false ) ) { wp_send_json_error( 'invalid_nonce' ); } $this->set_theme_mod_transient(); $this->reset_customizer(); wp_send_json_success(); } public function reset_customizer() { $settings = $this->wp_customize->settings(); // remove theme_mod settings registered in customizer foreach ( $settings as $setting ) { if ( 'theme_mod' == $setting->type ) { remove_theme_mod( $setting->id ); } } } //Function that saves customizer theme option in transient for 7 days. public function set_theme_mod_transient(){ $theme_mods = get_option( 'theme_mods_blossom-floral-pro' ); if( $theme_mods ) set_transient( 'blossom_floral_pro_theme_mod', $theme_mods, WEEK_IN_SECONDS ); } } } Blossom_Floral_Pro_Customizer_Reset::get_instance();