Unpublish nodes on expiration

3 replies [Last post]
zareen
Offline
Joined: 03/21/2011
Status: 
Answered

Thanks Leighton for all you do!
I am using Membership suite allowing members to post nodes. I would like all their nodes to automatically unpublish if they allow their membership to expire. I've been searching and searching in forums. I'm guessing this can be done with Rules, probably with Views Bulk Operations in addition. But feeling pretty confused about it.

Loved your video on sending multiple emails using views. Can you point me to any good instructions on how to do it... or maybe even shoot a quick video on how it can be done.

Thanks
Zareen

Leighton Whiting
Offline
Joined: 06/02/2009
zareen, It would be easy to

zareen,

It would be easy to do with a custom module using one of Membership Suite's hooks, but if you want to use Rules or the Web Interface to configure something, I think you will find it a bit more complicated. There is a post here that outlines how to do something like this using Views Bulk Operations: http://groups.drupal.org/node/94379 . I've never used the module, but it seems like it should work.

If you want to go the custom module route (I always build a custom module for every drupal site I develop, just for small things like this), then it would be a lot simpler, just change MYMODULE to your module name, and paste this code into it:

  1. /**
  2.  * Implements hook_ms_membership_expiring().
  3.  */
  4. function MYMODULENAME_ms_membership_expiring($account, $membership, $m_plan) {
  5.   // Set all nodes to unpublished that the account has published
  6.   db_query("UPDATE {node} SET status = %d WHERE uid = %d", 0, $account->uid);
  7. }

Sincerely,
Leighton Whiting

zareen
Offline
Joined: 03/21/2011
I'll give it a try

I've never done a custom module, so I guess it's time to learn! I'll give it a try.

Leighton Whiting
Offline
Joined: 06/02/2009
You just need to make two

You just need to make two files, yourmodule.info and yourmodule.module . The info file is really easy, just put the following in it:

; $Id: $
name = Your Module Name
description = Some custom functions
version = 1.0
core = 6.x

Then in the yourmodule.module file, copy and paste the function in the post above (but put a

  1.  at the top of the file first).
  2.  
  3. Then put both files in a folder called yourmodule, and upload the folder to your sites/all/modules folder. Now you can see your module on the Modules page and Enable it. Now the content should be unpublished when a user's membership expires. It's that simple :)
  4.  
  5. Of course, you can rename the 'yourmodule' to whatever you want. And in the code above, be sure to replace the ALL_CAPS text with the module name as well.
  6.  
  7. Sincerely,
  8. Leighton Whiting

Twitter Feed