最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to abort a save operation with a WordPress hook?

programmeradmin2浏览0评论

I have a WooCommerce and Dokan website. I wrote a new plugin that is supposed to do some backend form validation on custom fields before performing an insert or update operation. I am having problems using PHP code to abort a save operation when form validation fails. This piece of code taken from this answer is able to abort an INSERT operation

function disable_save( $maybe_empty, $postarr ) {
    $maybe_empty = true;

    return $maybe_empty;
}
add_filter( 'wp_insert_post_empty_content', 'disable_save', 0, 2 );

But it does not work for an update operation.

I even went right into the wp-includes/post.php file and changed the wp_update_post() function to return 0 on the first line, but it does not prevent the update operation from occurring.

How do I gracefully prevent a save operation with a WordPress hook in a WooCommerce + Dokan project?

发布评论

评论列表(0)

  1. 暂无评论