// ============================================================================================== // INICIO: API REST PARA EL NUEVO FRONTEND REACT (BETA.GAYPERU.PE) // ============================================================================================== // 1. Obligar a la API a enviar a todos los usuarios (no solo a los autores de posts) add_filter('rest_user_query', function($prepared_args, $request) { if (isset($prepared_args['has_published_posts'])) { unset($prepared_args['has_published_posts']); } return $prepared_args; }, 10, 2); // 2. Exponer fotos reales y metas personalizados a React add_filter('rest_prepare_user', function($response, $user, $request) { $user_id = $user->ID; // A. Extracción de foto idéntica a gp_expose_global_and_chat_data $foto_url = ''; $foto_meta = get_user_meta( $user_id, 'gp_foto_perfil', true ); if ( $foto_meta && is_numeric($foto_meta) ) { $foto_url = wp_get_attachment_url( $foto_meta ); } if ( empty($foto_url) ) { $avatar_ajax = get_user_meta( $user_id, 'gp_avatar', true ); if ($avatar_ajax) { $foto_url = is_numeric($avatar_ajax) ? wp_get_attachment_url($avatar_ajax) : $avatar_ajax; } } if ( empty($foto_url) ) { $um_foto = get_user_meta($user_id, 'profile_photo', true); if ($um_foto) { $foto_url = (strpos($um_foto, 'http') === 0) ? $um_foto : site_url(ltrim($um_foto, '/')); } } if ( empty($foto_url) ) { $foto_url = get_avatar_url( $user_id, array('size' => 300) ); } // B. Inyectar datos a la API $response->data['gp_foto_url'] = $foto_url; $age = get_user_meta( $user_id, 'gp_age', true ); if ( empty($age) ) { $age = get_user_meta( $user_id, 'gp_edad', true ); } $response->data['gp_edad'] = $age; $district = get_user_meta( $user_id, 'gp_district', true ); if ( empty($district) ) { $district = get_user_meta( $user_id, 'gp_distrito', true ); } if ( empty($district) ) { $district = get_user_meta( $user_id, 'gp_city', true ); } if ( empty($district) ) { $district = get_user_meta( $user_id, 'gp_ciudad', true ); } $response->data['gp_distrito'] = $district; $response->data['gp_genero'] = get_user_meta($user_id, 'gp_genero', true); $role = get_user_meta( $user_id, 'gp_rol', true ); if ( empty($role) ) { $role = get_user_meta( $user_id, 'rol', true ); } if ( empty($role) ) { $role = get_user_meta( $user_id, 'gp_role', true ); } if ( empty($role) ) { $role = get_user_meta( $user_id, 'role', true ); } $response->data['gp_rol'] = $role; return $response; }, 10, 3); // ============================================================================================== // FIN: API REST PARA EL NUEVO FRONTEND REACT // ==============================================================================================