<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[36525] trunk: Introduce `publicly_queryable` taxonomy argument.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/36525">36525</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/36525","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-02-13 03:50:37 +0000 (Sat, 13 Feb 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Introduce `publicly_queryable` taxonomy argument.
Taxonomies registered as `publicly_queryable` can be queried as taxonomy
archives.
If not provided explicitly, the value of `publicly_queryable` is inherited
from `public`.
Props Chouby.
Fixes <a href="https://core.trac.wordpress.org/ticket/34491">#34491</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpphp">trunk/src/wp-includes/class-wp.php</a></li>
<li><a href="#trunksrcwpincludestaxonomyphp">trunk/src/wp-includes/taxonomy.php</a></li>
<li><a href="#trunktestsphpunitincludesutilsphp">trunk/tests/phpunit/includes/utils.php</a></li>
<li><a href="#trunktestsphpunitteststaxonomyphp">trunk/tests/phpunit/tests/taxonomy.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp.php 2016-02-13 03:04:05 UTC (rev 36524)
+++ trunk/src/wp-includes/class-wp.php 2016-02-13 03:50:37 UTC (rev 36525)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -331,12 +331,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) )
</span><span class="cx" style="display: block; padding: 0 10px"> $this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Don't allow non-public taxonomies to be queried from the front-end.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Don't allow non-publicly queryable taxonomies to be queried from the front-end.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_admin() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( get_taxonomies( array( 'public' => false ), 'objects' ) as $taxonomy => $t ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( get_taxonomies( array( 'publicly_queryable' => false ), 'objects' ) as $taxonomy => $t ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * Disallow when set to the 'taxonomy' query var.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Non-public taxonomies cannot register custom query vars. See register_taxonomy().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Non-publicly queryable taxonomies cannot register custom query vars. See register_taxonomy().
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $this->query_vars['taxonomy'], $this->query_vars['term'] );
</span></span></pre></div>
<a id="trunksrcwpincludestaxonomyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/taxonomy.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/taxonomy.php 2016-02-13 03:04:05 UTC (rev 36524)
+++ trunk/src/wp-includes/taxonomy.php 2016-02-13 03:50:37 UTC (rev 36525)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -288,7 +288,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * taxonomies. See accepted values in get_taxonomy_labels().
</span><span class="cx" style="display: block; padding: 0 10px"> * Default empty array.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $description A short descriptive summary of what the taxonomy is for. Default empty.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool $public Whether the taxonomy is publicly queryable. Default true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type bool $public Whether a taxonomy is intended for use publicly either via
+ * the admin interface or by front-end users. The default settings
+ * of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
+ * are inherited from `$public`.
+ * @type bool $publicly_queryable Whether the taxonomy is publicly queryable.
+ * If not set, the default is inherited from `$public`
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type bool $hierarchical Whether the taxonomy is hierarchical. Default false.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type bool $show_ui Whether to generate and allow a UI for managing terms in this taxonomy in
</span><span class="cx" style="display: block; padding: 0 10px"> * the admin. If not set, the default is inherited from `$public`
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -362,6 +367,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'labels' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> 'public' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'publicly_queryable' => null,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'hierarchical' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_ui' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_in_menu' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -383,8 +389,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Non-public taxonomies should not register query vars, except in the admin.
- if ( false !== $args['query_var'] && ( is_admin() || false !== $args['public'] ) && ! empty( $wp ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If not set, default to the setting for public.
+ if ( null === $args['publicly_queryable'] ) {
+ $args['publicly_queryable'] = $args['public'];
+ }
+
+ // Non-publicly queryable taxonomies should not register query vars, except in the admin.
+ if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) && ! empty( $wp ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( true === $args['query_var'] )
</span><span class="cx" style="display: block; padding: 0 10px"> $args['query_var'] = $taxonomy;
</span><span class="cx" style="display: block; padding: 0 10px"> else
</span></span></pre></div>
<a id="trunktestsphpunitincludesutilsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/utils.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/utils.php 2016-02-13 03:04:05 UTC (rev 36524)
+++ trunk/tests/phpunit/includes/utils.php 2016-02-13 03:50:37 UTC (rev 36525)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -362,7 +362,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $GLOBALS[$v] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( get_taxonomies( array() , 'objects' ) as $t ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $t->public && ! empty( $t->query_var ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $t->publicly_queryable && ! empty( $t->query_var ) )
</ins><span class="cx" style="display: block; padding: 0 10px"> $GLOBALS['wp']->add_query_var( $t->query_var );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunitteststaxonomyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/taxonomy.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/taxonomy.php 2016-02-13 03:04:05 UTC (rev 36524)
+++ trunk/tests/phpunit/tests/taxonomy.php 2016-02-13 03:50:37 UTC (rev 36525)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -446,9 +446,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 21949
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_nonpublic_taxonomy_should_not_be_queryable_using_taxname_query_var() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxname_query_var() {
</ins><span class="cx" style="display: block; padding: 0 10px"> register_taxonomy( 'wptests_tax', 'post', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'public' => false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'publicly_queryable' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $t = self::factory()->term->create_and_get( array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -466,11 +466,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 21949
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_it_should_be_possible_to_register_a_query_var_that_matches_the_name_of_a_nonpublic_taxonomy() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_it_should_be_possible_to_register_a_query_var_that_matches_the_name_of_a_nonpublicly_queryable_taxonomy() {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> register_taxonomy( 'wptests_tax', 'post', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'public' => false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'publicly_queryable' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $t = $this->factory->term->create_and_get( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'taxonomy' => 'wptests_tax',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -501,9 +501,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 21949
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_nonpublic_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() {
</ins><span class="cx" style="display: block; padding: 0 10px"> register_taxonomy( 'wptests_tax', 'post', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'public' => false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'publicly_queryable' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $t = self::factory()->term->create_and_get( array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -519,6 +519,73 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 34491
+ */
+ public function test_public_taxonomy_should_be_publicly_queryable() {
+ register_taxonomy( 'wptests_tax', 'post', array(
+ 'public' => true,
+ ) );
+
+ $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) );
+
+ $t = self::factory()->term->create_and_get( array(
+ 'taxonomy' => 'wptests_tax',
+ ) );
+
+ $p = self::factory()->post->create();
+ wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
+
+ $this->go_to( '/?wptests_tax=' . $t->slug );
+
+ $this->assertTrue( is_tax( 'wptests_tax' ) );
+ }
+
+ /**
+ * @ticket 34491
+ */
+ public function test_private_taxonomy_should_not_be_publicly_queryable() {
+ register_taxonomy( 'wptests_tax', 'post', array(
+ 'public' => false,
+ ) );
+
+ $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => false ) ) );
+
+ $t = self::factory()->term->create_and_get( array(
+ 'taxonomy' => 'wptests_tax',
+ ) );
+
+ $p = self::factory()->post->create();
+ wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
+
+ $this->go_to( '/?wptests_tax=' . $t->slug );
+
+ $this->assertFalse( is_tax( 'wptests_tax' ) );
+ }
+
+ /**
+ * @ticket 34491
+ */
+ public function test_private_taxonomy_should_be_overridden_by_publicly_queryable() {
+ register_taxonomy( 'wptests_tax', 'post', array(
+ 'public' => false,
+ 'publicly_queryable' => true,
+ ) );
+
+ $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) );
+
+ $t = self::factory()->term->create_and_get( array(
+ 'taxonomy' => 'wptests_tax',
+ ) );
+
+ $p = self::factory()->post->create();
+ wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
+
+ $this->go_to( '/?wptests_tax=' . $t->slug );
+
+ $this->assertTrue( is_tax( 'wptests_tax' ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 35089
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_query_var_should_be_forced_to_false_for_non_public_taxonomy() {
</span></span></pre>
</div>
</div>
</body>
</html>