admin管理员组文章数量:1418065
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 ?
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 asked Mar 18, 2013 at 10:16 masterzoranmasterzoran 532 silver badges7 bronze badges2 Answers
Reset to default 2You 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.
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
.
本文标签: functionsHow to reset the plugins without deactivate the plugin
版权声明:本文标题:functions - How to reset the plugins without deactivate the plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745250716a2649807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论