In admin/content page we have some update options. I want to execute a Php code only when I use publish selected content or unpublished selected content on that page.

This rules should be fired JUST when I publish/unpublished selected content

  • What do you want to happen if some selected content gets published (or unpublished) without using "admin/content" (eg simply using a node edit form to do so)? Jul 11, 2016 at 14:01

2 Answers 2


You can use drupal's hook_form_alter() for firing your PHP code. Check below example:

function contr_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'node_admin_content'){
    $form['admin']['options']['submit']['#submit'][] = 'CUSTOM_SUBMIT_HANDLER';

and then you can write your PHP code in CUSTOM_SUBMIT_HANDLER function as below:

function CUSTOM_SUBMIT_HANDLER($form, $form_state){
  if($form_state['values']['operation'] == 'publish'){
    // Do your stuff when PUBLISH here.
  }elseif ($form_state['values']['operation'] == 'unpublish') {
    // Do your stuff when UNPUBLISH here.    

You probably need to alter the action performed on publish or unpublish of the node.

Try using hook_action_info_alter to alter the existing actions.


Your Answer

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

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