I have a custom post that users can use to register their resumes on the website after login. I try this code for set status post after sending by users to "pending" and not showing while Admin change status to "publish". It work but when Admin want to change the status, after publishing that reset to "pending". How I can fix this?
add_filter( 'wp_insert_post_data', 'prevent_post_change', 20, 2 );
function prevent_post_change( $data, $postarr ) {
if ( ! isset($postarr['ID']) || ! $postarr['ID'] ) return $data;
if ( $postarr['post_type'] !== 'noo_resume' )
$old = get_post($postarr['ID']);
if (
$old->post_status !== 'pending' &&
$old->post_status !== 'trash' &&
$data['post_status'] === 'publish'
) {
$data['post_status'] = 'pending';
}
return $data;
}