bp_get_member_profile_data (|字符串数组args美元='')
获取用户配置文件数据。
描述
当用于bp_has_members ()循环时,该函数将尝试获取缓存在模板全局变量中的配置文件数据。在循环之外使用它也是安全的。
参数
- args美元
-
(数组|字符串)(可选)配置参数数组。
- “字段”
(字符串)配置文件字段的名称。 - “user_id”
(int)正在获取数据的用户的ID。默认为循环中的当前成员,如果不存在,则为当前显示的用户。
默认值:“
- “字段”
返回
(字符串| bool)如果发现配置文件数据,则为false。
源
文件:bp-members / bp-members-template.php
函数bp_get_member_profile_data($args = ") {global $members_template;如果(!Bp_is_active ('xprofile')){返回false;} //声明局部变量。$ data = false;//默认为$user_id美元default_user_id = 0;如果(!$members_template->member->id)) {$default_user_id = $members_template->member->id;} elseif (bp_displayed_user_id()) {$default_user_id = bp_displayed_user_id(); } $defaults = array( 'field' => false, 'user_id' => $default_user_id, ); $r = wp_parse_args( $args, $defaults ); // If we're in a members loop, get the data from the global. if ( ! empty( $members_template->member->profile_data ) ) { $profile_data = $members_template->member->profile_data; } // Otherwise query for the data. if ( empty( $profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) { $profile_data = BP_XProfile_ProfileData::get_all_for_user( $r['user_id'] ); } // If we're in the members loop, but the profile data has not // been loaded into the global, cache it there for later use. if ( ! empty( $members_template->member ) && empty( $members_template->member->profile_data ) ) { $members_template->member->profile_data = $profile_data; } // Get the data for the specific field requested. if ( ! empty( $profile_data ) && ! empty( $profile_data[ $r['field'] ]['field_type'] ) && ! empty( $profile_data[ $r['field'] ]['field_data'] ) ) { $data = xprofile_format_profile_field( $profile_data[ $r['field'] ]['field_type'], $profile_data[ $r['field'] ]['field_data'] ); } /** * Filters resulting piece of member profile data. * * @since BuddyPress 1.2.0 * @since BuddyPress 2.6.0 Added the `$r` parameter. * * @param string|bool $data Profile data if found, otherwise false. * @param array $r Array of parsed arguments. */ $data = apply_filters( 'bp_get_member_profile_data', $data, $r ); /** * Filters the resulting piece of member profile data by field type. * * This is a dynamic filter based on field type of the current field requested. * * @since BuddyPress 2.7.0 * * @param string|bool $data Profile data if found, otherwise false. * @param array $r Array of parsed arguments. */ if ( ! empty( $profile_data[ $r['field'] ]['field_type'] ) ) { $data = apply_filters( 'bp_get_member_profile_data_' . $profile_data[ $r['field'] ]['field_type'], $data, $r ); } return $data; }
更新日志
版本 | 描述 |
---|---|
BuddyPress 1.2.0 | 介绍了。 |