wp/wp-includes/class-wp-taxonomy.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    41 	 * @var stdClass
    41 	 * @var stdClass
    42 	 */
    42 	 */
    43 	public $labels;
    43 	public $labels;
    44 
    44 
    45 	/**
    45 	/**
       
    46 	 * Default labels.
       
    47 	 *
       
    48 	 * @since 6.0.0
       
    49 	 * @var (string|null)[][] $default_labels
       
    50 	 */
       
    51 	protected static $default_labels = array();
       
    52 
       
    53 	/**
    46 	 * A short descriptive summary of what the taxonomy is for.
    54 	 * A short descriptive summary of what the taxonomy is for.
    47 	 *
    55 	 *
    48 	 * @since 4.7.0
    56 	 * @since 4.7.0
    49 	 * @var string
    57 	 * @var string
    50 	 */
    58 	 */
   142 
   150 
   143 	/**
   151 	/**
   144 	 * An array of object types this taxonomy is registered for.
   152 	 * An array of object types this taxonomy is registered for.
   145 	 *
   153 	 *
   146 	 * @since 4.7.0
   154 	 * @since 4.7.0
   147 	 * @var array
   155 	 * @var string[]
   148 	 */
   156 	 */
   149 	public $object_type = null;
   157 	public $object_type = null;
   150 
   158 
   151 	/**
   159 	/**
   152 	 * Capabilities for this taxonomy.
   160 	 * Capabilities for this taxonomy.
   196 	 *
   204 	 *
   197 	 * @since 4.7.4
   205 	 * @since 4.7.4
   198 	 * @var string|bool $rest_base
   206 	 * @var string|bool $rest_base
   199 	 */
   207 	 */
   200 	public $rest_base;
   208 	public $rest_base;
       
   209 
       
   210 	/**
       
   211 	 * The namespace for this taxonomy's REST API endpoints.
       
   212 	 *
       
   213 	 * @since 5.9.0
       
   214 	 * @var string|bool $rest_namespace
       
   215 	 */
       
   216 	public $rest_namespace;
   201 
   217 
   202 	/**
   218 	/**
   203 	 * The controller for this taxonomy's REST API endpoints.
   219 	 * The controller for this taxonomy's REST API endpoints.
   204 	 *
   220 	 *
   205 	 * Custom controllers must extend WP_REST_Controller.
   221 	 * Custom controllers must extend WP_REST_Controller.
   279 	 *
   295 	 *
   280 	 * See the register_taxonomy() function for accepted arguments for `$args`.
   296 	 * See the register_taxonomy() function for accepted arguments for `$args`.
   281 	 *
   297 	 *
   282 	 * @since 4.7.0
   298 	 * @since 4.7.0
   283 	 *
   299 	 *
   284 	 * @param array|string $object_type Name of the object type for the taxonomy object.
   300 	 * @param string|string[] $object_type Name or array of names of the object types for the taxonomy.
   285 	 * @param array|string $args        Array or query string of arguments for registering a taxonomy.
   301 	 * @param array|string    $args        Array or query string of arguments for registering a taxonomy.
   286 	 */
   302 	 */
   287 	public function set_props( $object_type, $args ) {
   303 	public function set_props( $object_type, $args ) {
   288 		$args = wp_parse_args( $args );
   304 		$args = wp_parse_args( $args );
   289 
   305 
   290 		/**
   306 		/**
   296 		 *                              See the register_taxonomy() function for accepted arguments.
   312 		 *                              See the register_taxonomy() function for accepted arguments.
   297 		 * @param string   $taxonomy    Taxonomy key.
   313 		 * @param string   $taxonomy    Taxonomy key.
   298 		 * @param string[] $object_type Array of names of object types for the taxonomy.
   314 		 * @param string[] $object_type Array of names of object types for the taxonomy.
   299 		 */
   315 		 */
   300 		$args = apply_filters( 'register_taxonomy_args', $args, $this->name, (array) $object_type );
   316 		$args = apply_filters( 'register_taxonomy_args', $args, $this->name, (array) $object_type );
       
   317 
       
   318 		$taxonomy = $this->name;
       
   319 
       
   320 		/**
       
   321 		 * Filters the arguments for registering a specific taxonomy.
       
   322 		 *
       
   323 		 * The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key.
       
   324 		 *
       
   325 		 * Possible hook names include:
       
   326 		 *
       
   327 		 *  - `register_category_taxonomy_args`
       
   328 		 *  - `register_post_tag_taxonomy_args`
       
   329 		 *
       
   330 		 * @since 6.0.0
       
   331 		 *
       
   332 		 * @param array    $args        Array of arguments for registering a taxonomy.
       
   333 		 *                              See the register_taxonomy() function for accepted arguments.
       
   334 		 * @param string   $taxonomy    Taxonomy key.
       
   335 		 * @param string[] $object_type Array of names of object types for the taxonomy.
       
   336 		 */
       
   337 		$args = apply_filters( "register_{$taxonomy}_taxonomy_args", $args, $this->name, (array) $object_type );
   301 
   338 
   302 		$defaults = array(
   339 		$defaults = array(
   303 			'labels'                => array(),
   340 			'labels'                => array(),
   304 			'description'           => '',
   341 			'description'           => '',
   305 			'public'                => true,
   342 			'public'                => true,
   317 			'rewrite'               => true,
   354 			'rewrite'               => true,
   318 			'query_var'             => $this->name,
   355 			'query_var'             => $this->name,
   319 			'update_count_callback' => '',
   356 			'update_count_callback' => '',
   320 			'show_in_rest'          => false,
   357 			'show_in_rest'          => false,
   321 			'rest_base'             => false,
   358 			'rest_base'             => false,
       
   359 			'rest_namespace'        => false,
   322 			'rest_controller_class' => false,
   360 			'rest_controller_class' => false,
   323 			'default_term'          => null,
   361 			'default_term'          => null,
   324 			'sort'                  => null,
   362 			'sort'                  => null,
   325 			'args'                  => null,
   363 			'args'                  => null,
   326 			'_builtin'              => false,
   364 			'_builtin'              => false,
   380 		}
   418 		}
   381 
   419 
   382 		// If not set, default to the setting for 'show_ui'.
   420 		// If not set, default to the setting for 'show_ui'.
   383 		if ( null === $args['show_in_quick_edit'] ) {
   421 		if ( null === $args['show_in_quick_edit'] ) {
   384 			$args['show_in_quick_edit'] = $args['show_ui'];
   422 			$args['show_in_quick_edit'] = $args['show_ui'];
       
   423 		}
       
   424 
       
   425 		// If not set, default rest_namespace to wp/v2 if show_in_rest is true.
       
   426 		if ( false === $args['rest_namespace'] && ! empty( $args['show_in_rest'] ) ) {
       
   427 			$args['rest_namespace'] = 'wp/v2';
   385 		}
   428 		}
   386 
   429 
   387 		$default_caps = array(
   430 		$default_caps = array(
   388 			'manage_terms' => 'manage_categories',
   431 			'manage_terms' => 'manage_categories',
   389 			'edit_terms'   => 'manage_categories',
   432 			'edit_terms'   => 'manage_categories',
   546 			return null;
   589 			return null;
   547 		}
   590 		}
   548 
   591 
   549 		return $this->rest_controller;
   592 		return $this->rest_controller;
   550 	}
   593 	}
       
   594 
       
   595 	/**
       
   596 	 * Returns the default labels for taxonomies.
       
   597 	 *
       
   598 	 * @since 6.0.0
       
   599 	 *
       
   600 	 * @return (string|null)[][] The default labels for taxonomies.
       
   601 	 */
       
   602 	public static function get_default_labels() {
       
   603 		if ( ! empty( self::$default_labels ) ) {
       
   604 			return self::$default_labels;
       
   605 		}
       
   606 
       
   607 		$name_field_description   = __( 'The name is how it appears on your site.' );
       
   608 		$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.' );
       
   609 		$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.' );
       
   610 		$desc_field_description   = __( 'The description is not prominent by default; however, some themes may show it.' );
       
   611 
       
   612 		self::$default_labels = array(
       
   613 			'name'                       => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
       
   614 			'singular_name'              => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
       
   615 			'search_items'               => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
       
   616 			'popular_items'              => array( __( 'Popular Tags' ), null ),
       
   617 			'all_items'                  => array( __( 'All Tags' ), __( 'All Categories' ) ),
       
   618 			'parent_item'                => array( null, __( 'Parent Category' ) ),
       
   619 			'parent_item_colon'          => array( null, __( 'Parent Category:' ) ),
       
   620 			'name_field_description'     => array( $name_field_description, $name_field_description ),
       
   621 			'slug_field_description'     => array( $slug_field_description, $slug_field_description ),
       
   622 			'parent_field_description'   => array( null, $parent_field_description ),
       
   623 			'desc_field_description'     => array( $desc_field_description, $desc_field_description ),
       
   624 			'edit_item'                  => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
       
   625 			'view_item'                  => array( __( 'View Tag' ), __( 'View Category' ) ),
       
   626 			'update_item'                => array( __( 'Update Tag' ), __( 'Update Category' ) ),
       
   627 			'add_new_item'               => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
       
   628 			'new_item_name'              => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
       
   629 			'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),
       
   630 			'add_or_remove_items'        => array( __( 'Add or remove tags' ), null ),
       
   631 			'choose_from_most_used'      => array( __( 'Choose from the most used tags' ), null ),
       
   632 			'not_found'                  => array( __( 'No tags found.' ), __( 'No categories found.' ) ),
       
   633 			'no_terms'                   => array( __( 'No tags' ), __( 'No categories' ) ),
       
   634 			'filter_by_item'             => array( null, __( 'Filter by category' ) ),
       
   635 			'items_list_navigation'      => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ),
       
   636 			'items_list'                 => array( __( 'Tags list' ), __( 'Categories list' ) ),
       
   637 			/* translators: Tab heading when selecting from the most used terms. */
       
   638 			'most_used'                  => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ),
       
   639 			'back_to_items'              => array( __( '← Go to Tags' ), __( '← Go to Categories' ) ),
       
   640 			'item_link'                  => array(
       
   641 				_x( 'Tag Link', 'navigation link block title' ),
       
   642 				_x( 'Category Link', 'navigation link block title' ),
       
   643 			),
       
   644 			'item_link_description'      => array(
       
   645 				_x( 'A link to a tag.', 'navigation link block description' ),
       
   646 				_x( 'A link to a category.', 'navigation link block description' ),
       
   647 			),
       
   648 		);
       
   649 
       
   650 		return self::$default_labels;
       
   651 	}
       
   652 
       
   653 	/**
       
   654 	 * Resets the cache for the default labels.
       
   655 	 *
       
   656 	 * @since 6.0.0
       
   657 	 */
       
   658 	public static function reset_default_labels() {
       
   659 		self::$default_labels = array();
       
   660 	}
   551 }
   661 }