BP_REST_XProfile_Update_Endpoint:: update_items (WP_REST_Request美元的请求

更新XProfile。

描述

参数

美元的请求

WP_REST_Request(必需)关于请求的完整数据。

返回

(WP_REST_Response | WP_Error)

文件:bp-xprofile /类/ class-bp-rest-xprofile-update-endpoint.php

public function update_items($request){//设置上下文。$request->set_param('context', 'edit');$ user_id = bp_loggedin_user_id ();$fields = $request->get_param('fields');数组$错误= ();如果(!$field_post = (isset($field_post['group_id']) && !($field_post['group_id'])) ?美元field_post [' group_id ']:”;美元$ field_id =(收取(field_post [' field_id ']) & & ! empty( $field_post['field_id'] ) ) ? $field_post['field_id'] : ''; $visibility_level = ( isset( $field_post['visibility_level'] ) && ! empty( $field_post['visibility_level'] ) ) ? $field_post['visibility_level'] : ''; $value = ( isset( $field_post['value'] ) && ! empty( $field_post['value'] ) ) ? $field_post['value'] : ''; if ( empty( $field_id ) ) { continue; } $field = xprofile_get_field( $field_id ); if ( isset( $field_post['value'] ) ) { if ( 'checkbox' === $field->type || 'socialnetworks' === $field->type ) { if ( is_serialized( $value ) ) { $value = maybe_unserialize( $value ); } $value = json_decode( $value, true ); if ( ! is_array( $value ) ) { $value = (array) $value; } } $validation = $this->validate_update( $field_id, $user_id, $value ); if ( empty( $validation ) ) { xprofile_set_field_data( $field_id, $user_id, $value, $field->is_required ); } else { $errors[ $field_id ] = $validation; } } if ( ! empty( $visibility_level ) ) { xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); } } } $args = array( 'profile_group_id' => $request['profile_group_id'], 'user_id' => bp_loggedin_user_id(), 'member_type' => $request['member_type'], 'hide_empty_groups' => $request['hide_empty_groups'], 'hide_empty_fields' => $request['hide_empty_fields'], 'fetch_field_data' => $request['fetch_field_data'], 'fetch_visibility_level' => $request['fetch_visibility_level'], 'exclude_groups' => $request['exclude_groups'], 'exclude_fields' => $request['exclude_fields'], 'update_meta_cache' => $request['update_meta_cache'], 'fetch_fields' => true, ); if ( empty( $request['member_type'] ) ) { $args['member_type'] = false; } /** * Filter the query arguments for the request. * * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ $args = apply_filters( 'bp_rest_xprofile_fields_get_items_query_args', $args, $request ); // Actually, query it. $field_groups = bp_xprofile_get_groups( $args ); $response = array(); if ( empty( $errors ) ) { $response['updated'] = true; } else { $response['updated'] = $errors; } $retval = array(); foreach ( (array) $field_groups as $item ) { $retval[] = $this->group_fields_endpoint->prepare_response_for_collection( $this->group_fields_endpoint->prepare_item_for_response( $item, $request ) ); } $response['data'] = $retval; $response = rest_ensure_response( $response ); /** * Fires after a XProfile update is created via the REST API. * * @param BP_XProfile_Field $field Created field object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_xprofile_update_items', $field_groups, $response, $request ); return $response; }

更新日志

更新日志
版本 描述
0.1.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队