1

How can I unpublish a certain user's content when a certain rule triggers?

3 Answers 3

1

Here is a summary of what you'll need to get it to work using the Rules module:

  1. Keep track of all node IDs of a user that need to be unpublished later on (= "when a certain rule triggers"). For this add an entity reference to the user's profile (multiple values allowed). And each time a node gets saved, you need to add the reference to that node as an extra value in this entity reference field (= Rule 1). So basically this is the "queue" of nodes for a user that need "post processing" after your "certain rule triggers". It is will serve as your entry point starting from the user's id to "access (find) the exact node ids again later on".

  2. Create a Rules component (= Rule 2, though of type "component") with parameter just a "node id". All this Rules component has to do, is to "unpublish" the node indicated in the parameter. But you can add any Rules "Conditions" also if you'd need any (already now or later on if requirements change). E.g: only for specific content types or user roles, etc.

  3. Create a rule (= Rule 3) containing a Loop that should be triggered ""when a certain rule triggers". The goal of this rule is to loop over each of the nodes in the reference field from Step 1, and in each iteration of that loop you use an action which is to invoke the Rule Component as detailed in Step 2 (and which uses the node id as a parameter). By using a Rules Component, you'll be able to add any "Conditions" you might need inside the "Loop".

Video tutorials

If you're not familiar (enough/yet) with using Loops in the Rules module, then watch the video about List and loops.

For a video that is fairly similar to what's needed in step 2 and step 3, refer to the 2nd video (= Solution video) about Creating multiple back links. Some more details about how your scenario slightly differs from what is shown in that solution video:

  • You are creating an entity reference to nodes also, but from a user (not a node).
  • You only need the first parameter (= Node to link to) in your Rules component (you don't need the 2nd parameter).
2
  • Thank you for this answer. It will take me some time to work through learning rules well enough to be able to do this, but it does seem like something like this could work.
    – puudutus
    Commented Feb 17, 2016 at 8:46
  • Great! It's really worth the investment to learn Rules ... trust me ... And when you look at the suggested videos, have a look at the entire series ... and/or look at some of my other answers to illustrate all the things you can do with rules. None of them require any (repeat any) custom PHP code ... read: pretty forward to upgrade to D8 also ... Commented Feb 17, 2016 at 8:57
1

The configuration would look like this:

  1. Build a view that, when given a user ID as input, lists all the nodes that that user has posted.
  2. Use view style bulk operations, and select the action unpublished node.
  3. Set up a rule that triggers on user updates. (Is there one? I'm not sure...) As condition, compare the roles before and after user save to see if anything should be unpublished. As an action, let it call the view from.

Use this idea you can do that

1
  • Thank you for your comment. I am not very experienced with rules so I will have to look into this. But this seems like the right way to go.
    – puudutus
    Commented Jan 21, 2016 at 6:59
0

Yes you can Unpublish the user content by Rules Module,

you can do by lot of possibilities, like: if user is deleted then Un publish the content of user, If user is In active then Unpublish the Content of the user.

Hope this one will help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.