我正在使用Facebook页面发布插件,它在metabox submitdiv中添加了一个复选框。我想删除自定义帖子类型的复选框。有没有什么方法可以使用函数来实现这一点?
这是Facebook Page Publish中打印复选框的功能:
/**
* Renders a \'publish to facebook\' checkbox. Renders the box only if
* the current post is a real post, not a page or something else.
*/
function fpp_render_post_button() {
global $post;
$object_access_token = get_option(\'fpp_object_access_token\');
if (!array_pop(get_post_meta($post->ID, \'_fpp_is_published\'))) {
echo \'<label for="fpp_post_to_facebook"><img style="vertical-align:middle; margin:2px" src="\'.FPP_BASE_URL.\'publish_icon.png" alt="\'.__(\'Publish to Facebook\', FPP_TEXT_DOMAIN).\'" /> \'.__(\'Publish to Facebook\', FPP_TEXT_DOMAIN).\' </label><input \'.(((FPP_DEFAULT_POST_TO_FACEBOOK or fpp_get_default_publishing($post)) and !empty($object_access_token)) ? \'checked="checked"\' : \'\').\' type="checkbox" value="1" id="fpp_post_to_facebook" name="fpp_post_to_facebook" \'.(empty($object_access_token) ? \'disabled="disabled"\' : \'\').\' />\';
} else {
echo \'<label for="fpp_post_to_facebook"><img style="vertical-align:middle; margin:2px" src="\'.FPP_BASE_URL.\'publish_icon.png" alt="\'.__(\'Publish to Facebook\', FPP_TEXT_DOMAIN).\'" /> \'.__(\'Post <em>again</em> to Facebook\', FPP_TEXT_DOMAIN).\' </label><input type="checkbox" value="1" id="fpp_post_to_facebook" name="fpp_post_to_facebook" \'.(empty($object_access_token) ? \'disabled="disabled"\' : \'\').\' />\';
}
if (empty($object_access_token)) {
echo \'<div><em style="color:#aa6600">\'.sprintf(__(\'Facebook Page Publish is not set up.<br />Please check your <a href="%s">plugin settings</a>.\', FPP_TEXT_DOMAIN), \'options-general.php?page=\'.plugin_basename(__FILE__)).\'</em></div>\';
}
if ($post->post_status == "private") {
echo \'<div><em style="color:#aa6600">\'.__(\'Private posts are not published\', FPP_TEXT_DOMAIN).\'</em></div>\';
}
echo \'<input type="hidden" name="fpp_send_from_admin" value="1" />\';
$error = get_option(\'fpp_error\');
if (!empty($error)) {
echo \'<div class="error"><strong>\'.sprintf(__(\'Your Facebook Page Publish plugin reports an error. Please check your <a href="%s">plugin settings</a>.\', FPP_TEXT_DOMAIN), \'options-general.php?page=\'.plugin_basename(__FILE__)).\'</strong></div>\';
}
}
最合适的回答,由SO网友:Mamaduka 整理而成
该函数用于渲染按钮,并在内部调用fpp_post_submitbox_start_action()
, 它执行一些条件检查并连接到post_submitbox_start
行动
首先,您需要删除插件的原始操作,并使用自己的带条件渲染按钮。请参见下面的代码示例。
// Remove original action
remove_action( \'post_submitbox_start\', \'fpp_post_submitbox_start_action\' );
/**
* Renders Facebook publish button, if post type is \'post\'
* and current user has \'publish_posts\' capability.
*/
function mamaduka_post_submitbox_start() {
global $post;
if ( \'post\' == get_post_type( $post ) && current_user_can( \'publish_posts\' ) )
fpp_render_post_button();
}
add_action( \'post_submitbox_start\', \'mamaduka_post_submitbox_start\' );
要仅从特定自定义帖子类型中删除复选框,可以更改条件帖子类型检查,如下所示:
if ( \'myposttype\' != get_post_type( $post ) && current_user_can( \'publish_posts\' ) )