Can membership unpublish a post when a subscription expires?

I was wondering if there might be a way to automatically unpublish a post when the post's author's membership subscription expires?

Perhaps using pings?

  • Shawn
    • The Crimson Coder

    I wouldn't recommend doing it that way. "Publish" is a state that affects the date and assorted other meta properties of a post, when what you're really after is more likely the ability to change it's visibility. To that end I'd suggest making the post 'private' instead.

    The code below SHOULD do this 'as is' - though it might require some changes (it hasn't been tested):

    function privatize_posts_from_expired_user($sub_id, $user_id) {
    	global $wpdb;
    		UPDATE $wpdb->posts
    		SET post_status = 'private'
    		WHERE post_author = $user_id
    			AND post_status = 'publish'
    add_action( 'membership_expire_subscription', 'privatize_posts_from_expired_user', 10, 2 );

    For example, it currently ONLY sets posts to private for the current blog. Thus, if they have their own blog, you'll need to iterate through or check it by checking their associated blogs.

  • PC
    • WPMU DEV Initiate

    Hey Chris,

    Thanks for posting on the forums.

    There is no out of the box way to do it once their membership expires as they are still added as a user on your site.

    so you will need to remove them in order to remove their posts (that is when WordPress asks you what to do with the posts of the user)

    Does the code entered by Shawn help ? I hope it does.

    Please advise.

    Cheers, PC

  • ChrisMc
    • Site Builder, Child of Zeus

    Many thanks for the replies and for the code.

    I won't normally want to remove the user or their posts but rather make sure the post in question (it's a kind of profile) is not available for viewing by the public or other users, so making it private would only go half way. (This is in the hope that the user may renew/upgrade and then get the post republished)

    I will give the code a try to see if it works - I assume that it would probably work equally with the status set to draft or pending as for private.

    Many thanks for the support.

  • PC
    • WPMU DEV Initiate

    Hey Chris,

    I am not sure why you are using Membership plugin for this !

    You can use Pro sites plugin and have the authors have their own sites and if they don't pay, you can have the site set to be disabled and they will have to pay again to reinstate the site.

    It has a Pay To Blog module you can use to do it.

    That will be best according to me.

    Cheers, PC

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.