- 状态
- 已解决
- 报告针对
- WPML Multilingual CMS 4.6.5
- 解决于
- 4.6.6
- 主题标签
- Bug
问题概述
在多站点 WordPress 安装上更新至 WPML 4.6.5 后,您会发现本应在 WPML > 翻译管理 > 译者 下显示的译者列表为空。
临时解决方法
在继续操作之前,请确保对您的站点进行了完整备份。
- 打开 …/wp-content/plugins/sitepress-multilingual-cms/classes/user/class-wpml-translation-roles-records.php 文件。
- 找到第 116 行。
- 替换方法:/WPML_Translation_Roles_Records::get_records:
private function get_records( $compare, $search = '', $limit = -1 ) { $search = trim( $search ); $cache_key = md5( (string) wp_json_encode( [ get_class( $this ), $compare, $search, $limit ] ) ); $cache = wpml_get_cache( self::CACHE_GROUP ); $found = false; $results = $cache->get( $cache_key, $found ); if ( $found ) { return $results; } $preparedUserQuery = $this->wpdb->prepare( "SELECT u.id FROM {$this->wpdb->prefix}users u INNER JOIN {$this->wpdb->prefix}usermeta c ON c.user_id=u.ID AND CAST(c.meta_key AS BINARY)=%s AND c.meta_value {$compare} %s", "{$this->wpdb->prefix}capabilities", "%" . $this->get_capability() . "%" ); if ( self::USERS_WITHOUT_CAPABILITY === $compare ) { $required_wp_roles = $this->get_required_wp_roles(); foreach( $required_wp_roles as $required_wp_role ) { $preparedUserQuery .= $this->wpdb->prepare( " AND c.meta_value LIKE %s", "%{$required_wp_role}%" ); } } if ( $search ) { $preparedUserQuery .= $this->wpdb->prepare( " AND (u.user_login LIKE %s OR u.user_nicename LIKE %s OR u.user_email LIKE %s)", "%{$search}%", "%{$search}%", "%{$search}%" ); } $preparedUserQuery .= ' ORDER BY user_login ASC'; if ( $limit > 0 ) { $preparedUserQuery .= $this->wpdb->prepare(" LIMIT 0,%d", $limit ); } $users = $this->wpdb->get_col( $preparedUserQuery ); if ( $search && strlen( $search ) > self::MIN_SEARCH_LENGTH && ( $limit <= 0 || count( $users ) < $limit ) ) { $users_from_metas = $this->get_records_from_users_metas( $compare, $search, $limit ); $users_with_dupes = array_merge( $users, $users_from_metas ); $users = wpml_array_unique( $users_with_dupes, SORT_REGULAR ); } $results = array(); foreach ( $users as $user_id ) { $user_data = get_userdata( $user_id ); if ( $user_data ) { $language_pair_records = new WPML_Language_Pair_Records( $this->wpdb, new WPML_Language_Records( $this->wpdb ) ); $language_pairs = $language_pair_records->get( $user_id ); $result = (object) array( 'ID' => $user_data->ID, 'full_name' => trim( $user_data->first_name . ' ' . $user_data->last_name ), 'user_login' => $user_data->user_login, 'user_email' => $user_data->user_email, 'display_name' => $user_data->display_name, 'language_pairs' => $language_pairs, 'roles' => $user_data->roles ); $results[] = $result; } } $cache->set( $cache_key, $results ); return $results; } - 替换为:
private function get_records( $compare, $search = '', $limit = -1 ) { $search = trim( $search ); $cache_key = md5( (string) wp_json_encode( [ get_class( $this ), $compare, $search, $limit ] ) ); $cache = wpml_get_cache( self::CACHE_GROUP ); $found = false; $results = $cache->get( $cache_key, $found ); if ( $found ) { return $results; } $query_args = array( 'fields' => 'ID', 'meta_query' => array( array( 'key' => "{$this->wpdb->prefix}capabilities", 'value' => $this->get_capability(), 'compare' => $compare, ), ), 'number' => $limit, ); if ( 'NOT LIKE' === $compare ) { $required_wp_roles = $this->get_required_wp_roles(); if ( $required_wp_roles ) { $query_args['role__in'] = $required_wp_roles; } } if ( $search ) { $query_args['search'] = '*' . $search . '*'; $query_args['search_columns'] = array( 'user_login', 'user_nicename', 'user_email' ); } $user_query = $this->user_query_factory->create( $query_args ); $users = $user_query->get_results(); if ( $search && strlen( $search ) > self::MIN_SEARCH_LENGTH && ( $limit <= 0 || count( $users ) < $limit ) ) { $users_from_metas = $this->get_records_from_users_metas( $compare, $search, $limit ); $users_with_dupes = array_merge( $users, $users_from_metas ); $users = wpml_array_unique( $users_with_dupes, SORT_REGULAR ); } $results = array(); foreach ( $users as $user_id ) { $user_data = get_userdata( $user_id ); if ( $user_data ) { $language_pair_records = new WPML_Language_Pair_Records( $this->wpdb, new WPML_Language_Records( $this->wpdb ) ); $language_pairs = $language_pair_records->get( $user_id ); $result = (object) array( 'ID' => $user_data->ID, 'full_name' => trim( $user_data->first_name . ' ' . $user_data->last_name ), 'user_login' => $user_data->user_login, 'user_email' => $user_data->user_email, 'display_name' => $user_data->display_name, 'language_pairs' => $language_pairs, 'roles' => $user_data->roles ); $results[] = $result; } } $cache->set( $cache_key, $results ); return $results; }