0
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 ?

2

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.

0

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.

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.