我想通过单击插件中的按钮来启用和禁用自定义元框。此按钮将在插件的设置页面上。这是我到目前为止所做的:
function wpplugin_settings_page_markup()
{
if(!current_user_can('manage_options'))
{
return;
}
?>
<div class="wrap">
<h1><?php esc_html_e(get_admin_page_title()); ?></h1>
<?php
?>
<form method="post" action="">
<input type="checkbox" id="postcb" name="postcheck" value="Post">
<label id='postcbid' name="labelpostcheck" for='postcb'>
Post
</label>
<input type="submit" value="submit" name="submit_btn">
</form>
</div>
<?php
function cd_meta_box_add()
{
$multi_posts=array('post', 'page');
foreach ($multi_posts as $multi_post) {
add_meta_box(
'my-meta-box-id', //id
'Custom Meta Box', //title
'cd_meta_box_cb', //callback
$multi_post, //post type
'normal', //position
'high' //priority
);
}
}
add_action('add_meta_boxes', 'cd_meta_box_add');
function cd_meta_box_cb()
{
echo'<b> This is Custom meta box </b>';
}
}
此代码不显示meta-box,但我希望仅在选中该复选框时才添加meta-box,而在未选中checkbox时将其删除。谁能帮我实现这一目标?谢谢!