【问题标题】:Adding multiple add_action functions in Wordpress breaks site在 Wordpress 中断站点中添加多个 add_action 函数
【发布时间】:2014-11-07 03:30:06
【问题描述】:

我正在使用以下代码使用 Wordpress 中的 Formidable 插件更新字段值:

// 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));
     }
  }

这完全没有错误。

但是,如果我复制代码,它会破坏我的 WordPress 安装(死机白屏)。即使我做了以下事情:

  • 将“order_mgmt_status”更改为新的函数名称
  • 为了测试它,我还注释掉了全局行 $wpdb->update 行,并更改了重复代码中的变量名称。
  • 我已经通过为每个字段更新一个新的 add_action 条目并通过调用多个函数来更新每个字段的单个 add_action 条目对其进行了测试。这些都不起作用。

任何解决方案的想法都将不胜感激!

【问题讨论】:

    标签: php wordpress formidable


    【解决方案1】:

    在那个示例函数中,我会在最后添加一个 return 语句:

    return array( $entry_id, $form_id );
    

    以便您的以下钩子可以使用。

    其他 add_action 钩子应该看起来非常相似:

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

    【讨论】:

    • 感谢您的回复!我在“array”之前添加了“return”,这导致了同样的空白白屏问题。
    • 空白屏幕表示某种严重错误。你应该试着弄清楚它是什么。您是否在 wp-config.php 中将 wp_debug 设置为 true?您还可以检查是否在目录树的某处生成了一些 error.log。
    猜你喜欢
    • 2014-02-03
    • 2011-04-05
    • 1970-01-01
    • 2023-02-01
    • 2018-11-04
    • 2015-07-17
    • 2012-10-31
    • 2017-11-06
    • 2021-08-26
    相关资源
    最近更新 更多