• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

Move Users Posts To Draft When User Role Changes After Expired Subscription

The code in this tutorial is a extension of the code in this tutorial which enables you to delete the posts of users when their role changes.

When the role of the user is changed to customer ( customer being a custom role ), the status of all posts published by the user will change from published to draft.

So rather than delete the posts when a users subscription expires, this code changes the status of the posts from published to draft.

Here’s the code you can paste at the end of your child themes functions file or in a Must Use plugin.

Register for full access

Demo Video

Shows the test post status changed from published to draft when the user role changes from editor to subscriber ( customer ).

Roles & Capabilities WooCommerce

Reader Interactions

Comments

  1. Paul Matthew says

    May 26, 2022 at 1:53 pm

    Thanks for checking Brad. Does it only work if the user has one role on the site? My users have 3-4 different roles.

    Log in to Reply
    • Brad Dalton says

      May 26, 2022 at 2:17 pm

      I only tested with editor. You can try and see if it works with other roles, it might. You are welcome to order a custom extension of this code to work with CPT’s. I estimate 1 hour of work https://wpsites.net/product/hourly-consulting/

      Log in to Reply
  2. Paul Matthew says

    May 26, 2022 at 3:58 am

    Hi Brad,

    This is exactly what I need, but it’s not working for me.

    Posts should be set to draft is a user has the role called “expired”
    The post type that is called “gd_place”

    Any idea what I need to change in my code?

    Log in to Reply
    • Brad Dalton says

      May 26, 2022 at 6:00 am

      Hi Paul. I re-tested the code and it does exactly as shown in the demo videos, description and/or screenshots. https://youtu.be/rNhjUirS-74

      I also tested it using a CPT and it works as long as the editor is publishing a new single CPT NOT a standard post. To make it work with standard posts when using a CPT requires code modification and testing.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags