我正在写一个插件,它将禁止用户在某些类别中发表文章。我试图向用户显示一条错误消息,当用户试图在受限类别中发布时,我还希望WP不要将相同的内容发布到数据库中。我正在尝试使用save\\u post挂钩来完成此操作。然而,我被困在如何告诉WordPress不要保存这篇文章上。
function buc_validatePostUpdate($post_id) {
global $wpdb, $user_ID;
$buc_values = get_user_meta($user_ID,\'buc_user_cat\');
$buc_final = explode(\',\', $buc_values[0]);
$post_cat = get_the_category($post_id);
foreach($post_cat as $cat) {
if(in_array( $cat->term_id, $buc_final ) !== FALSE) {
}
else {
//At this place, I need to tell WordPress not to update the post and return back.
add_action( \'admin_notices\', \'custom_error_notice\' );
return false;
}
}
}
add_action( \'save_post\', \'buc_validatePostUpdate\' );
function custom_error_notice(){
echo \'<div class="error"><p>Error!!!!</p></div>\';
remove_action( \'admin_notices\', \'custom_error_notice\' );
}
EDIT 1
在进一步搜索时,我在WA. 我不确定是否需要实现类似于此问题中提到的内容。如有任何建议,将不胜感激。提前谢谢。