I need a way to disable the save process completely using an action/filter
. Something that works (for e.g.:) in the query
, posts_clauses
or wp_insert_post/save_post/update_post
hooks.
So far I only tried to return '';
, which gives me tons of errors for missing values for post object parts in the admin UI.
This should happen “silently”, so no errors get thrown when php_error/WP_DEBUG
and such are set to TRUE/On
.
Btw: I’m not asking for how to disable the autosave feature.
Because
wp_insert_post_empty_content
is set to true, WordPress thinks there is no title and no content and stops updating the post.EDIT: An even shorter variant would be:
The reason you get notices for stopping inserts with the
wp_insert_post_empty_content
filter as mentioned in your comment at the https://wordpress.stackexchange.com/a/51980/31794 answer, is that: Forpost-new.php
the auto-draft process needs to get a$post->ID
throughget_default_post_to_edit()
andwp_insert_post()
, and use that ID from the $post return.i.e. The ‘Add New Post’ pages actually creates and gets a new ‘post record’ every time.
Sadly wp_insert_post() return 0 if you stop the save process instead of an expected post ID. In other words, you can’t stop ‘Auto drafts’ with the ‘wp_insert_post_empty_content’ filter. And should you use the filter, you sadly must let “auto-drafts pass through to avoid the PHP Notice. It’s a pretty bad bug.
The only way I have found left to stop creating new auto-draft records pointlessly and go around this bug is, to extend the wpdb class with a db.php Drop-in plugin:
This keeps only one auto-draft per author, and avoids pointless new auto-draft(s) records wasting/skipping id increments for nothing.