doufan3958 2014-09-12 21:17
浏览 86

在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!

  • 写回答

1条回答 默认 最新

  • dongxiezhuo8852 2014-09-13 09:20
    关注

    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 );
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog