1
當發佈內容包含特定字符串,然後顯示一條消息給用戶時,我需要中止後保存過程。WordPress的 - 取消後保存過程
我發現了一種顯示消息的方法,但沒有找到拒絕後保存的方法。
到目前爲止,這裏就是我所做的
add_action("pre_post_update", "checkPost");
function checkPost($post_ID) {
$post = get_post($post_ID);
$postContent = $post->post_content;
if (wp_is_post_revision($post_ID ))
return;
if(preg_match("/bad string/", $postContent) == 1) {
//
// cancel post save
//
// then
add_filter("redirect_post_location", "my_redirect_post_location_filter", 99);
}
}
function my_redirect_post_location_filter($location) {
remove_filter('redirect_post_location', __FUNCTION__, 99);
$location = add_query_arg('message', 99, $location);
return $location;
}
add_filter('post_updated_messages', 'my_post_updated_messages_filter');
function my_post_updated_messages_filter($messages) {
$messages['post'][99] = 'Publish not allowed';
return $messages;
}
感謝,但我原來的代碼已經檢查的內容,我只是在尋找一箇中止更新/插入後的方式 – titiyoyo