How do I link a button I created in theme customizer to a function?

I created a button in the theme customizer and I want to use it to execute a function? All I can find is using controls to add theme settings such as CSS and text. Although this button is to clear out all of the settings.

I need it to execute this code:

Read More
   <?php remove_theme_mods() ?>

I basically just need to link them together. Can anyone assist?

*EDIT:*Here is the custom control I created for the button I want to access the remove theme mods function:

function newtheme_customize_reset_control($wp_customize) {
    /**
     * Reset Control
     *
     */
    class newtheme_Customize_reset_Control extends WP_Customize_Control {
        public $type = 'button';

        public function render_content() {
    ?>
        <label>
                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
                                <div>
                                    <a href="#" class="button-secondary upload"><?php _e( 'Reset Settings' ); ?></a>

                            </div>
                    </label>
    <?php
        }
    } 
}
add_action( 'customize_register', 'newtheme_customize_reset_control', 1, 1 );

As stated previously I am hoping to reset all theme mods with this button, although there isn’t much on how to do it.

Here is the code I have added the button and section with:

/**
 * Clear theme mod settings
 *
 * Clears all theme modification options/settings in current theme.
 *
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 * @return void
 */

function newtheme_customize_register_clear_settings( $wp_customize ) {

    $theme = wp_get_theme();

    $wp_customize->add_section( 'newtheme_clear', array(
        'title'      => sprintf( __( '%s Reset settings', 'newtheme' ), $theme->Name ),
        'priority'   => 205,
    ) );

    $wp_customize->add_setting( 'newtheme_clear_settings', array(
        'default'    => newtheme_theme_mod( 'clear_settings' )
    ) );

    $wp_customize->add_control( new newtheme_Customize_reset_Control( $wp_customize, 'newtheme_clear_settings', array(
        'label'      => __( 'Reset all settings back to their defaults. Once this is done it cannot be reversed.', 'newtheme' ),
        'section'    => 'newtheme_clear',
        'settings'   => 'newtheme_clear_settings',
        'type'       => 'button',
        'priority'   => 10
    ) ) );      

        do_action( 'newtheme_customize_clear_settings', $wp_customize );

    return $wp_customize;

}

Related posts

Leave a Reply