bp_xprofile_bp_user_query_search (数组美元的sqlBP_User_Query美元的查询

当search_terms传递给BP_User_Query,搜索xprofile字段。

描述

参数

美元的sql

数组(必需)user_id SQL查询中的子句。

美元的查询

BP_User_Query(必需)用户查询对象。

返回

(数组)

文件:bp-xprofile / bp-xprofile-functions.php

函数bp_xprofile_bp_user_query_search($sql, BP_User_Query $query) {global $wpdb;If (empty($query->query_vars['search_terms']) || empty($sql['where']['search']) {return $sql;} $bp = buddypress();$search_terms_clean = bp_esc_like(wp_kses_normalize_entities($query->query_vars['search_terms']));If ($query->query_vars['search_wildcard'] === 'left') {$search_terms_nospace = '%' . php . php . php . php . php . php . php . php . php . php . php . php . php . php。search_terms_clean美元;$search_terms_space = '%'。search_terms_clean美元。“%”;} elseif ($query->query_vars['search_wildcard'] === 'right') {$search_terms_nospace = $search_terms_clean . txt . txt . txt . txt . txt . txt。 '%'; $search_terms_space = '% ' . $search_terms_clean . '%'; } else { $search_terms_nospace = '%' . $search_terms_clean . '%'; $search_terms_space = '%' . $search_terms_clean . '%'; } // Combine the core search (against wp_users) into a single OR clause // with the xprofile_data search. $matched_user_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s OR value LIKE %s", $search_terms_nospace, $search_terms_space ) ); // Checked profile fields based on privacy settings of particular user while searching if ( ! empty( $matched_user_ids ) ) { $matched_user_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE value LIKE %s OR value LIKE %s", $search_terms_nospace, $search_terms_space ) ); foreach ( $matched_user_data as $key => $user ) { $field_visibility = xprofile_get_field_visibility_level( $user->field_id, $user->user_id ); if ( 'adminsonly' === $field_visibility && !current_user_can('administrator') ) { if (($key = array_search($user->user_id, $matched_user_ids)) !== false) { unset($matched_user_ids[$key]); } } if ( 'friends' === $field_visibility && !current_user_can('administrator') && false === friends_check_friendship( intval($user->user_id), bp_loggedin_user_id() ) ) { if (($key = array_search($user->user_id, $matched_user_ids)) !== false) { unset($matched_user_ids[$key]); } } } } if ( ! empty( $matched_user_ids ) ) { $search_core = $sql['where']['search']; $search_combined = " ( u.{$query->uid_name} IN (" . implode(',', $matched_user_ids) . ") OR {$search_core} )"; $sql['where']['search'] = $search_combined; } return $sql; }

更新日志

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

问题吗?

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