简体   繁体   English

更新 Buddypress 用户的 xprofile 输入

[英]Update Buddypress user’s xprofile input

I'd like to update what users insert into 3 specific xprofile fields and store it to the database using sanitize_key (force letters lowercase, remove special characters besides "-" and "_").我想更新用户插入 3 个特定 xprofile 字段的内容,并使用 sanitize_key(强制字母小写,删除“-”和“_”之外的特殊字符)将其存储到数据库中。 The values change the way I want to temporarily when I echo them out, but don't store in the database.当我将它们回显时,这些值会临时改变我想要的方式,但不要存储在数据库中。

Would really appreciate your help!非常感谢您的帮助! Here's what I have so far这是我到目前为止所拥有的

In my functions.php:在我的函数中。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);
  • I've tried switching out 'xprofile_data_before_save for 'xprofile_data_after_save' but it still doesn't work.我试过将“xprofile_data_before_save”换成“xprofile_data_after_save”,但它仍然不起作用。

Your changes are probably being overwritten after the filter hook runs.过滤器挂钩运行后,您的更改可能会被覆盖。 You are directly updating the field.您正在直接更新该字段。 You should be changing the submitted profile data.您应该更改已提交的配置文件数据。 This is the filter hook which includes access to that data:这是过滤器挂钩,其中包括对该数据的访问:

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

So try:所以尝试:

function expertise_tag_functions_before_save( $data ) {

   // make your changes to field values in $data

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM