admin管理员组

文章数量:1432205

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?

本文标签: How to abort a save operation with a WordPress hook