Last active
February 21, 2020 17:50
-
-
Save groupunknown/d307a9ed147e521f44e3a4f26d51a8a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_user_role($id) { | |
$user = new WP_User($id); | |
return array_shift($user->roles); | |
} | |
function verify_user_role_post_status($user_role, $user_id) { | |
if (in_array($user_role, (array) 'subscriber')) { | |
auto_draft_posts_subscriber('draft', $user_id); | |
} else { | |
auto_draft_posts_subscriber('publish', $user_id); | |
} | |
} | |
function auto_draft_posts_subscriber($post_status, $user_id) { | |
global $post; | |
$args = array( | |
'author' => $user_id, | |
'post_type' => 'post', | |
'post_status' => 'any', | |
'orderby' => 'ID', | |
'order' => 'ASC', | |
'posts_per_page' => -1 | |
); | |
$query = new WP_Query($args); | |
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); | |
//echo $post->ID . ', '; | |
wp_update_post(array('ID' => $post->ID, 'post_status' => $post_status)); | |
endwhile; endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment