Remove Directory Listings When Membership Expires

Support Access Granted ...

Guys ... I am in a rather frustrated place in trying to make your plugins work in a way that will suit my needs and I genuinely need a custom solution to resolve this.

I am using the Directory plugin to hold a business directory, the facilities within the plugin itself do not allow for expiration when purchasing via credits.

So I thought I would make all listings free if you were in the correct Membership group and use your Membership plugin to achieve this.

So user signs up via Membership+ and is allowed to create a listing as they have paid for an annual Subscription package in Membership+ which moved them to the membership group with these permissions.

When that member then fails to renew their annual subscription Membership moves them back down to the Standard subscriber group meaning they can no longer create Directory listings or edit existing ones etc.

I need two things to happen;

Firstly that if the above happens any listings in their username are placed into draft mode from published to remove them from being visible.

Secondly I would like to restrict the number of Directory listings any one single user can create to just one so they cannot create multiple listings?

Can you advise on how this can be achieved perhaps through a cron job etc?

Im at a loss with it in all honesty.

Thanks

Wayne

  • Michelle Shull

    Hi, Wayne!

    Ultimately, I think this is a custom job, like you suspect. I'm happy to flag the dev with a feature request, if it seems like these features would benefit enough of the members who use Directory, the changes could make it into a future version of Directory.

    Otherwise, this may be best suited for a custom job through our Jobs Board. We can do a lot of customization here on the forum, but what you want is pretty complex, and it would take quite a bit of time to put together.

    A cron job could trigger these actions, but the actions themselves would still need to be coded into Directory, and tested fairly extensively.

    Thanks for your question!

  • aristath

    Hello there @Wayne, I hope you're well today!

    The Membership plugin controls access, it does not by default perform any actions based on that access. These actions will have to be custom-coded as mentioned before.
    The amount of customisations needed to accomplish what you want are beyond the scope of these forums. You will need to hire a developer to do what you need as it is not the default behaviour of the Membership plugin.

    I wrote this little function that will trigger when a membership subscription expires, and it will set the post status of published posts from that specific user from published to draft:

    function change_post_status_on_membership_expire( $sub_id, $user_id ) {
    
    	// Get the posts of the user
    	$query = new WP_Query( 'author=' . $user_id );
    
    	if ( $query->have_posts() ) {
    
    		while ( $the_query->have_posts() ) : $query->the_post();
    			$post = get_post( get_the_ID() );
    			// Change the post's status from published to draft
    			wp_transition_post_status( 'draft', 'publish', $post );
    	}
    
    }
    add_action( 'membership_expire_subscription', 'change_post_status_on_membership_expire', 10, 2 );

    Please note that I have not tested the above, but something like this should work. It's meant as an example of the code that will have to be written.

    You will of course have to write something similar that will take care of the reverse: re-publishing the posts once the user re-subscribes, as well as any other implementations you may need to do.

    If you are not comfortable doing these customizations yourself then please post a new job in our Jobs board on https://premium.wpmudev.org/wordpress-development/ so that a skilled developer can do that for you.

    Cheers,
    Ari.

  • William

    Hi @Wayne

    Did you ever get this working? I would love to see your progress or solutions. :slight_smile:

    I found a plugin to help restrict the number of Directory listings any one single user can create, but have not been able to figure out how to move directory listings from published to draft and back to publish again if a user stops/restarts their membership.

    Plugin: https://wordpress.org/plugins/bainternet-posts-creation-limits/installation/

    I have been playing with the code that @aristath provided above but it keeps throwing syntax errors in my functions file.

    With the code provided above I get this error:
    PHP Syntax Check: Parse error: syntax error, unexpected '}' in your code on line 12

    When I remove the '}' I get even more errors:
    Error: There is 1 more opening curly braces '{' than expected
    { $query = new WP_Query( 'author=' . $user_id ); if ( $query->have_posts() ) { while ( $the_query->have_posts() ) : $query->the_post(); $post = get_post( get_the_ID() ); wp_transition_post_status( 'draft', 'publish', $post ) }
    PHP Syntax Check: Parse error: syntax error, unexpected '}' in your code on line 13

    I agree with you that this should be a standard plugin feature especially when integrating with the Membership Pro plugin. Any thoughts or help from the WPMUDEV team would be greatly appreciated! :slight_smile:

    Thanks,
    William

  • Mark

    Hi, I'd like to chime in here. I started with Directory to get paid listings with the assumption that if an account wasn't paid that the listings would go away. (I was browsing around trying to find the fix to another error (been finding several, in fact, the latest is: "Fatal error: Using $this when not in object context in /page-update-listing.php on line 18")) and then read what Wayne wrote.

    Digging in further, I don't see anything about expiring memberships. Is this true? Listings in Directory don't automatically remove for non-payment? I hope not as that's a show stopper for me.

    Thanks!

    Mark

  • Bojan Radonic

    Hey again guys,

    Sorry for the confusion I made here. After consulting developers on this one it appears that such customization would require a lot of modifications which is a bit beyond the scope of support that we provide. See here : https://premium.wpmudev.org/manuals/using-wpmu-dev/support-vs-custom-development/.

    So @William if the code Ari provided is not working for you since he is no longer working here I'd have to suggest to post a job in our job board where you can hire a developer to assist further.

    @Mark After payment is cancelled, post status should be private. If you have additional questions please open a new thread so we don't flood this one here.

    Have a great day!

    Cheers,
    Bojan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.