首先创建一个将打印“发布”按钮的函数:
//function to print publish button
function show_publish_button(){
Global $post;
//only print fi admin
if (current_user_can(\'manage_options\')){
echo \'<form name="front_end_publish" method="POST" action="">
<input type="hidden" name="pid" id="pid" value="\'.$post->ID.\'">
<input type="hidden" name="FE_PUBLISH" id="FE_PUBLISH" value="FE_PUBLISH">
<input type="submit" name="submit" id="submit" value="Publish">
</form>\';
}
}
接下来创建一个函数来更改post状态:
//function to update post status
function change_post_status($post_id,$status){
$current_post = get_post( $post_id, \'ARRAY_A\' );
$current_post[\'post_status\'] = $status;
wp_update_post($current_post);
}
然后确保捕获按钮的提交:
if (isset($_POST[\'FE_PUBLISH\']) && $_POST[\'FE_PUBLISH\'] == \'FE_PUBLISH\'){
if (isset($_POST[\'pid\']) && !empty($_POST[\'pid\'])){
change_post_status((int)$_POST[\'pid\'],\'publish\');
}
}
现在,上述所有代码都可以放入主题的函数中。php文件,您只需添加
show_publish_button();
在每个帖子之后的挂起帖子循环中。