From 471fc6d9a5deca23e8592bd14971237adbe20f10 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 16 Sep 2015 19:05:23 +0000 Subject: [PATCH] Allow taxonomies to be non-public. [13216] introduced the 'public' argument for `register_taxonomy()`. This param was used to set defaults for 'show_ui' and a number of other params, but it never did anything itself. With this changeset, taxonomies registered with `public=false` will no longer be queryable on the front end, ie via taxonomy archive queries. Props wpsmith, ocean90, nacin, ericlewis, boonebgorges. Fixes #21949. Built from https://develop.svn.wordpress.org/trunk@34247 git-svn-id: http://core.svn.wordpress.org/trunk@34211 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp.php | 15 +++++++++++++++ wp-includes/taxonomy-functions.php | 2 +- wp-includes/version.php | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 84111bca9f..6d008c87da 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -300,6 +300,21 @@ class WP { if ( $t->query_var && isset( $this->query_vars[$t->query_var] ) ) $this->query_vars[$t->query_var] = str_replace( ' ', '+', $this->query_vars[$t->query_var] ); + // Don't allow non-public taxonomies to be queried from the front-end. + if ( ! is_admin() ) { + foreach ( get_taxonomies( array( 'public' => false ), 'objects' ) as $taxonomy => $t ) { + // Check first for taxonomy-specific query_var. + if ( $t->query_var && isset( $this->query_vars[ $t->query_var ] ) ) { + unset( $this->query_vars[ $t->query_var ] ); + } + + // Next, check the 'taxonomy' query_var. + if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) { + unset( $this->query_vars['taxonomy'], $this->query_vars['term'] ); + } + } + } + // Limit publicly queried post_types to those that are publicly_queryable if ( isset( $this->query_vars['post_type']) ) { $queryable_post_types = get_post_types( array('publicly_queryable' => true) ); diff --git a/wp-includes/taxonomy-functions.php b/wp-includes/taxonomy-functions.php index eee37bc8a3..280f440775 100644 --- a/wp-includes/taxonomy-functions.php +++ b/wp-includes/taxonomy-functions.php @@ -278,7 +278,7 @@ function is_taxonomy_hierarchical($taxonomy) { * * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones. * * You can see accepted values in {@link get_taxonomy_labels()}. * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank. - * - public - If the taxonomy should be publicly queryable; //@TODO not implemented. + * - public - If the taxonomy should be publicly queryable. * * Defaults to true. * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false. * - show_ui - Whether to generate a default UI for managing this taxonomy in the admin. diff --git a/wp-includes/version.php b/wp-includes/version.php index 957fe4557e..15b4adff53 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34246'; +$wp_version = '4.4-alpha-34247'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.