Categories
Apply to

Here’s an updated version of your code that also handles the notification message using the Transients API.

/**
* If post status is pending, set transient containing error message and
* change the redirect location.
* Filters slashed post data just before it is inserted into the database.
*
* @param array $data An array of slashed post data.
* @param array $postarr An array of sanitized, but otherwise unmodified post data.
*
*/
add_filter( ‘wp_insert_post_data’, ‘wpse242399_wp_insert_post_data’, 99, 2 );
function wpse242399_wp_insert_post_data( $data, $postarr ) {
if ( $data[‘post_type’] !== ‘revision’ && $data[‘post_status’] === ‘pending’ ) {

set_transient( get_current_user_id() . ‘_wpse242399_post_pending_notice’,
__( ‘Your post has been submitted for review.’, ‘your-text-domain’ )
);

add_filter( ‘redirect_post_location’, ‘wpse242399_redirect_post_location’, 99 );
}

return $data;
}

Leave a Reply

Your email address will not be published. Required fields are marked *