0

How can I add a reset button when using the Settings API?

I've have something like this that's storing my defaults:

$slider_options = get_option( 'nextslider_options' );

 /* Define the array of defaults */ 
$defaults = array(
    'width'             => 0,
    'height'            => 0,
    'effect'            => 'fade',
    'bullets'           => 0,
    'arrows'            => 0,
    'slidelength'       => 4000,
    'animationlength'   => 600
);

$slider_options = wp_parse_args( $slider_options, $defaults );

As a boilerplate I've used the Settings Sandbox.

  • What exactly is your problem? Checking for the key of the reset button and deleting the option? – fuxia Oct 15 '12 at 7:37
  • Basically I want to add a 'Reset Options' button that will reset the options to their defaults, and I honestly have no idea how to do so. – bryceadams Oct 15 '12 at 7:39
1

Add a new settings section for the reset button that is called on every tab. In the callback function for the field create the reset button. I would include the submit button here too to get both side by side.

In the validation function delete the whole option if the reset button is present in the request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.