Ticket #34491: 34491.3.patch
File 34491.3.patch, 7.8 KB (added by , 5 years ago) |
---|
-
src/wp-includes/class-wp.php
319 319 if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) ) 320 320 $this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] ); 321 321 322 // Don't allow non-public taxonomies to be queried from the front-end.322 // Don't allow non-publicly queryable taxonomies to be queried from the front-end. 323 323 if ( ! is_admin() ) { 324 foreach ( get_taxonomies( array( 'public ' => false ), 'objects' ) as $taxonomy => $t ) {324 foreach ( get_taxonomies( array( 'publicly_queryable' => false ), 'objects' ) as $taxonomy => $t ) { 325 325 /* 326 326 * Disallow when set to the 'taxonomy' query var. 327 * Non-public taxonomies cannot register custom query vars. See register_taxonomy().327 * Non-publicly queryable taxonomies cannot register custom query vars. See register_taxonomy(). 328 328 */ 329 329 if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) { 330 330 unset( $this->query_vars['taxonomy'], $this->query_vars['term'] ); -
src/wp-includes/taxonomy.php
288 288 * taxonomies. See accepted values in get_taxonomy_labels(). 289 289 * Default empty array. 290 290 * @type string $description A short descriptive summary of what the taxonomy is for. Default empty. 291 * @type bool $public Whether the taxonomy is publicly queryable. Default true. 291 * @type bool $public Whether a taxonomy is intended for use publicly either via 292 * the admin interface or by front-end users. While the default settings 293 * of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus` 294 * are inherited from `$public`, each does not rely on this relationship 295 * and controls a very specific intention (default true). 296 * @type bool $publicly_queryable Whether the taxonomy is publicly queryable. 297 * If not set, the default is inherited from `$public` 292 298 * @type bool $hierarchical Whether the taxonomy is hierarchical. Default false. 293 299 * @type bool $show_ui Whether to generate and allow a UI for managing terms in this taxonomy in 294 300 * the admin. If not set, the default is inherited from `$public` … … 362 368 'labels' => array(), 363 369 'description' => '', 364 370 'public' => true, 371 'publicly_queryable' => null, 365 372 'hierarchical' => false, 366 373 'show_ui' => null, 367 374 'show_in_menu' => null, … … 383 390 return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) ); 384 391 } 385 392 386 // Non-public taxonomies should not register query vars, except in the admin. 387 if ( false !== $args['query_var'] && ( is_admin() || false !== $args['public'] ) && ! empty( $wp ) ) { 393 // If not set, default to the setting for public. 394 if ( null === $args['publicly_queryable'] ) { 395 $args['publicly_queryable'] = $args['public']; 396 } 397 398 // Non-publicly queryable taxonomies should not register query vars, except in the admin. 399 if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) && ! empty( $wp ) ) { 388 400 if ( true === $args['query_var'] ) 389 401 $args['query_var'] = $taxonomy; 390 402 else -
tests/phpunit/includes/utils.php
369 369 unset( $GLOBALS[$v] ); 370 370 371 371 foreach ( get_taxonomies( array() , 'objects' ) as $t ) { 372 if ( $t->public && ! empty( $t->query_var ) )372 if ( $t->publicly_queryable && ! empty( $t->query_var ) ) 373 373 $GLOBALS['wp']->add_query_var( $t->query_var ); 374 374 } 375 375 … … 410 410 */ 411 411 function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { 412 412 $saved_config = ini_get( 'pcre.backtrack_limit' ); 413 413 414 414 // Attempt to prevent PHP crashes. Adjust these lower when needed. 415 415 if ( version_compare( phpversion(), '5.4.8', '>' ) ) { 416 416 $limit = 1000000; … … 422 422 for( $i = 4; $i <= $limit; $i *= 2 ) { 423 423 424 424 ini_set( 'pcre.backtrack_limit', $i ); 425 425 426 426 switch( $strategy ) { 427 427 case 'split': 428 428 preg_split( $pattern, $subject ); -
tests/phpunit/tests/taxonomy.php
446 446 /** 447 447 * @ticket 21949 448 448 */ 449 public function test_nonpublic _taxonomy_should_not_be_queryable_using_taxname_query_var() {449 public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxname_query_var() { 450 450 register_taxonomy( 'wptests_tax', 'post', array( 451 'public ' => false,451 'publicly_queryable' => false, 452 452 ) ); 453 453 454 454 $t = self::factory()->term->create_and_get( array( … … 466 466 /** 467 467 * @ticket 21949 468 468 */ 469 public function test_it_should_be_possible_to_register_a_query_var_that_matches_the_name_of_a_nonpublic _taxonomy() {469 public function test_it_should_be_possible_to_register_a_query_var_that_matches_the_name_of_a_nonpublicly_queryable_taxonomy() { 470 470 global $wp; 471 471 472 472 register_taxonomy( 'wptests_tax', 'post', array( 473 'public ' => false,473 'publicly_queryable' => false, 474 474 ) ); 475 475 $t = $this->factory->term->create_and_get( array( 476 476 'taxonomy' => 'wptests_tax', … … 501 501 /** 502 502 * @ticket 21949 503 503 */ 504 public function test_nonpublic _taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() {504 public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() { 505 505 register_taxonomy( 'wptests_tax', 'post', array( 506 'public ' => false,506 'publicly_queryable' => false, 507 507 ) ); 508 508 509 509 $t = self::factory()->term->create_and_get( array( … … 519 519 } 520 520 521 521 /** 522 * @ticket 34491 523 */ 524 public function test_public_taxonomy_should_be_publicly_queryable() { 525 register_taxonomy( 'wptests_tax', 'post', array( 526 'public' => true, 527 ) ); 528 529 $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) ); 530 531 $t = self::factory()->term->create_and_get( array( 532 'taxonomy' => 'wptests_tax', 533 ) ); 534 535 $p = self::factory()->post->create(); 536 wp_set_object_terms( $p, $t->slug, 'wptests_tax' ); 537 538 $this->go_to( '/?wptests_tax=' . $t->slug ); 539 540 $this->assertTrue( is_tax( 'wptests_tax' ) ); 541 } 542 543 /** 544 * @ticket 34491 545 */ 546 public function test_private_taxonomy_should_not_be_publicly_queryable() { 547 register_taxonomy( 'wptests_tax', 'post', array( 548 'public' => false, 549 ) ); 550 551 $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => false ) ) ); 552 553 $t = self::factory()->term->create_and_get( array( 554 'taxonomy' => 'wptests_tax', 555 ) ); 556 557 $p = self::factory()->post->create(); 558 wp_set_object_terms( $p, $t->slug, 'wptests_tax' ); 559 560 $this->go_to( '/?wptests_tax=' . $t->slug ); 561 562 $this->assertFalse( is_tax( 'wptests_tax' ) ); 563 } 564 565 /** 522 566 * @ticket 35089 523 567 */ 524 568 public function test_query_var_should_be_forced_to_false_for_non_public_taxonomy() {