【问题标题】:Buddypress hook after xprofile field is updated更新 xprofile 字段后的 Buddypress 挂钩
【发布时间】:2019-10-14 19:24:42
【问题描述】:

当用户更改/编辑 xProfile 字段(宽度 ID 1542)时,我想更新自定义 user_meta 字段。

这个钩子不起作用

    function action_xprofile_data_after_save( $x )
    { 

        print_r($x);

    //    if($field == 1542)
    //    {
    //        update_user_meta($user_id, 'field_1542', 'changed');
    //    }
    }
    add_action( 'xprofile_data_after_save', 'action_xprofile_data_after_save', 10, 1 ); 

【问题讨论】:

    标签: wordpress hook buddypress


    【解决方案1】:

    我相信这种方法适用于在前端和后端进行的编辑。它提供了$user_id:

    function peter_xprofile_data_after_save( $data ) {
    
        if ( $data->field_id == 1542 ) {
    
            update_user_meta( $data->user_id, 'field_1542', 'changed');
    
        }
    }
    add_action( 'xprofile_data_after_save', 'peter_xprofile_data_after_save' );
    

    【讨论】:

      【解决方案2】:

      以上在编辑的情况下工作正常,但当您“清理/删除”字段中的文本时不起作用。你应该使用这样的东西:

      function peter_xprofile_data_after_save( $data ) {
      
          $field_content = bp_get_member_profile_data('field=field_name'); // enter your field name here
      
          if($field_content == '') {
              update_user_meta( $data->user_id, 'field_1542', '' );
          }
      
          if ( $data->field_id == 1542 ) {
              update_user_meta( $data->user_id, 'field_1542', $data->value);
          }
      }
      add_action( 'xprofile_data_after_save', 'peter_xprofile_data_after_save' );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-17
        • 1970-01-01
        • 2012-10-18
        相关资源
        最近更新 更多