I'm using Drupal 7 + Rules. I would like to create a rule that unpublishes all nodes authored by a user when they have been given a particular role.
- EVENT - After updating an existing user account
- CONDITION - User has role(s): SelectedRole
- ACTION - ???
BONUS: If this could be limited to nodes of a certain type, that would be even better.
If there is a better way outside of Rules to do this, I'm open to other ideas.
Thanks so much!
You can create a custom ruleset to loop through the nodes or a Views Bulk Operation action.
An easiest option is to add a custom PHP function on your rule (PHP > Execute custom PHP code). Of course you have to enable the php filter core module if you didn't already.
In the PHP action you have to get all the nids of the published nodes the current user and loop through them to unpublish them. I will use the EntityFieldQuery API class but you can use the database functions also.
I would also suggest to add one more Condition for the user before the one you are using: User Has Roles: (NOT) SelectedRole so that the action do not run everytime the user profile is updated.
References: