I'm creating a website where user pays to publish posts. If this user membership expires, the role changes from "Subscriber" to "Pending".

I need a code that allows to update all posts to draft if certain user's role is "Pending" and then back to publish if is "Subscriber".

Any suggestions on this problem? I only found this plugin but it's not working.

1 Answer 1


You should be able to use the set_user_role action which is triggered when a user's role is changed. The action function is passed the user's ID, new role, and old role(s). Something like this:

add_action( 'set_user_role', 'wpse161590_set_user_role', 10, 3 );
function wpse161590_set_user_role( $user_id, $role, $old_roles ) {
  if ( 'Pending' == $role ) {
    // set all of the user's posts to Draft
  if ( 'Subscriber' == $role ) {
    // set all of the user's posts to Publish

You may want to consider a custom post status on the off chance that a Subscriber has one or more posts manually set as Drafts when they are switched to Pending - to prevent those posts from being automatically published when the user renews and is switched back to Subscriber.

  • Karpstrucking, I really appreciate your help. From your answer I could understand better how it works and ended up finding a code that applies perfectly to what I needed. Once again, thank you. Commented Sep 18, 2014 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.