diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php
index f54717f804..2db58a7c15 100644
|
|
function validate_plugin_requirements( $plugin ) { |
1096 | 1096 | $plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) ); |
1097 | 1097 | |
1098 | 1098 | if ( ! $plugin_data['wp_compatible'] && ! $plugin_data['php_compatible'] ) { |
1099 | | return new WP_Error( 'plugin_wp_php_incompatible', sprintf( |
1100 | | /* translators: %s: plugin name */ |
1101 | | __( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.' ), $plugin_data['Name'] ) |
| 1099 | return new WP_Error( |
| 1100 | 'plugin_wp_php_incompatible', |
| 1101 | sprintf( |
| 1102 | /* translators: %s: plugin name */ |
| 1103 | __( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.' ), |
| 1104 | $plugin_data['Name'] |
| 1105 | ) |
1102 | 1106 | ); |
1103 | 1107 | } elseif ( ! $plugin_data['php_compatible'] ) { |
1104 | | return new WP_Error( 'plugin_php_incompatible', sprintf( |
1105 | | /* translators: %s: plugin name */ |
1106 | | __( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.' ), $plugin_data['Name'] ) |
| 1108 | return new WP_Error( |
| 1109 | 'plugin_php_incompatible', |
| 1110 | sprintf( |
| 1111 | /* translators: %s: plugin name */ |
| 1112 | __( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.' ), |
| 1113 | $plugin_data['Name'] |
| 1114 | ) |
1107 | 1115 | ); |
1108 | 1116 | } elseif ( ! $plugin_data['wp_compatible'] ) { |
1109 | | return new WP_Error( 'plugin_wp_incompatible', sprintf( |
1110 | | /* translators: %s: plugin name */ |
1111 | | __( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.' ), $plugin_data['Name'] ) |
| 1117 | return new WP_Error( |
| 1118 | 'plugin_wp_incompatible', |
| 1119 | sprintf( |
| 1120 | /* translators: %s: plugin name */ |
| 1121 | __( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.' ), |
| 1122 | $plugin_data['Name'] |
| 1123 | ) |
1112 | 1124 | ); |
1113 | 1125 | } |
1114 | 1126 | |
diff --git src/wp-includes/class-wp-site-query.php src/wp-includes/class-wp-site-query.php
index bc3e3519a3..ec5fa0fcda 100644
|
|
class WP_Site_Query { |
87 | 87 | */ |
88 | 88 | public $sites; |
89 | 89 | |
| 90 | /** |
| 91 | * List of site ids in the query. |
| 92 | * |
| 93 | * @since 5.2.0 |
| 94 | * @var array|null |
| 95 | */ |
| 96 | public $site_ids = null; |
| 97 | |
90 | 98 | /** |
91 | 99 | * The amount of found sites for the current query. |
92 | 100 | * |
… |
… |
class WP_Site_Query { |
288 | 296 | $this->meta_query_clauses = $this->meta_query->get_sql( 'blog', $wpdb->blogs, 'blog_id', $this ); |
289 | 297 | } |
290 | 298 | |
291 | | // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. |
292 | | $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); |
| 299 | /** |
| 300 | * Filter the sites array before the query takes place. |
| 301 | * |
| 302 | * Return a non-null value to bypass WordPress's default site queries. |
| 303 | * |
| 304 | * |
| 305 | * @since 5.2.0 |
| 306 | * |
| 307 | * @param array|null $site_ids Return an array of site data to short-circuit WP's site query, |
| 308 | * or null to allow WP to run its normal queries. |
| 309 | * @param WP_Site_Query $this The WP_Site_Query instance, passed by reference. |
| 310 | */ |
| 311 | $this->site_ids = apply_filters_ref_array( 'sites_pre_query', array( $this->site_ids, &$this ) ); |
293 | 312 | |
294 | | // Ignore the $fields argument as the queried result will be the same regardless. |
295 | | unset( $_args['fields'] ); |
| 313 | if ( null === $this->site_ids ) { |
296 | 314 | |
297 | | $key = md5( serialize( $_args ) ); |
298 | | $last_changed = wp_cache_get_last_changed( 'sites' ); |
| 315 | // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. |
| 316 | $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); |
299 | 317 | |
300 | | $cache_key = "get_sites:$key:$last_changed"; |
301 | | $cache_value = wp_cache_get( $cache_key, 'sites' ); |
| 318 | // Ignore the $fields argument as the queried result will be the same regardless. |
| 319 | unset( $_args['fields'] ); |
302 | 320 | |
303 | | if ( false === $cache_value ) { |
304 | | $site_ids = $this->get_site_ids(); |
305 | | if ( $site_ids ) { |
306 | | $this->set_found_sites(); |
307 | | } |
| 321 | $key = md5( serialize( $_args ) ); |
| 322 | $last_changed = wp_cache_get_last_changed( 'sites' ); |
308 | 323 | |
309 | | $cache_value = array( |
310 | | 'site_ids' => $site_ids, |
311 | | 'found_sites' => $this->found_sites, |
312 | | ); |
313 | | wp_cache_add( $cache_key, $cache_value, 'sites' ); |
314 | | } else { |
315 | | $site_ids = $cache_value['site_ids']; |
316 | | $this->found_sites = $cache_value['found_sites']; |
| 324 | $cache_key = "get_sites:$key:$last_changed"; |
| 325 | $cache_value = wp_cache_get( $cache_key, 'sites' ); |
| 326 | |
| 327 | if ( false === $cache_value ) { |
| 328 | $this->site_ids = $this->get_site_ids(); |
| 329 | if ( $this->site_ids ) { |
| 330 | $this->set_found_sites(); |
| 331 | } |
| 332 | |
| 333 | $cache_value = array( |
| 334 | 'site_ids' => $this->site_ids, |
| 335 | 'found_sites' => $this->found_sites, |
| 336 | ); |
| 337 | wp_cache_add( $cache_key, $cache_value, 'sites' ); |
| 338 | } else { |
| 339 | $this->site_ids = $cache_value['site_ids']; |
| 340 | $this->found_sites = $cache_value['found_sites']; |
| 341 | } |
317 | 342 | } |
318 | 343 | |
319 | 344 | if ( $this->found_sites && $this->query_vars['number'] ) { |
… |
… |
class WP_Site_Query { |
323 | 348 | // If querying for a count only, there's nothing more to do. |
324 | 349 | if ( $this->query_vars['count'] ) { |
325 | 350 | // $site_ids is actually a count in this case. |
326 | | return intval( $site_ids ); |
| 351 | return intval( $this->site_ids ); |
327 | 352 | } |
328 | 353 | |
329 | | $site_ids = array_map( 'intval', $site_ids ); |
| 354 | $this->site_ids = array_map( 'intval', $site_ids ); |
330 | 355 | |
331 | 356 | if ( 'ids' == $this->query_vars['fields'] ) { |
332 | | $this->sites = $site_ids; |
| 357 | $this->sites = $this->site_ids; |
333 | 358 | |
334 | 359 | return $this->sites; |
335 | 360 | } |
336 | 361 | |
337 | 362 | // Prime site network caches. |
338 | 363 | if ( $this->query_vars['update_site_cache'] ) { |
339 | | _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] ); |
| 364 | _prime_site_caches( $this->site_ids, $this->query_vars['update_site_meta_cache'] ); |
340 | 365 | } |
341 | 366 | |
342 | 367 | // Fetch full site objects from the primed cache. |
343 | 368 | $_sites = array(); |
344 | | foreach ( $site_ids as $site_id ) { |
| 369 | foreach ( $this->site_ids as $site_id ) { |
345 | 370 | if ( $_site = get_site( $site_id ) ) { |
346 | 371 | $_sites[] = $_site; |
347 | 372 | } |
diff --git tests/phpunit/tests/multisite/siteQuery.php tests/phpunit/tests/multisite/siteQuery.php
index bac9269ff4..c17f977932 100644
|
|
if ( is_multisite() ) : |
911 | 911 | } |
912 | 912 | } |
913 | 913 | |
| 914 | |
| 915 | /** |
| 916 | * @ticket 45749 |
| 917 | */ |
| 918 | public function test_sites_pre_query_filter_should_bypass_database_query() { |
| 919 | global $wpdb; |
| 920 | |
| 921 | add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); |
| 922 | |
| 923 | $num_queries = $wpdb->num_queries; |
| 924 | |
| 925 | $q = new WP_Site_Query(); |
| 926 | $results = $q->query( |
| 927 | array( |
| 928 | 'fields' => 'ids', |
| 929 | ) |
| 930 | ); |
| 931 | |
| 932 | remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); |
| 933 | |
| 934 | // Make sure no queries were executed. |
| 935 | $this->assertSame( $num_queries, $wpdb->num_queries ); |
| 936 | |
| 937 | // We manually inserted a non-existing site and overrode the results with it. |
| 938 | $this->assertSame( array( 555 ), $q->sites ); |
| 939 | |
| 940 | // Make sure manually setting total_users doesn't get overwritten. |
| 941 | $this->assertEquals( 1, $q->found_sites ); |
| 942 | } |
| 943 | |
| 944 | public static function filter_sites_pre_query( $sites, $query ) { |
| 945 | $query->found_sites = 1; |
| 946 | |
| 947 | return array( 555 ); |
| 948 | } |
| 949 | |
914 | 950 | public function data_wp_site_query_meta_query() { |
915 | 951 | return array( |
916 | 952 | array( |