gpt4 book ai didi

Wordpress-取消帖子保存过程

转载 作者:行者123 更新时间:2023-12-02 08:31:08 25 4
gpt4 key购买 nike

当帖子内容包含特定字符串时,我需要中止帖子保存过程,然后向用户显示一条消息。

我找到了显示消息的方法,但没有找到拒绝后期保存的方法。

到目前为止,这就是我所做的

 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;
}

最佳答案

希望这可以帮助您检查帖子内容

function to_err_is_human( $post_id ) {
// If this is just a revision, don't check
if ( wp_is_post_revision( $post_id ) )
return;
$post_content = wp_unslash(!empty($_REQUEST['content']) ? $_REQUEST['content'] : $post_data['content']);
if ($post_content=="abc")
{ add_filter("redirect_post_location", "my_redirect_post_location_filter", 99);}
}
add_action( 'save_post', 'to_err_is_human' );
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;
}

关于Wordpress-取消帖子保存过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20683749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com