之前在上发布了类似的内容https://stackoverflow.com/questions/5007748/modifying-wordpress-post-status-on-publish
这允许您添加一个过滤器,在发布帖子时更改帖子状态。然而,birgire关于Contributor用户的评论可能更符合您的需要。投稿者可以登录并创建帖子,这些帖子在您登录并批准之前不会发布。
add_filter(\'wp_insert_post_data\', \'my_post_data_validator\', \'99\');
function my_post_data_validator($data) {
if ($data[\'post_type\'] == \'post\') {
// If post data is invalid then
$data[\'post_status\'] = \'draft\';
add_filter(\'redirect_post_location\', \'my_post_redirect_filter\', \'99\');
}
return $data;
}
function my_post_redirect_filter($location) {
remove_filter(\'redirect_post_location\', __FILTER__, \'99\');
return add_query_arg(\'my_message\', 1, $location);
}
add_action(\'admin_notices\', \'my_post_admin_notices\');
function my_post_admin_notices() {
if (!isset($_GET[\'my_message\'])) return;
switch (absint($_GET[\'my_message\'])) {
case 1:
$message = \'Invalid post data\';
break;
default:
$message = \'Unexpected error\';
}
echo \'<div id="notice" class="error"><p>\' . $message . \'</p></div>\';
}