BP_REST_Members_Endpoint:: user_data (WP_User$ user,字符串美元的上下文=“视图”)
方法,以方便获取用户数据。
描述
这被抽象出来用于其他BuddyPress端点。
参数
- $ user
-
(WP_User)(必需)用户对象。
- 美元的上下文
-
(字符串)(可选)请求的上下文。默认为“视图”。
默认值:“视图”
返回
(数组)
源
文件:bp-members /类/ class-bp-rest-members-endpoint.php
公共职能user_data(用户、上下文美元=“视图”){$ data =数组(“id”= >用户- > id '名字' = >用户- > display_name, '用户_ ' = >用户- >用户_美元,“链接”= > bp_core_get_user_domain(用户- > id、用户- > user_nicename, $ user - >用户_),“member_types”= > bp_get_member_type(用户- > id、假),“角色”= >数组(),“功能”= >数组(),“extra_capabilities”= >数组(),“registered_date”= > bp_rest_prepare_date_response (get_userdata ($ user - > ID) - > user_registered),“profile_name”= > bp_core_get_user_displayname ($ user - > ID),“last_activity”= > $ this - > bp_rest_get_member_last_active(用户- > ID数组(“相对”= > false)),“xprofile”= > $ this - > xprofile_data ($ user - > ID),'following' => count($this->rest_bp_get_following_ids(array('user_id' => $user->ID))),); / /用户ID$data['friends '] = ((bp_is_active('friends') && function_exists('friends_check_friendship_status')) ?friends_check_friendship_status(get_current_user_id(), $user->ID): ");$data['friendship_id'] = ((bp_is_active('friends') && function_exists('friends_get_friendship_id')) ?friends_get_friendship_id(get_current_user_id(), $user->ID): ");$data['is_following'] = (bool) (function_exists('bp_is_following')) ?bp_is_following(数组(' leader_id ' = >用户- > ID ' follower_id ' = > get_current_user_id (), ) ) : ' 0 ');If ('edit' === $context) {$data['registered_date'] = bp_rest_prepare_date_response($user->data->user_registered); $data['roles'] = (array) array_values( $user->roles ); $data['capabilities'] = (array) array_keys( $user->allcaps ); $data['extra_capabilities'] = (array) array_keys( $user->caps ); } // The name used for that user in @-mentions. if ( bp_is_active( 'activity' ) ) { $data['mention_name'] = bp_activity_get_user_mentionname( $user->ID ); } // Get item schema. $schema = $this->get_item_schema(); // Avatars. if ( ! empty( $schema['properties']['avatar_urls'] ) ) { $data['avatar_urls'] = array( 'full' => bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'html' => false, 'type' => 'full', ) ), 'thumb' => bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'html' => false, ) ), ); } // Cover Image. $data['cover_url'] = ( empty( bp_disable_cover_image_uploads() ) ? bp_attachments_get_attachment( 'url', array( 'object_dir' => 'members', 'item_id' => $user->ID, ) ) : false ); // Fallback. if ( false === $data['member_types'] ) { $data['member_types'] = array(); } if ( function_exists( 'bp_member_type_enable_disable' ) && bp_member_type_enable_disable() === false ) { $data['member_types'] = array(); } if ( ! empty( $data['member_types'] ) ) { $member_types = array(); foreach ( $data['member_types'] as $name ) { $member_types[ $name ] = bp_get_member_type_object( $name ); } $data['member_types'] = $member_types; } return $data; }
更新日志
版本 | 描述 |
---|---|
0.1.0 | 介绍了。 |