change a post status when users update posts?
-
04-11-2019 - |
Question
Is there an efficient way to change a post status from 'published' to 'draft' when a user of a certain type tries to update their posts. I tried something along these lines
function change_post_status($post_id)
{
if(current_user_can('rolename'))
{
$current_post = get_post( $post_id, 'ARRAY_A' );
$current_post['post_status'] = 'draft';
wp_update_post($current_post);
}
}
add_action('pre_post_update','change_post_status');
The code looks good to me but for some reason it doesnt work properly and I think it creates an endless loop(forcing me to restart my SQL server).
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange