wp/wp-includes/class-wp-taxonomy.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/class-wp-taxonomy.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/class-wp-taxonomy.php	Tue Sep 27 16:37:53 2022 +0200
@@ -43,6 +43,14 @@
 	public $labels;
 
 	/**
+	 * Default labels.
+	 *
+	 * @since 6.0.0
+	 * @var (string|null)[][] $default_labels
+	 */
+	protected static $default_labels = array();
+
+	/**
 	 * A short descriptive summary of what the taxonomy is for.
 	 *
 	 * @since 4.7.0
@@ -144,7 +152,7 @@
 	 * An array of object types this taxonomy is registered for.
 	 *
 	 * @since 4.7.0
-	 * @var array
+	 * @var string[]
 	 */
 	public $object_type = null;
 
@@ -200,6 +208,14 @@
 	public $rest_base;
 
 	/**
+	 * The namespace for this taxonomy's REST API endpoints.
+	 *
+	 * @since 5.9.0
+	 * @var string|bool $rest_namespace
+	 */
+	public $rest_namespace;
+
+	/**
 	 * The controller for this taxonomy's REST API endpoints.
 	 *
 	 * Custom controllers must extend WP_REST_Controller.
@@ -281,8 +297,8 @@
 	 *
 	 * @since 4.7.0
 	 *
-	 * @param array|string $object_type Name of the object type for the taxonomy object.
-	 * @param array|string $args        Array or query string of arguments for registering a taxonomy.
+	 * @param string|string[] $object_type Name or array of names of the object types for the taxonomy.
+	 * @param array|string    $args        Array or query string of arguments for registering a taxonomy.
 	 */
 	public function set_props( $object_type, $args ) {
 		$args = wp_parse_args( $args );
@@ -299,6 +315,27 @@
 		 */
 		$args = apply_filters( 'register_taxonomy_args', $args, $this->name, (array) $object_type );
 
+		$taxonomy = $this->name;
+
+		/**
+		 * Filters the arguments for registering a specific taxonomy.
+		 *
+		 * The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key.
+		 *
+		 * Possible hook names include:
+		 *
+		 *  - `register_category_taxonomy_args`
+		 *  - `register_post_tag_taxonomy_args`
+		 *
+		 * @since 6.0.0
+		 *
+		 * @param array    $args        Array of arguments for registering a taxonomy.
+		 *                              See the register_taxonomy() function for accepted arguments.
+		 * @param string   $taxonomy    Taxonomy key.
+		 * @param string[] $object_type Array of names of object types for the taxonomy.
+		 */
+		$args = apply_filters( "register_{$taxonomy}_taxonomy_args", $args, $this->name, (array) $object_type );
+
 		$defaults = array(
 			'labels'                => array(),
 			'description'           => '',
@@ -319,6 +356,7 @@
 			'update_count_callback' => '',
 			'show_in_rest'          => false,
 			'rest_base'             => false,
+			'rest_namespace'        => false,
 			'rest_controller_class' => false,
 			'default_term'          => null,
 			'sort'                  => null,
@@ -384,6 +422,11 @@
 			$args['show_in_quick_edit'] = $args['show_ui'];
 		}
 
+		// If not set, default rest_namespace to wp/v2 if show_in_rest is true.
+		if ( false === $args['rest_namespace'] && ! empty( $args['show_in_rest'] ) ) {
+			$args['rest_namespace'] = 'wp/v2';
+		}
+
 		$default_caps = array(
 			'manage_terms' => 'manage_categories',
 			'edit_terms'   => 'manage_categories',
@@ -548,4 +591,71 @@
 
 		return $this->rest_controller;
 	}
+
+	/**
+	 * Returns the default labels for taxonomies.
+	 *
+	 * @since 6.0.0
+	 *
+	 * @return (string|null)[][] The default labels for taxonomies.
+	 */
+	public static function get_default_labels() {
+		if ( ! empty( self::$default_labels ) ) {
+			return self::$default_labels;
+		}
+
+		$name_field_description   = __( 'The name is how it appears on your site.' );
+		$slug_field_description   = __( 'The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' );
+		$parent_field_description = __( 'Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.' );
+		$desc_field_description   = __( 'The description is not prominent by default; however, some themes may show it.' );
+
+		self::$default_labels = array(
+			'name'                       => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
+			'singular_name'              => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
+			'search_items'               => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
+			'popular_items'              => array( __( 'Popular Tags' ), null ),
+			'all_items'                  => array( __( 'All Tags' ), __( 'All Categories' ) ),
+			'parent_item'                => array( null, __( 'Parent Category' ) ),
+			'parent_item_colon'          => array( null, __( 'Parent Category:' ) ),
+			'name_field_description'     => array( $name_field_description, $name_field_description ),
+			'slug_field_description'     => array( $slug_field_description, $slug_field_description ),
+			'parent_field_description'   => array( null, $parent_field_description ),
+			'desc_field_description'     => array( $desc_field_description, $desc_field_description ),
+			'edit_item'                  => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
+			'view_item'                  => array( __( 'View Tag' ), __( 'View Category' ) ),
+			'update_item'                => array( __( 'Update Tag' ), __( 'Update Category' ) ),
+			'add_new_item'               => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
+			'new_item_name'              => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
+			'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),
+			'add_or_remove_items'        => array( __( 'Add or remove tags' ), null ),
+			'choose_from_most_used'      => array( __( 'Choose from the most used tags' ), null ),
+			'not_found'                  => array( __( 'No tags found.' ), __( 'No categories found.' ) ),
+			'no_terms'                   => array( __( 'No tags' ), __( 'No categories' ) ),
+			'filter_by_item'             => array( null, __( 'Filter by category' ) ),
+			'items_list_navigation'      => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ),
+			'items_list'                 => array( __( 'Tags list' ), __( 'Categories list' ) ),
+			/* translators: Tab heading when selecting from the most used terms. */
+			'most_used'                  => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ),
+			'back_to_items'              => array( __( '← Go to Tags' ), __( '← Go to Categories' ) ),
+			'item_link'                  => array(
+				_x( 'Tag Link', 'navigation link block title' ),
+				_x( 'Category Link', 'navigation link block title' ),
+			),
+			'item_link_description'      => array(
+				_x( 'A link to a tag.', 'navigation link block description' ),
+				_x( 'A link to a category.', 'navigation link block description' ),
+			),
+		);
+
+		return self::$default_labels;
+	}
+
+	/**
+	 * Resets the cache for the default labels.
+	 *
+	 * @since 6.0.0
+	 */
+	public static function reset_default_labels() {
+		self::$default_labels = array();
+	}
 }