'The best way to set to draft and add admin notice?
Right now I am checking the saved post for certain conditions. If the conditions fail the post is set to draft and an admin notice is displayed to let the user know what needs to change.
The timing of the hooks require me to do the same or similar functions twice. Once for each hook. I would like to reduce overhead if possible.
When wp_insert_post_data runs, I check the content and if it doesn't pass the checks, it sets it to draft. When admin_notices runs the post status has already been set and is unchangable. Is there a different hook I should be using? Or is there a better way to do this?
There are many other checks being done in the real code. Here is a basic example of what I'm doing:
add_action( 'admin_notices', 'incorrect_content_notices' );
function notice_of_incorrect_content() {
/**
* Do a bunch of conditional checks. These also get done in another hook.
*/
}
add_filter( 'wp_insert_post_data', 'incorrect_content_set_to_draft', 99 );
function incorrect_content_set_to_draft( $post_data ) {
/**
* Do a bunch of conditional checks that were already done in another hook.
*/
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
