在Wordpress中添加多个add_action函数会中断站点

I'm using the following code to update a field value using the Formidable plug-in in Wordpress:

// Order Update Mgmt: Status
add_action('frm_after_create_entry', 'order_mgmt_status', 30, 2);
   function order_mgmt_status($entry_id, $form_id){
      if($form_id == 25){ //change 25 to the ID of your update form
         global $wpdb, $frmdb, $frm_entry_meta;
         $order_id = $_POST['item_meta'][1252]; //change 1252 to the ID of the field containing the primary key
         $new_status = $_POST['item_meta'][1245]; //change 1245 to the ID of the field containing the new data to insert
         $old_status = 368; //change 368 to the ID of field on the master form containing the old data
         $wpdb->update($frmdb->entry_metas, array('meta_value' => $new_status), array('item_id' => $order_id, 'field_id' => $old_status));
     }
  }

This works perfectly with no errors.

However, if I duplicate the code it breaks my WordPress installation (white screen of death). Even though I do the following:

  • Change 'order_mgmt_status' to a new function name
  • And just to test it out, I also commented out the global line, $wpdb->update line, and changed the names of the variables in the duplicated code.
  • I've tested it by doing a new add_action entry for each field to update AND by doing a single add_action entry that calls multiple functions to update each field. Neither of these worked.

Any ideas for a solution would be greatly appreciated!

In that sample function, I'd add a return statement in the end:

return array( $entry_id, $form_id );

so that your following hooks have something to work with.

Other add_action hooks should look very similar:

add_action('frm_after_create_entry', 'another_order_mgmt_status', 35, 2);
function another_order_mgmt_status($entry_id, $form_id){
    // do smth
    return array( $entry_id, $form_id );
}