以下代码有效。根据米洛的评论,我使用选项名称是错误的。因此,我使用选项中的每个键,并使用数组传递默认值。谢谢你,米洛!:_
register_activation_hook( __FILE__, \'twmm_activate\'); //activate plugin options open activation of plugin
register_deactivation_hook(__FILE__, \'twmm_deactivate\'); //deactivate plugin options open deactivation of plugin
function twmm_activate() {
$defaults_twmm = array(
\'twmm_on_off\' => \'disabled\',
\'twmm_middle_layout_selector\' => \'email\',
\'twmm_permission_lvl\' => \'admin\',
\'twmm_page_title\' => \'We will be back\',
\'twmm_custom_message\' => \'Please check back after some time. <br />Thank you!\',
\'twmm_facebook\' => \'http://facebook.com/techtuft\',
\'twmm_twitter\' => \'http://twitter.com/techtuft\',
);
$options = wp_parse_args(update_option(\'twmm_options\', $defaults_twmm));
}
function twmm_deactivate() {
delete_option(\'twmm_on_off\'); //delete plugin specific options upon deactivation
delete_option(\'twmm_middle_layout_selector\');
delete_option(\'twmm_permission_lvl\');
delete_option(\'twmm_page_title\');
delete_option(\'twmm_custom_message\');
delete_option(\'twmm_facebook\');
delete_option(\'twmm_twitter\');
}