【问题标题】:Update Buddypress user’s xprofile input更新 Buddypress 用户的 xprofile 输入
【发布时间】:2021-02-16 08:55:43
【问题描述】:

我想更新用户在 3 个特定 xprofile 字段中插入的内容,并使用 sanitize_key 将其存储到数据库中(强制字母小写,删除除“-”和“_”之外的特殊字符)。当我回显它们时,这些值会改变我想要临时改变的方式,但不要存储在数据库中。

非常感谢您的帮助!这是我目前所拥有的

在我的functions.php中:

function expertise_tag_functions_before_save() {
  global $bp;
    foreach ($_REQUEST as $field => $value) {
        if ($field == ‘field_24’ || $field == ‘field_26’ || $field == ‘field_27’) {
            $value = sanitize_key( $value );
            $field_label = str_replace(‘field_’, ”, $field);
            xprofile_set_field_data($field_label, $user_id, $value);
    }
  }
};

add_action( ‘xprofile_data_before_save’, ‘expertise_tag_functions_before_save’, 10);
  • 我已尝试将“xprofile_data_before_save”切换为“xprofile_data_after_save”,但仍然无效。

【问题讨论】:

    标签: php wordpress buddypress


    【解决方案1】:

    您的更改可能会在过滤器挂钩运行后被覆盖。 您正在直接更新该字段。您应该更改提交的配置文件数据。 这是包含访问该数据的过滤器挂钩:

    do_action_ref_array( 'xprofile_data_before_save', array( $this ) );
    

    那就试试吧:

    function expertise_tag_functions_before_save( $data ) {
    
       // make your changes to field values in $data
    
    }
    

    【讨论】:

    • 感谢您的意见。当我尝试这样做时,我得到了“未捕获的错误:不在对象上下文中使用 $this”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多