Skip to content

Instantly share code, notes, and snippets.

@groupunknown
Last active February 21, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupunknown/d307a9ed147e521f44e3a4f26d51a8a2 to your computer and use it in GitHub Desktop.
Save groupunknown/d307a9ed147e521f44e3a4f26d51a8a2 to your computer and use it in GitHub Desktop.
<?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