Adding command button to theme options page
-
Using the Settings API, what is the recommended method for adding a button that once clicked, executes a server side function?
I’m trying to trigger actions such as clearing cache, re-generating stats, building CSS files via a button click. These functions are defined server side.
I’ve already tried adding the html button code and attempted to get the values from the post collection, I’ve also tried to process the keys submitted in the sanitize function specified in register_setting but the key is not present.
Simplified Code (so far):
function mytheme_initialize_theme_options() { /******************* Notifications *******************/ add_settings_section( 'mytheme_options_notifications', 'Notifications', 'mytheme_options_notifications_callback', 'mytheme_options_notifications' ); function mytheme_options_notifications_callback() { echo '<p>Description for notificaation options</p>'; } register_setting('mytheme_options_notifications', 'mytheme_options_notifications', 'mytheme_options_sanitize'); add_settings_field( 'notificationType', 'Notification Type', 'mytheme_options_field_callback', 'mytheme_options_notifications', 'mytheme_options_notifications', array('button', 'notificationType', 'Notification Type', 'Notification Type', '') ); } add_action('admin_init', 'mytheme_initialize_theme_options'); function mytheme_options_sanitize($input) { var_dump($input); die(); } function mytheme_options_field_callback($args) { $options = get_option('mytheme_theme_options'); $value = $options[$args[1]]; switch($args[0]) { case 'button': $html = '<input type="submit" id="'.$args[1].'" name="'.$args[1].'" value="'.$args[2].'" />'; break; } echo $html; }
The button is rendered to the browser on the correct page, and sanitize function is called but the contents of $input is NULL.
What am I missing here?
Thanks in advance
- The topic ‘Adding command button to theme options page’ is closed to new replies.