Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
function set_copyright_options() {
    delete_option('ptechsolcopy_notice');
    delete_option('ptechsolcopy_reserved');

    add_option('ptechsolcopy_notice','Copyright ©');
    add_option('ptechsolcopy_reserved','All Rights Reserved');

}
register_activation_hook(__FILE__, 'set_copyright_options');

Hi I use the code to make it plugin default while deactivate and activate plugin .But i need the options to make it using the reset button in the admin side to make it default without deactivate the plugin ?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You could make another function with will (re)set the default option values:

function wpse_91307_set_option_defaults() {
  $options = array(
    'ptechsolcopy_notice'   => 'Copyright ©',
    'ptechsolcopy_reserved' => 'All Rights Reserved'
  );

  foreach ( $options as $option => $default_value ) {
    if ( ! get_option( $option ) ) {
        add_option( $option, $default_value );
    } else {
        update_option( $option, $default_value );
    }
  }
}

Then you could change your set_copyright_options() function into this:

function set_copyright_options() {
  delete_option( 'ptechsolcopy_notice' );
  delete_option( 'ptechsolcopy_reserved' );

  wpse_91307_set_option_defaults( );
}

When you hit the reset button, the only thing you have to do is execute the wpse_91307_set_option_defaults() function.

share|improve this answer
add comment

Use add_menu_page to create the page. In the callback function, add a form with a reset button:

function reset_my_options() {
  add_menu_page( 'Reset Options', 'Reset Options', 'manage_options', 'reset-options', 'reset_option_page' );
}

function reset_option_page() {
if ( isset( $_POST['reset_options'] ) && $_POST['reset_options'] === 'true' ) {

delete_option('ptechsolcopy_notice');
delete_option('ptechsolcopy_reserved');

}
  ?>

  <div class="wrap">
    <h2>Reset options</h2>

    <form action="<?php echo admin_url( 'admin.php?page=reset-options' ); ?>" method="post">
      <input type="submit" value="Click to reset plugin options" style="float:left;" />
      <input type="hidden" name="reset_options" value="true" />
    </form>
  </div>
  <?php
}

You can also add nonces to it for further security.

BTW, you could have use update_option in your plugin activation instead of delete_option and add_option.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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