wp/wp-includes/taxonomy.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    16  * This function fires twice: in wp-settings.php before plugins are loaded (for
    16  * This function fires twice: in wp-settings.php before plugins are loaded (for
    17  * backward compatibility reasons), and again on the {@see 'init'} action. We must
    17  * backward compatibility reasons), and again on the {@see 'init'} action. We must
    18  * avoid registering rewrite rules before the {@see 'init'} action.
    18  * avoid registering rewrite rules before the {@see 'init'} action.
    19  *
    19  *
    20  * @since 2.8.0
    20  * @since 2.8.0
       
    21  * @since 5.9.0 Added `'wp_template_part_area'` taxonomy.
    21  *
    22  *
    22  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    23  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    23  */
    24  */
    24 function create_initial_taxonomies() {
    25 function create_initial_taxonomies() {
    25 	global $wp_rewrite;
    26 	global $wp_rewrite;
       
    27 
       
    28 	WP_Taxonomy::reset_default_labels();
    26 
    29 
    27 	if ( ! did_action( 'init' ) ) {
    30 	if ( ! did_action( 'init' ) ) {
    28 		$rewrite = array(
    31 		$rewrite = array(
    29 			'category'    => false,
    32 			'category'    => false,
    30 			'post_tag'    => false,
    33 			'post_tag'    => false,
   105 
   108 
   106 	register_taxonomy(
   109 	register_taxonomy(
   107 		'nav_menu',
   110 		'nav_menu',
   108 		'nav_menu_item',
   111 		'nav_menu_item',
   109 		array(
   112 		array(
   110 			'public'            => false,
   113 			'public'                => false,
   111 			'hierarchical'      => false,
   114 			'hierarchical'          => false,
   112 			'labels'            => array(
   115 			'labels'                => array(
   113 				'name'          => __( 'Navigation Menus' ),
   116 				'name'          => __( 'Navigation Menus' ),
   114 				'singular_name' => __( 'Navigation Menu' ),
   117 				'singular_name' => __( 'Navigation Menu' ),
   115 			),
   118 			),
   116 			'query_var'         => false,
   119 			'query_var'             => false,
   117 			'rewrite'           => false,
   120 			'rewrite'               => false,
   118 			'show_ui'           => false,
   121 			'show_ui'               => false,
   119 			'_builtin'          => true,
   122 			'_builtin'              => true,
   120 			'show_in_nav_menus' => false,
   123 			'show_in_nav_menus'     => false,
       
   124 			'capabilities'          => array(
       
   125 				'manage_terms' => 'edit_theme_options',
       
   126 				'edit_terms'   => 'edit_theme_options',
       
   127 				'delete_terms' => 'edit_theme_options',
       
   128 				'assign_terms' => 'edit_theme_options',
       
   129 			),
       
   130 			'show_in_rest'          => true,
       
   131 			'rest_base'             => 'menus',
       
   132 			'rest_controller_class' => 'WP_REST_Menus_Controller',
   121 		)
   133 		)
   122 	);
   134 	);
   123 
   135 
   124 	register_taxonomy(
   136 	register_taxonomy(
   125 		'link_category',
   137 		'link_category',
   173 		)
   185 		)
   174 	);
   186 	);
   175 
   187 
   176 	register_taxonomy(
   188 	register_taxonomy(
   177 		'wp_theme',
   189 		'wp_theme',
   178 		array( 'wp_template' ),
   190 		array( 'wp_template', 'wp_template_part', 'wp_global_styles' ),
   179 		array(
   191 		array(
   180 			'public'            => false,
   192 			'public'            => false,
   181 			'hierarchical'      => false,
   193 			'hierarchical'      => false,
   182 			'labels'            => array(
   194 			'labels'            => array(
   183 				'name'          => __( 'Themes' ),
   195 				'name'          => __( 'Themes' ),
   189 			'_builtin'          => true,
   201 			'_builtin'          => true,
   190 			'show_in_nav_menus' => false,
   202 			'show_in_nav_menus' => false,
   191 			'show_in_rest'      => false,
   203 			'show_in_rest'      => false,
   192 		)
   204 		)
   193 	);
   205 	);
       
   206 
       
   207 	register_taxonomy(
       
   208 		'wp_template_part_area',
       
   209 		array( 'wp_template_part' ),
       
   210 		array(
       
   211 			'public'            => false,
       
   212 			'hierarchical'      => false,
       
   213 			'labels'            => array(
       
   214 				'name'          => __( 'Template Part Areas' ),
       
   215 				'singular_name' => __( 'Template Part Area' ),
       
   216 			),
       
   217 			'query_var'         => false,
       
   218 			'rewrite'           => false,
       
   219 			'show_ui'           => false,
       
   220 			'_builtin'          => true,
       
   221 			'show_in_nav_menus' => false,
       
   222 			'show_in_rest'      => false,
       
   223 		)
       
   224 	);
   194 }
   225 }
   195 
   226 
   196 /**
   227 /**
   197  * Retrieves a list of registered taxonomy names or objects.
   228  * Retrieves a list of registered taxonomy names or objects.
   198  *
   229  *
   199  * @since 3.0.0
   230  * @since 3.0.0
   200  *
   231  *
   201  * @global array $wp_taxonomies The registered taxonomies.
   232  * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
   202  *
   233  *
   203  * @param array  $args     Optional. An array of `key => value` arguments to match against the taxonomy objects.
   234  * @param array  $args     Optional. An array of `key => value` arguments to match against the taxonomy objects.
   204  *                         Default empty array.
   235  *                         Default empty array.
   205  * @param string $output   Optional. The type of output to return in the array. Accepts either taxonomy 'names'
   236  * @param string $output   Optional. The type of output to return in the array. Accepts either taxonomy 'names'
   206  *                         or 'objects'. Default 'names'.
   237  *                         or 'objects'. Default 'names'.
   216 
   247 
   217 	return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field );
   248 	return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field );
   218 }
   249 }
   219 
   250 
   220 /**
   251 /**
   221  * Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
   252  * Returns the names or objects of the taxonomies which are registered for the requested object or object type,
   222  * a post object or post type name.
   253  * such as a post object or post type name.
   223  *
   254  *
   224  * Example:
   255  * Example:
   225  *
   256  *
   226  *     $taxonomies = get_object_taxonomies( 'post' );
   257  *     $taxonomies = get_object_taxonomies( 'post' );
   227  *
   258  *
   229  *
   260  *
   230  *     Array( 'category', 'post_tag' )
   261  *     Array( 'category', 'post_tag' )
   231  *
   262  *
   232  * @since 2.3.0
   263  * @since 2.3.0
   233  *
   264  *
   234  * @global array $wp_taxonomies The registered taxonomies.
   265  * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
   235  *
   266  *
   236  * @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
   267  * @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
   237  * @param string                  $output Optional. The type of output to return in the array. Accepts either
   268  * @param string                  $output Optional. The type of output to return in the array. Accepts either
   238  *                                        'names' or 'objects'. Default 'names'.
   269  *                                        'names' or 'objects'. Default 'names'.
   239  * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
   270  * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
   270  * The get_taxonomy function will first check that the parameter string given
   301  * The get_taxonomy function will first check that the parameter string given
   271  * is a taxonomy object and if it is, it will return it.
   302  * is a taxonomy object and if it is, it will return it.
   272  *
   303  *
   273  * @since 2.3.0
   304  * @since 2.3.0
   274  *
   305  *
   275  * @global array $wp_taxonomies The registered taxonomies.
   306  * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
   276  *
   307  *
   277  * @param string $taxonomy Name of taxonomy object to return.
   308  * @param string $taxonomy Name of taxonomy object to return.
   278  * @return WP_Taxonomy|false The Taxonomy Object or false if $taxonomy doesn't exist.
   309  * @return WP_Taxonomy|false The taxonomy object or false if $taxonomy doesn't exist.
   279  */
   310  */
   280 function get_taxonomy( $taxonomy ) {
   311 function get_taxonomy( $taxonomy ) {
   281 	global $wp_taxonomies;
   312 	global $wp_taxonomies;
   282 
   313 
   283 	if ( ! taxonomy_exists( $taxonomy ) ) {
   314 	if ( ! taxonomy_exists( $taxonomy ) ) {
   296  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   327  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
   297  * Conditional Tags} article in the Theme Developer Handbook.
   328  * Conditional Tags} article in the Theme Developer Handbook.
   298  *
   329  *
   299  * @since 3.0.0
   330  * @since 3.0.0
   300  *
   331  *
   301  * @global array $wp_taxonomies The registered taxonomies.
   332  * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
   302  *
   333  *
   303  * @param string $taxonomy Name of taxonomy object.
   334  * @param string $taxonomy Name of taxonomy object.
   304  * @return bool Whether the taxonomy exists.
   335  * @return bool Whether the taxonomy exists.
   305  */
   336  */
   306 function taxonomy_exists( $taxonomy ) {
   337 function taxonomy_exists( $taxonomy ) {
   349  * @since 4.2.0 Introduced `show_in_quick_edit` argument.
   380  * @since 4.2.0 Introduced `show_in_quick_edit` argument.
   350  * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
   381  * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
   351  * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
   382  * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
   352  * @since 4.5.0 Introduced `publicly_queryable` argument.
   383  * @since 4.5.0 Introduced `publicly_queryable` argument.
   353  * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
   384  * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
   354  *              arguments to register the Taxonomy in REST API.
   385  *              arguments to register the taxonomy in REST API.
   355  * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
   386  * @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
   356  * @since 5.4.0 Added the registered taxonomy object as a return value.
   387  * @since 5.4.0 Added the registered taxonomy object as a return value.
   357  * @since 5.5.0 Introduced `default_term` argument.
   388  * @since 5.5.0 Introduced `default_term` argument.
   358  *
   389  * @since 5.9.0 Introduced `rest_namespace` argument.
   359  * @global array $wp_taxonomies Registered taxonomies.
   390  *
       
   391  * @global WP_Taxonomy[] $wp_taxonomies Registered taxonomies.
   360  *
   392  *
   361  * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
   393  * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
   362  * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
   394  * @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
   363  * @param array|string $args        {
   395  * @param array|string $args        {
   364  *     Optional. Array or query string of arguments for registering a taxonomy.
   396  *     Optional. Array or query string of arguments for registering a taxonomy.
   385  *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
   417  *     @type bool          $show_in_nav_menus     Makes this taxonomy available for selection in navigation menus. If not
   386  *                                                set, the default is inherited from `$public` (default true).
   418  *                                                set, the default is inherited from `$public` (default true).
   387  *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
   419  *     @type bool          $show_in_rest          Whether to include the taxonomy in the REST API. Set this to true
   388  *                                                for the taxonomy to be available in the block editor.
   420  *                                                for the taxonomy to be available in the block editor.
   389  *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
   421  *     @type string        $rest_base             To change the base url of REST API route. Default is $taxonomy.
       
   422  *     @type string        $rest_namespace        To change the namespace URL of REST API route. Default is wp/v2.
   390  *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
   423  *     @type string        $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
   391  *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
   424  *     @type bool          $show_tagcloud         Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
   392  *                                                the default is inherited from `$show_ui` (default true).
   425  *                                                the default is inherited from `$show_ui` (default true).
   393  *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
   426  *     @type bool          $show_in_quick_edit    Whether to show the taxonomy in the quick/bulk edit panel. It not set,
   394  *                                                the default is inherited from `$show_ui` (default true).
   427  *                                                the default is inherited from `$show_ui` (default true).
   494 	 * @param array|string $object_type Object type or array of object types.
   527 	 * @param array|string $object_type Object type or array of object types.
   495 	 * @param array        $args        Array of taxonomy registration arguments.
   528 	 * @param array        $args        Array of taxonomy registration arguments.
   496 	 */
   529 	 */
   497 	do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );
   530 	do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );
   498 
   531 
       
   532 	/**
       
   533 	 * Fires after a specific taxonomy is registered.
       
   534 	 *
       
   535 	 * The dynamic portion of the filter name, `$taxonomy`, refers to the taxonomy key.
       
   536 	 *
       
   537 	 * Possible hook names include:
       
   538 	 *
       
   539 	 *  - `registered_taxonomy_category`
       
   540 	 *  - `registered_taxonomy_post_tag`
       
   541 	 *
       
   542 	 * @since 6.0.0
       
   543 	 *
       
   544 	 * @param string       $taxonomy    Taxonomy slug.
       
   545 	 * @param array|string $object_type Object type or array of object types.
       
   546 	 * @param array        $args        Array of taxonomy registration arguments.
       
   547 	 */
       
   548 	do_action( "registered_taxonomy_{$taxonomy}", $taxonomy, $object_type, (array) $taxonomy_object );
       
   549 
   499 	return $taxonomy_object;
   550 	return $taxonomy_object;
   500 }
   551 }
   501 
   552 
   502 /**
   553 /**
   503  * Unregisters a taxonomy.
   554  * Unregisters a taxonomy.
   505  * Can not be used to unregister built-in taxonomies.
   556  * Can not be used to unregister built-in taxonomies.
   506  *
   557  *
   507  * @since 4.5.0
   558  * @since 4.5.0
   508  *
   559  *
   509  * @global WP    $wp            Current WordPress environment instance.
   560  * @global WP    $wp            Current WordPress environment instance.
   510  * @global array $wp_taxonomies List of taxonomies.
   561  * @global WP_Taxonomy[] $wp_taxonomies List of taxonomies.
   511  *
   562  *
   512  * @param string $taxonomy Taxonomy name.
   563  * @param string $taxonomy Taxonomy name.
   513  * @return true|WP_Error True on success, WP_Error on failure or if the taxonomy doesn't exist.
   564  * @return true|WP_Error True on success, WP_Error on failure or if the taxonomy doesn't exist.
   514  */
   565  */
   515 function unregister_taxonomy( $taxonomy ) {
   566 function unregister_taxonomy( $taxonomy ) {
   556  * @since 4.3.0 Added the `no_terms` label.
   607  * @since 4.3.0 Added the `no_terms` label.
   557  * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels.
   608  * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels.
   558  * @since 4.9.0 Added the `most_used` and `back_to_items` labels.
   609  * @since 4.9.0 Added the `most_used` and `back_to_items` labels.
   559  * @since 5.7.0 Added the `filter_by_item` label.
   610  * @since 5.7.0 Added the `filter_by_item` label.
   560  * @since 5.8.0 Added the `item_link` and `item_link_description` labels.
   611  * @since 5.8.0 Added the `item_link` and `item_link_description` labels.
       
   612  * @since 5.9.0 Added the `name_field_description`, `slug_field_description`,
       
   613  *              `parent_field_description`, and `desc_field_description` labels.
   561  *
   614  *
   562  * @param WP_Taxonomy $tax Taxonomy object.
   615  * @param WP_Taxonomy $tax Taxonomy object.
   563  * @return object {
   616  * @return object {
   564  *     Taxonomy labels object. The first default value is for non-hierarchical taxonomies
   617  *     Taxonomy labels object. The first default value is for non-hierarchical taxonomies
   565  *     (like tags) and the second one is for hierarchical taxonomies (like categories).
   618  *     (like tags) and the second one is for hierarchical taxonomies (like categories).
   572  *                                              Default 'Popular Tags'.
   625  *                                              Default 'Popular Tags'.
   573  *     @type string $all_items                  Default 'All Tags'/'All Categories'.
   626  *     @type string $all_items                  Default 'All Tags'/'All Categories'.
   574  *     @type string $parent_item                This label is only used for hierarchical taxonomies. Default
   627  *     @type string $parent_item                This label is only used for hierarchical taxonomies. Default
   575  *                                              'Parent Category'.
   628  *                                              'Parent Category'.
   576  *     @type string $parent_item_colon          The same as `parent_item`, but with colon `:` in the end.
   629  *     @type string $parent_item_colon          The same as `parent_item`, but with colon `:` in the end.
       
   630  *     @type string $name_field_description     Description for the Name field on Edit Tags screen.
       
   631  *                                              Default 'The name is how it appears on your site'.
       
   632  *     @type string $slug_field_description     Description for the Slug field on Edit Tags screen.
       
   633  *                                              Default 'The “slug” is the URL-friendly version
       
   634  *                                              of the name. It is usually all lowercase and contains
       
   635  *                                              only letters, numbers, and hyphens'.
       
   636  *     @type string $parent_field_description   Description for the Parent field on Edit Tags screen.
       
   637  *                                              Default 'Assign a parent term to create a hierarchy.
       
   638  *                                              The term Jazz, for example, would be the parent
       
   639  *                                              of Bebop and Big Band'.
       
   640  *     @type string $desc_field_description     Description for the Description field on Edit Tags screen.
       
   641  *                                              Default 'The description is not prominent by default;
       
   642  *                                              however, some themes may show it'.
   577  *     @type string $edit_item                  Default 'Edit Tag'/'Edit Category'.
   643  *     @type string $edit_item                  Default 'Edit Tag'/'Edit Category'.
   578  *     @type string $view_item                  Default 'View Tag'/'View Category'.
   644  *     @type string $view_item                  Default 'View Tag'/'View Category'.
   579  *     @type string $update_item                Default 'Update Tag'/'Update Category'.
   645  *     @type string $update_item                Default 'Update Tag'/'Update Category'.
   580  *     @type string $add_new_item               Default 'Add New Tag'/'Add New Category'.
   646  *     @type string $add_new_item               Default 'Add New Tag'/'Add New Category'.
   581  *     @type string $new_item_name              Default 'New Tag Name'/'New Category Name'.
   647  *     @type string $new_item_name              Default 'New Tag Name'/'New Category Name'.
   611 
   677 
   612 	if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) {
   678 	if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) {
   613 		$tax->labels['not_found'] = $tax->no_tagcloud;
   679 		$tax->labels['not_found'] = $tax->no_tagcloud;
   614 	}
   680 	}
   615 
   681 
   616 	$nohier_vs_hier_defaults = array(
   682 	$nohier_vs_hier_defaults = WP_Taxonomy::get_default_labels();
   617 		'name'                       => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
       
   618 		'singular_name'              => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
       
   619 		'search_items'               => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
       
   620 		'popular_items'              => array( __( 'Popular Tags' ), null ),
       
   621 		'all_items'                  => array( __( 'All Tags' ), __( 'All Categories' ) ),
       
   622 		'parent_item'                => array( null, __( 'Parent Category' ) ),
       
   623 		'parent_item_colon'          => array( null, __( 'Parent Category:' ) ),
       
   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 description' ),
       
   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 
   683 
   650 	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
   684 	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
   651 
   685 
   652 	$labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
   686 	$labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
   653 
   687 
   678 
   712 
   679 	return $labels;
   713 	return $labels;
   680 }
   714 }
   681 
   715 
   682 /**
   716 /**
   683  * Add an already registered taxonomy to an object type.
   717  * Adds an already registered taxonomy to an object type.
   684  *
   718  *
   685  * @since 3.0.0
   719  * @since 3.0.0
   686  *
   720  *
   687  * @global array $wp_taxonomies The registered taxonomies.
   721  * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
   688  *
   722  *
   689  * @param string $taxonomy    Name of taxonomy object.
   723  * @param string $taxonomy    Name of taxonomy object.
   690  * @param string $object_type Name of the object type.
   724  * @param string $object_type Name of the object type.
   691  * @return bool True if successful, false if not.
   725  * @return bool True if successful, false if not.
   692  */
   726  */
   720 
   754 
   721 	return true;
   755 	return true;
   722 }
   756 }
   723 
   757 
   724 /**
   758 /**
   725  * Remove an already registered taxonomy from an object type.
   759  * Removes an already registered taxonomy from an object type.
   726  *
   760  *
   727  * @since 3.7.0
   761  * @since 3.7.0
   728  *
   762  *
   729  * @global array $wp_taxonomies The registered taxonomies.
   763  * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
   730  *
   764  *
   731  * @param string $taxonomy    Name of taxonomy object.
   765  * @param string $taxonomy    Name of taxonomy object.
   732  * @param string $object_type Name of the object type.
   766  * @param string $object_type Name of the object type.
   733  * @return bool True if successful, false if not.
   767  * @return bool True if successful, false if not.
   734  */
   768  */
   766 //
   800 //
   767 // Term API.
   801 // Term API.
   768 //
   802 //
   769 
   803 
   770 /**
   804 /**
   771  * Retrieve object_ids of valid taxonomy and term.
   805  * Retrieves object IDs of valid taxonomy and term.
   772  *
   806  *
   773  * The strings of $taxonomies must exist before this function will continue.
   807  * The strings of `$taxonomies` must exist before this function will continue.
   774  * On failure of finding a valid taxonomy, it will return a WP_Error class,
   808  * On failure of finding a valid taxonomy, it will return a WP_Error.
   775  * kind of like Exceptions in PHP 5, except you can't catch them. Even so,
   809  *
   776  * you can still test for the WP_Error class and get the error message.
   810  * The `$terms` aren't checked the same as `$taxonomies`, but still need to exist
   777  *
   811  * for object IDs to be returned.
   778  * The $terms aren't checked the same as $taxonomies, but still need to exist
   812  *
   779  * for $object_ids to be returned.
   813  * It is possible to change the order that object IDs are returned by using `$args`
   780  *
   814  * with either ASC or DESC array. The value should be in the key named 'order'.
   781  * It is possible to change the order that object_ids is returned by either
       
   782  * using PHP sort family functions or using the database by using $args with
       
   783  * either ASC or DESC array. The value should be in the key named 'order'.
       
   784  *
   815  *
   785  * @since 2.3.0
   816  * @since 2.3.0
   786  *
   817  *
   787  * @global wpdb $wpdb WordPress database abstraction object.
   818  * @global wpdb $wpdb WordPress database abstraction object.
   788  *
   819  *
   789  * @param int|array    $term_ids   Term ID or array of term IDs of terms that will be used.
   820  * @param int|int[]       $term_ids   Term ID or array of term IDs of terms that will be used.
   790  * @param string|array $taxonomies String of taxonomy name or Array of string values of taxonomy names.
   821  * @param string|string[] $taxonomies String of taxonomy name or Array of string values of taxonomy names.
   791  * @param array|string $args       Change the order of the object_ids, either ASC or DESC.
   822  * @param array|string    $args       Change the order of the object IDs, either ASC or DESC.
   792  * @return array|WP_Error An array of $object_ids on success, WP_Error if the taxonomy does not exist.
   823  * @return string[]|WP_Error An array of object IDs as numeric strings on success,
       
   824  *                           WP_Error if the taxonomy does not exist.
   793  */
   825  */
   794 function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) {
   826 function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) {
   795 	global $wpdb;
   827 	global $wpdb;
   796 
   828 
   797 	if ( ! is_array( $term_ids ) ) {
   829 	if ( ! is_array( $term_ids ) ) {
   842  * @see WP_Tax_Query
   874  * @see WP_Tax_Query
   843  *
   875  *
   844  * @param array  $tax_query         A compact tax query
   876  * @param array  $tax_query         A compact tax query
   845  * @param string $primary_table
   877  * @param string $primary_table
   846  * @param string $primary_id_column
   878  * @param string $primary_id_column
   847  * @return array
   879  * @return string[]
   848  */
   880  */
   849 function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
   881 function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
   850 	$tax_query_obj = new WP_Tax_Query( $tax_query );
   882 	$tax_query_obj = new WP_Tax_Query( $tax_query );
   851 	return $tax_query_obj->get_sql( $primary_table, $primary_id_column );
   883 	return $tax_query_obj->get_sql( $primary_table, $primary_id_column );
   852 }
   884 }
   853 
   885 
   854 /**
   886 /**
   855  * Get all Term data from database by Term ID.
   887  * Gets all term data from database by term ID.
   856  *
   888  *
   857  * The usage of the get_term function is to apply filters to a term object. It
   889  * The usage of the get_term function is to apply filters to a term object. It
   858  * is possible to get a term object from the database before applying the
   890  * is possible to get a term object from the database before applying the
   859  * filters.
   891  * filters.
   860  *
   892  *
   863  * returns for the get_row method.
   895  * returns for the get_row method.
   864  *
   896  *
   865  * There are two hooks, one is specifically for each term, named 'get_term', and
   897  * There are two hooks, one is specifically for each term, named 'get_term', and
   866  * the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the
   898  * the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the
   867  * term object, and the taxonomy name as parameters. Both hooks are expected to
   899  * term object, and the taxonomy name as parameters. Both hooks are expected to
   868  * return a Term object.
   900  * return a term object.
   869  *
   901  *
   870  * {@see 'get_term'} hook - Takes two parameters the term Object and the taxonomy name.
   902  * {@see 'get_term'} hook - Takes two parameters the term Object and the taxonomy name.
   871  * Must return term object. Used in get_term() as a catch-all filter for every
   903  * Must return term object. Used in get_term() as a catch-all filter for every
   872  * $term.
   904  * $term.
   873  *
   905  *
   943 	$_term = apply_filters( 'get_term', $_term, $taxonomy );
   975 	$_term = apply_filters( 'get_term', $_term, $taxonomy );
   944 
   976 
   945 	/**
   977 	/**
   946 	 * Filters a taxonomy term object.
   978 	 * Filters a taxonomy term object.
   947 	 *
   979 	 *
   948 	 * The dynamic portion of the filter name, `$taxonomy`, refers
   980 	 * The dynamic portion of the hook name, `$taxonomy`, refers
   949 	 * to the slug of the term's taxonomy.
   981 	 * to the slug of the term's taxonomy.
       
   982 	 *
       
   983 	 * Possible hook names include:
       
   984 	 *
       
   985 	 *  - `get_category`
       
   986 	 *  - `get_post_tag`
   950 	 *
   987 	 *
   951 	 * @since 2.3.0
   988 	 * @since 2.3.0
   952 	 * @since 4.4.0 `$_term` is now a `WP_Term` object.
   989 	 * @since 4.4.0 `$_term` is now a `WP_Term` object.
   953 	 *
   990 	 *
   954 	 * @param WP_Term $_term    Term object.
   991 	 * @param WP_Term $_term    Term object.
   972 
  1009 
   973 	return $_term;
  1010 	return $_term;
   974 }
  1011 }
   975 
  1012 
   976 /**
  1013 /**
   977  * Get all Term data from database by Term field and data.
  1014  * Gets all term data from database by term field and data.
   978  *
  1015  *
   979  * Warning: $value is not escaped for 'name' $field. You must do it yourself, if
  1016  * Warning: $value is not escaped for 'name' $field. You must do it yourself, if
   980  * required.
  1017  * required.
   981  *
  1018  *
   982  * The default $field is 'id', therefore it is possible to also use null for
  1019  * The default $field is 'id', therefore it is possible to also use null for
   983  * field, but not recommended that you do so.
  1020  * field, but not recommended that you do so.
   984  *
  1021  *
   985  * If $value does not exist, the return value will be false. If $taxonomy exists
  1022  * If $value does not exist, the return value will be false. If $taxonomy exists
   986  * and $field and $value combinations exist, the Term will be returned.
  1023  * and $field and $value combinations exist, the term will be returned.
   987  *
  1024  *
   988  * This function will always return the first term that matches the `$field`-
  1025  * This function will always return the first term that matches the `$field`-
   989  * `$value`-`$taxonomy` combination specified in the parameters. If your query
  1026  * `$value`-`$taxonomy` combination specified in the parameters. If your query
   990  * is likely to match more than one term (as is likely to be the case when
  1027  * is likely to match more than one term (as is likely to be the case when
   991  * `$field` is 'name', for example), consider using get_terms() instead; that
  1028  * `$field` is 'name', for example), consider using get_terms() instead; that
   999  *              a WP_Term object if `$output` is `OBJECT`.
  1036  *              a WP_Term object if `$output` is `OBJECT`.
  1000  * @since 5.5.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
  1037  * @since 5.5.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
  1001  *
  1038  *
  1002  * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param.
  1039  * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param.
  1003  *
  1040  *
  1004  * @param string     $field    Either 'slug', 'name', 'id' or 'ID' (term_id), or 'term_taxonomy_id'.
  1041  * @param string     $field    Either 'slug', 'name', 'term_id' (or 'id', 'ID'), or 'term_taxonomy_id'.
  1005  * @param string|int $value    Search for this term value.
  1042  * @param string|int $value    Search for this term value.
  1006  * @param string     $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'.
  1043  * @param string     $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'.
  1007  * @param string     $output   Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
  1044  * @param string     $output   Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
  1008  *                             correspond to a WP_Term object, an associative array, or a numeric array,
  1045  *                             correspond to a WP_Term object, an associative array, or a numeric array,
  1009  *                             respectively. Default OBJECT.
  1046  *                             respectively. Default OBJECT.
  1073 
  1110 
  1074 	return get_term( $term, $taxonomy, $output, $filter );
  1111 	return get_term( $term, $taxonomy, $output, $filter );
  1075 }
  1112 }
  1076 
  1113 
  1077 /**
  1114 /**
  1078  * Merge all term children into a single array of their IDs.
  1115  * Merges all term children into a single array of their IDs.
  1079  *
  1116  *
  1080  * This recursive function will merge all of the children of $term into the same
  1117  * This recursive function will merge all of the children of $term into the same
  1081  * array of term IDs. Only useful for taxonomies which are hierarchical.
  1118  * array of term IDs. Only useful for taxonomies which are hierarchical.
  1082  *
  1119  *
  1083  * Will return an empty array if $term does not exist in $taxonomy.
  1120  * Will return an empty array if $term does not exist in $taxonomy.
  1084  *
  1121  *
  1085  * @since 2.3.0
  1122  * @since 2.3.0
  1086  *
  1123  *
  1087  * @param int    $term_id  ID of Term to get children.
  1124  * @param int    $term_id  ID of term to get children.
  1088  * @param string $taxonomy Taxonomy Name.
  1125  * @param string $taxonomy Taxonomy name.
  1089  * @return array|WP_Error List of Term IDs. WP_Error returned if `$taxonomy` does not exist.
  1126  * @return array|WP_Error List of term IDs. WP_Error returned if `$taxonomy` does not exist.
  1090  */
  1127  */
  1091 function get_term_children( $term_id, $taxonomy ) {
  1128 function get_term_children( $term_id, $taxonomy ) {
  1092 	if ( ! taxonomy_exists( $taxonomy ) ) {
  1129 	if ( ! taxonomy_exists( $taxonomy ) ) {
  1093 		return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
  1130 		return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
  1094 	}
  1131 	}
  1115 
  1152 
  1116 	return $children;
  1153 	return $children;
  1117 }
  1154 }
  1118 
  1155 
  1119 /**
  1156 /**
  1120  * Get sanitized Term field.
  1157  * Gets sanitized term field.
  1121  *
  1158  *
  1122  * The function is for contextual reasons and for simplicity of usage.
  1159  * The function is for contextual reasons and for simplicity of usage.
  1123  *
  1160  *
  1124  * @since 2.3.0
  1161  * @since 2.3.0
  1125  * @since 4.4.0 The `$taxonomy` parameter was made optional. `$term` can also now accept a WP_Term object.
  1162  * @since 4.4.0 The `$taxonomy` parameter was made optional. `$term` can also now accept a WP_Term object.
  1126  *
  1163  *
  1127  * @see sanitize_term_field()
  1164  * @see sanitize_term_field()
  1128  *
  1165  *
  1129  * @param string      $field    Term field to fetch.
  1166  * @param string      $field    Term field to fetch.
  1130  * @param int|WP_Term $term     Term ID or object.
  1167  * @param int|WP_Term $term     Term ID or object.
  1131  * @param string      $taxonomy Optional. Taxonomy Name. Default empty.
  1168  * @param string      $taxonomy Optional. Taxonomy name. Default empty.
  1132  * @param string      $context  Optional. How to sanitize term fields. Look at sanitize_term_field() for available options.
  1169  * @param string      $context  Optional. How to sanitize term fields. Look at sanitize_term_field() for available options.
  1133  *                              Default 'display'.
  1170  *                              Default 'display'.
  1134  * @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term.
  1171  * @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term.
  1135  */
  1172  */
  1136 function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
  1173 function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
  1149 
  1186 
  1150 	return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
  1187 	return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
  1151 }
  1188 }
  1152 
  1189 
  1153 /**
  1190 /**
  1154  * Sanitizes Term for editing.
  1191  * Sanitizes term for editing.
  1155  *
  1192  *
  1156  * Return value is sanitize_term() and usage is for sanitizing the term for
  1193  * Return value is sanitize_term() and usage is for sanitizing the term for
  1157  * editing. Function is for contextual and simplicity.
  1194  * editing. Function is for contextual and simplicity.
  1158  *
  1195  *
  1159  * @since 2.3.0
  1196  * @since 2.3.0
  1288 	 *
  1325 	 *
  1289 	 * @since 2.3.0
  1326 	 * @since 2.3.0
  1290 	 * @since 4.6.0 Added the `$term_query` parameter.
  1327 	 * @since 4.6.0 Added the `$term_query` parameter.
  1291 	 *
  1328 	 *
  1292 	 * @param array         $terms      Array of found terms.
  1329 	 * @param array         $terms      Array of found terms.
  1293 	 * @param array         $taxonomies An array of taxonomies.
  1330 	 * @param array|null    $taxonomies An array of taxonomies if known.
  1294 	 * @param array         $args       An array of get_terms() arguments.
  1331 	 * @param array         $args       An array of get_terms() arguments.
  1295 	 * @param WP_Term_Query $term_query The WP_Term_Query object.
  1332 	 * @param WP_Term_Query $term_query The WP_Term_Query object.
  1296 	 */
  1333 	 */
  1297 	return apply_filters( 'get_terms', $terms, $term_query->query_vars['taxonomy'], $term_query->query_vars, $term_query );
  1334 	return apply_filters( 'get_terms', $terms, $term_query->query_vars['taxonomy'], $term_query->query_vars, $term_query );
  1298 }
  1335 }
  1396 function update_termmeta_cache( $term_ids ) {
  1433 function update_termmeta_cache( $term_ids ) {
  1397 	return update_meta_cache( 'term', $term_ids );
  1434 	return update_meta_cache( 'term', $term_ids );
  1398 }
  1435 }
  1399 
  1436 
  1400 /**
  1437 /**
  1401  * Get all meta data, including meta IDs, for the given term ID.
  1438  * Gets all meta data, including meta IDs, for the given term ID.
  1402  *
  1439  *
  1403  * @since 4.9.0
  1440  * @since 4.9.0
  1404  *
  1441  *
  1405  * @global wpdb $wpdb WordPress database abstraction object.
  1442  * @global wpdb $wpdb WordPress database abstraction object.
  1406  *
  1443  *
  1459  * For more information on this and similar theme functions, check out
  1496  * For more information on this and similar theme functions, check out
  1460  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  1497  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  1461  * Conditional Tags} article in the Theme Developer Handbook.
  1498  * Conditional Tags} article in the Theme Developer Handbook.
  1462  *
  1499  *
  1463  * @since 3.0.0
  1500  * @since 3.0.0
  1464  *
  1501  * @since 6.0.0 Converted to use `get_terms()`.
  1465  * @global wpdb $wpdb WordPress database abstraction object.
  1502  *
       
  1503  * @global bool $_wp_suspend_cache_invalidation
  1466  *
  1504  *
  1467  * @param int|string $term     The term to check. Accepts term ID, slug, or name.
  1505  * @param int|string $term     The term to check. Accepts term ID, slug, or name.
  1468  * @param string     $taxonomy Optional. The taxonomy name to use.
  1506  * @param string     $taxonomy Optional. The taxonomy name to use.
  1469  * @param int        $parent   Optional. ID of parent term under which to confine the exists search.
  1507  * @param int        $parent   Optional. ID of parent term under which to confine the exists search.
  1470  * @return mixed Returns null if the term does not exist.
  1508  * @return mixed Returns null if the term does not exist.
  1471  *               Returns the term ID if no taxonomy is specified and the term ID exists.
  1509  *               Returns the term ID if no taxonomy is specified and the term ID exists.
  1472  *               Returns an array of the term ID and the term taxonomy ID if the taxonomy is specified and the pairing exists.
  1510  *               Returns an array of the term ID and the term taxonomy ID if the taxonomy is specified and the pairing exists.
  1473  *               Returns 0 if term ID 0 is passed to the function.
  1511  *               Returns 0 if term ID 0 is passed to the function.
  1474  */
  1512  */
  1475 function term_exists( $term, $taxonomy = '', $parent = null ) {
  1513 function term_exists( $term, $taxonomy = '', $parent = null ) {
  1476 	global $wpdb;
  1514 	global $_wp_suspend_cache_invalidation;
  1477 
  1515 
  1478 	$select     = "SELECT term_id FROM $wpdb->terms as t WHERE ";
  1516 	if ( null === $term ) {
  1479 	$tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";
  1517 		return null;
       
  1518 	}
       
  1519 
       
  1520 	$defaults = array(
       
  1521 		'get'                    => 'all',
       
  1522 		'fields'                 => 'ids',
       
  1523 		'number'                 => 1,
       
  1524 		'update_term_meta_cache' => false,
       
  1525 		'order'                  => 'ASC',
       
  1526 		'orderby'                => 'term_id',
       
  1527 		'suppress_filter'        => true,
       
  1528 	);
       
  1529 
       
  1530 	// Ensure that while importing, queries are not cached.
       
  1531 	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
       
  1532 		// @todo Disable caching once #52710 is merged.
       
  1533 		$defaults['cache_domain'] = microtime();
       
  1534 	}
       
  1535 
       
  1536 	if ( ! empty( $taxonomy ) ) {
       
  1537 		$defaults['taxonomy'] = $taxonomy;
       
  1538 		$defaults['fields']   = 'all';
       
  1539 	}
       
  1540 
       
  1541 	/**
       
  1542 	 * Filters default query arguments for checking if a term exists.
       
  1543 	 *
       
  1544 	 * @since 6.0.0
       
  1545 	 *
       
  1546 	 * @param array      $defaults An array of arguments passed to get_terms().
       
  1547 	 * @param int|string $term     The term to check. Accepts term ID, slug, or name.
       
  1548 	 * @param string     $taxonomy The taxonomy name to use. An empty string indicates
       
  1549 	 *                             the search is against all taxonomies.
       
  1550 	 * @param int|null   $parent   ID of parent term under which to confine the exists search.
       
  1551 	 *                             Null indicates the search is unconfined.
       
  1552 	 */
       
  1553 	$defaults = apply_filters( 'term_exists_default_query_args', $defaults, $term, $taxonomy, $parent );
  1480 
  1554 
  1481 	if ( is_int( $term ) ) {
  1555 	if ( is_int( $term ) ) {
  1482 		if ( 0 === $term ) {
  1556 		if ( 0 === $term ) {
  1483 			return 0;
  1557 			return 0;
  1484 		}
  1558 		}
  1485 		$where = 't.term_id = %d';
  1559 		$args  = wp_parse_args( array( 'include' => array( $term ) ), $defaults );
  1486 		if ( ! empty( $taxonomy ) ) {
  1560 		$terms = get_terms( $args );
  1487 			// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
  1561 	} else {
  1488 			return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . ' AND tt.taxonomy = %s', $term, $taxonomy ), ARRAY_A );
  1562 		$term = trim( wp_unslash( $term ) );
  1489 		} else {
  1563 		if ( '' === $term ) {
  1490 			return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) );
  1564 			return null;
  1491 		}
  1565 		}
  1492 	}
  1566 
  1493 
  1567 		if ( ! empty( $taxonomy ) && is_numeric( $parent ) ) {
  1494 	$term = trim( wp_unslash( $term ) );
  1568 			$defaults['parent'] = (int) $parent;
  1495 	$slug = sanitize_title( $term );
  1569 		}
  1496 
  1570 
  1497 	$where             = 't.slug = %s';
  1571 		$args  = wp_parse_args( array( 'slug' => sanitize_title( $term ) ), $defaults );
  1498 	$else_where        = 't.name = %s';
  1572 		$terms = get_terms( $args );
  1499 	$where_fields      = array( $slug );
  1573 		if ( empty( $terms ) || is_wp_error( $terms ) ) {
  1500 	$else_where_fields = array( $term );
  1574 			$args  = wp_parse_args( array( 'name' => $term ), $defaults );
  1501 	$orderby           = 'ORDER BY t.term_id ASC';
  1575 			$terms = get_terms( $args );
  1502 	$limit             = 'LIMIT 1';
  1576 		}
       
  1577 	}
       
  1578 
       
  1579 	if ( empty( $terms ) || is_wp_error( $terms ) ) {
       
  1580 		return null;
       
  1581 	}
       
  1582 
       
  1583 	$_term = array_shift( $terms );
       
  1584 
  1503 	if ( ! empty( $taxonomy ) ) {
  1585 	if ( ! empty( $taxonomy ) ) {
  1504 		if ( is_numeric( $parent ) ) {
  1586 		return array(
  1505 			$parent              = (int) $parent;
  1587 			'term_id'          => (string) $_term->term_id,
  1506 			$where_fields[]      = $parent;
  1588 			'term_taxonomy_id' => (string) $_term->term_taxonomy_id,
  1507 			$else_where_fields[] = $parent;
  1589 		);
  1508 			$where              .= ' AND tt.parent = %d';
  1590 	}
  1509 			$else_where         .= ' AND tt.parent = %d';
  1591 
  1510 		}
  1592 	return (string) $_term;
  1511 
  1593 }
  1512 		$where_fields[]      = $taxonomy;
  1594 
  1513 		$else_where_fields[] = $taxonomy;
  1595 /**
  1514 
  1596  * Checks if a term is an ancestor of another term.
  1515 		$result = $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields ), ARRAY_A );
       
  1516 		if ( $result ) {
       
  1517 			return $result;
       
  1518 		}
       
  1519 
       
  1520 		return $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields ), ARRAY_A );
       
  1521 	}
       
  1522 
       
  1523 	// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
       
  1524 	$result = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields ) );
       
  1525 	if ( $result ) {
       
  1526 		return $result;
       
  1527 	}
       
  1528 
       
  1529 	// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
       
  1530 	return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields ) );
       
  1531 }
       
  1532 
       
  1533 /**
       
  1534  * Check if a term is an ancestor of another term.
       
  1535  *
  1597  *
  1536  * You can use either an ID or the term object for both parameters.
  1598  * You can use either an ID or the term object for both parameters.
  1537  *
  1599  *
  1538  * @since 3.4.0
  1600  * @since 3.4.0
  1539  *
  1601  *
  1559 
  1621 
  1560 	return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy );
  1622 	return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy );
  1561 }
  1623 }
  1562 
  1624 
  1563 /**
  1625 /**
  1564  * Sanitize all term fields.
  1626  * Sanitizes all term fields.
  1565  *
  1627  *
  1566  * Relies on sanitize_term_field() to sanitize the term. The difference is that
  1628  * Relies on sanitize_term_field() to sanitize the term. The difference is that
  1567  * this function will sanitize **all** fields. The context is based
  1629  * this function will sanitize **all** fields. The context is based
  1568  * on sanitize_term_field().
  1630  * on sanitize_term_field().
  1569  *
  1631  *
  1605 
  1667 
  1606 	return $term;
  1668 	return $term;
  1607 }
  1669 }
  1608 
  1670 
  1609 /**
  1671 /**
  1610  * Cleanse the field value in the term based on the context.
  1672  * Sanitizes the field value in the term based on the context.
  1611  *
  1673  *
  1612  * Passing a term field value through the function should be assumed to have
  1674  * Passing a term field value through the function should be assumed to have
  1613  * cleansed the value for whatever context the term field is going to be used.
  1675  * cleansed the value for whatever context the term field is going to be used.
  1614  *
  1676  *
  1615  * If no context or an unsupported context is given, then default filters will
  1677  * If no context or an unsupported context is given, then default filters will
  1622  * @since 2.3.0
  1684  * @since 2.3.0
  1623  *
  1685  *
  1624  * @param string $field    Term field to sanitize.
  1686  * @param string $field    Term field to sanitize.
  1625  * @param string $value    Search for this term value.
  1687  * @param string $value    Search for this term value.
  1626  * @param int    $term_id  Term ID.
  1688  * @param int    $term_id  Term ID.
  1627  * @param string $taxonomy Taxonomy Name.
  1689  * @param string $taxonomy Taxonomy name.
  1628  * @param string $context  Context in which to sanitize the term field.
  1690  * @param string $context  Context in which to sanitize the term field.
  1629  *                         Accepts 'raw', 'edit', 'db', 'display', 'rss',
  1691  *                         Accepts 'raw', 'edit', 'db', 'display', 'rss',
  1630  *                         'attribute', or 'js'. Default 'display'.
  1692  *                         'attribute', or 'js'. Default 'display'.
  1631  * @return mixed Sanitized field.
  1693  * @return mixed Sanitized field.
  1632  */
  1694  */
  1648 	if ( 'edit' === $context ) {
  1710 	if ( 'edit' === $context ) {
  1649 
  1711 
  1650 		/**
  1712 		/**
  1651 		 * Filters a term field to edit before it is sanitized.
  1713 		 * Filters a term field to edit before it is sanitized.
  1652 		 *
  1714 		 *
  1653 		 * The dynamic portion of the filter name, `$field`, refers to the term field.
  1715 		 * The dynamic portion of the hook name, `$field`, refers to the term field.
  1654 		 *
  1716 		 *
  1655 		 * @since 2.3.0
  1717 		 * @since 2.3.0
  1656 		 *
  1718 		 *
  1657 		 * @param mixed $value     Value of the term field.
  1719 		 * @param mixed $value     Value of the term field.
  1658 		 * @param int   $term_id   Term ID.
  1720 		 * @param int   $term_id   Term ID.
  1681 	} elseif ( 'db' === $context ) {
  1743 	} elseif ( 'db' === $context ) {
  1682 
  1744 
  1683 		/**
  1745 		/**
  1684 		 * Filters a term field value before it is sanitized.
  1746 		 * Filters a term field value before it is sanitized.
  1685 		 *
  1747 		 *
  1686 		 * The dynamic portion of the filter name, `$field`, refers to the term field.
  1748 		 * The dynamic portion of the hook name, `$field`, refers to the term field.
  1687 		 *
  1749 		 *
  1688 		 * @since 2.3.0
  1750 		 * @since 2.3.0
  1689 		 *
  1751 		 *
  1690 		 * @param mixed  $value    Value of the term field.
  1752 		 * @param mixed  $value    Value of the term field.
  1691 		 * @param string $taxonomy Taxonomy slug.
  1753 		 * @param string $taxonomy Taxonomy slug.
  1720 	} elseif ( 'rss' === $context ) {
  1782 	} elseif ( 'rss' === $context ) {
  1721 
  1783 
  1722 		/**
  1784 		/**
  1723 		 * Filters the term field for use in RSS.
  1785 		 * Filters the term field for use in RSS.
  1724 		 *
  1786 		 *
  1725 		 * The dynamic portion of the filter name, `$field`, refers to the term field.
  1787 		 * The dynamic portion of the hook name, `$field`, refers to the term field.
  1726 		 *
  1788 		 *
  1727 		 * @since 2.3.0
  1789 		 * @since 2.3.0
  1728 		 *
  1790 		 *
  1729 		 * @param mixed  $value    Value of the term field.
  1791 		 * @param mixed  $value    Value of the term field.
  1730 		 * @param string $taxonomy Taxonomy slug.
  1792 		 * @param string $taxonomy Taxonomy slug.
  1746 		// Use display filters by default.
  1808 		// Use display filters by default.
  1747 
  1809 
  1748 		/**
  1810 		/**
  1749 		 * Filters the term field sanitized for display.
  1811 		 * Filters the term field sanitized for display.
  1750 		 *
  1812 		 *
  1751 		 * The dynamic portion of the filter name, `$field`, refers to the term field name.
  1813 		 * The dynamic portion of the hook name, `$field`, refers to the term field name.
  1752 		 *
  1814 		 *
  1753 		 * @since 2.3.0
  1815 		 * @since 2.3.0
  1754 		 *
  1816 		 *
  1755 		 * @param mixed  $value    Value of the term field.
  1817 		 * @param mixed  $value    Value of the term field.
  1756 		 * @param int    $term_id  Term ID.
  1818 		 * @param int    $term_id  Term ID.
  1787 
  1849 
  1788 	return $value;
  1850 	return $value;
  1789 }
  1851 }
  1790 
  1852 
  1791 /**
  1853 /**
  1792  * Count how many terms are in Taxonomy.
  1854  * Counts how many terms are in taxonomy.
  1793  *
  1855  *
  1794  * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).
  1856  * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).
  1795  *
  1857  *
  1796  * @since 2.3.0
  1858  * @since 2.3.0
  1797  * @since 5.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
  1859  * @since 5.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
  1837 
  1899 
  1838 	return get_terms( $args );
  1900 	return get_terms( $args );
  1839 }
  1901 }
  1840 
  1902 
  1841 /**
  1903 /**
  1842  * Will unlink the object from the taxonomy or taxonomies.
  1904  * Unlinks the object from the taxonomy or taxonomies.
  1843  *
  1905  *
  1844  * Will remove all relationships between the object and any terms in
  1906  * Will remove all relationships between the object and any terms in
  1845  * a particular taxonomy or taxonomies. Does not remove the term or
  1907  * a particular taxonomy or taxonomies. Does not remove the term or
  1846  * taxonomy itself.
  1908  * taxonomy itself.
  1847  *
  1909  *
  1848  * @since 2.3.0
  1910  * @since 2.3.0
  1849  *
  1911  *
  1850  * @param int          $object_id  The term Object Id that refers to the term.
  1912  * @param int          $object_id  The term object ID that refers to the term.
  1851  * @param string|array $taxonomies List of Taxonomy Names or single Taxonomy name.
  1913  * @param string|array $taxonomies List of taxonomy names or single taxonomy name.
  1852  */
  1914  */
  1853 function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
  1915 function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
  1854 	$object_id = (int) $object_id;
  1916 	$object_id = (int) $object_id;
  1855 
  1917 
  1856 	if ( ! is_array( $taxonomies ) ) {
  1918 	if ( ! is_array( $taxonomies ) ) {
  1875  * @since 2.3.0
  1937  * @since 2.3.0
  1876  *
  1938  *
  1877  * @global wpdb $wpdb WordPress database abstraction object.
  1939  * @global wpdb $wpdb WordPress database abstraction object.
  1878  *
  1940  *
  1879  * @param int          $term     Term ID.
  1941  * @param int          $term     Term ID.
  1880  * @param string       $taxonomy Taxonomy Name.
  1942  * @param string       $taxonomy Taxonomy name.
  1881  * @param array|string $args {
  1943  * @param array|string $args {
  1882  *     Optional. Array of arguments to override the default term ID. Default empty array.
  1944  *     Optional. Array of arguments to override the default term ID. Default empty array.
  1883  *
  1945  *
  1884  *     @type int  $default       The term ID to make the default term. This will only override
  1946  *     @type int  $default       The term ID to make the default term. This will only override
  1885  *                               the terms found if there is only one term found. Any other and
  1947  *                               the terms found if there is only one term found. Any other and
  1941 	 * Fires when deleting a term, before any modifications are made to posts or terms.
  2003 	 * Fires when deleting a term, before any modifications are made to posts or terms.
  1942 	 *
  2004 	 *
  1943 	 * @since 4.1.0
  2005 	 * @since 4.1.0
  1944 	 *
  2006 	 *
  1945 	 * @param int    $term     Term ID.
  2007 	 * @param int    $term     Term ID.
  1946 	 * @param string $taxonomy Taxonomy Name.
  2008 	 * @param string $taxonomy Taxonomy name.
  1947 	 */
  2009 	 */
  1948 	do_action( 'pre_delete_term', $term, $taxonomy );
  2010 	do_action( 'pre_delete_term', $term, $taxonomy );
  1949 
  2011 
  1950 	// Update children to point to new parent.
  2012 	// Update children to point to new parent.
  1951 	if ( is_taxonomy_hierarchical( $taxonomy ) ) {
  2013 	if ( is_taxonomy_hierarchical( $taxonomy ) ) {
  2225 	 */
  2287 	 */
  2226 	return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
  2288 	return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
  2227 }
  2289 }
  2228 
  2290 
  2229 /**
  2291 /**
  2230  * Add a new term to the database.
  2292  * Adds a new term to the database.
  2231  *
  2293  *
  2232  * A non-existent term is inserted in the following sequence:
  2294  * A non-existent term is inserted in the following sequence:
  2233  * 1. The term is added to the term table, then related to the taxonomy.
  2295  * 1. The term is added to the term table, then related to the taxonomy.
  2234  * 2. If everything is correct, several actions are fired.
  2296  * 2. If everything is correct, several actions are fired.
  2235  * 3. The 'term_id_filter' is evaluated.
  2297  * 3. The 'term_id_filter' is evaluated.
  2469 	 * Sanity check: if we just created a term with the same parent + taxonomy + slug but a higher term_id than
  2531 	 * Sanity check: if we just created a term with the same parent + taxonomy + slug but a higher term_id than
  2470 	 * an existing term, then we have unwittingly created a duplicate term. Delete the dupe, and use the term_id
  2532 	 * an existing term, then we have unwittingly created a duplicate term. Delete the dupe, and use the term_id
  2471 	 * and term_taxonomy_id of the older term instead. Then return out of the function so that the "create" hooks
  2533 	 * and term_taxonomy_id of the older term instead. Then return out of the function so that the "create" hooks
  2472 	 * are not fired.
  2534 	 * are not fired.
  2473 	 */
  2535 	 */
  2474 	$duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) );
  2536 	$duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) );
  2475 
  2537 
  2476 	/**
  2538 	/**
  2477 	 * Filters the duplicate term check that takes place during term creation.
  2539 	 * Filters the duplicate term check that takes place during term creation.
  2478 	 *
  2540 	 *
  2479 	 * Term parent+taxonomy+slug combinations are meant to be unique, and wp_insert_term()
  2541 	 * Term parent + taxonomy + slug combinations are meant to be unique, and wp_insert_term()
  2480 	 * performs a last-minute confirmation of this uniqueness before allowing a new term
  2542 	 * performs a last-minute confirmation of this uniqueness before allowing a new term
  2481 	 * to be created. Plugins with different uniqueness requirements may use this filter
  2543 	 * to be created. Plugins with different uniqueness requirements may use this filter
  2482 	 * to bypass or modify the duplicate-term check.
  2544 	 * to bypass or modify the duplicate-term check.
  2483 	 *
  2545 	 *
  2484 	 * @since 5.1.0
  2546 	 * @since 5.1.0
  2620 		'term_taxonomy_id' => $tt_id,
  2682 		'term_taxonomy_id' => $tt_id,
  2621 	);
  2683 	);
  2622 }
  2684 }
  2623 
  2685 
  2624 /**
  2686 /**
  2625  * Create Term and Taxonomy Relationships.
  2687  * Creates term and taxonomy relationships.
  2626  *
  2688  *
  2627  * Relates an object (post, link etc) to a term and taxonomy type. Creates the
  2689  * Relates an object (post, link, etc.) to a term and taxonomy type. Creates the
  2628  * term and taxonomy relationship if it doesn't already exist. Creates a term if
  2690  * term and taxonomy relationship if it doesn't already exist. Creates a term if
  2629  * it doesn't exist (using the slug).
  2691  * it doesn't exist (using the slug).
  2630  *
  2692  *
  2631  * A relationship means that the term is grouped in or belongs to the taxonomy.
  2693  * A relationship means that the term is grouped in or belongs to the taxonomy.
  2632  * A term has no meaning until it is given context by defining which taxonomy it
  2694  * A term has no meaning until it is given context by defining which taxonomy it
  2804 
  2866 
  2805 	return $tt_ids;
  2867 	return $tt_ids;
  2806 }
  2868 }
  2807 
  2869 
  2808 /**
  2870 /**
  2809  * Add term(s) associated with a given object.
  2871  * Adds term(s) associated with a given object.
  2810  *
  2872  *
  2811  * @since 3.6.0
  2873  * @since 3.6.0
  2812  *
  2874  *
  2813  * @param int              $object_id The ID of the object to which the terms will be added.
  2875  * @param int              $object_id The ID of the object to which the terms will be added.
  2814  * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to add.
  2876  * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to add.
  2818 function wp_add_object_terms( $object_id, $terms, $taxonomy ) {
  2880 function wp_add_object_terms( $object_id, $terms, $taxonomy ) {
  2819 	return wp_set_object_terms( $object_id, $terms, $taxonomy, true );
  2881 	return wp_set_object_terms( $object_id, $terms, $taxonomy, true );
  2820 }
  2882 }
  2821 
  2883 
  2822 /**
  2884 /**
  2823  * Remove term(s) associated with a given object.
  2885  * Removes term(s) associated with a given object.
  2824  *
  2886  *
  2825  * @since 3.6.0
  2887  * @since 3.6.0
  2826  *
  2888  *
  2827  * @global wpdb $wpdb WordPress database abstraction object.
  2889  * @global wpdb $wpdb WordPress database abstraction object.
  2828  *
  2890  *
  2829  * @param int              $object_id The ID of the object from which the terms will be removed.
  2891  * @param int              $object_id The ID of the object from which the terms will be removed.
  2830  * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
  2892  * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
  2831  * @param array|string     $taxonomy  Taxonomy name.
  2893  * @param string           $taxonomy  Taxonomy name.
  2832  * @return bool|WP_Error True on success, false or WP_Error on failure.
  2894  * @return bool|WP_Error True on success, false or WP_Error on failure.
  2833  */
  2895  */
  2834 function wp_remove_object_terms( $object_id, $terms, $taxonomy ) {
  2896 function wp_remove_object_terms( $object_id, $terms, $taxonomy ) {
  2835 	global $wpdb;
  2897 	global $wpdb;
  2836 
  2898 
  2873 		 * Fires immediately before an object-term relationship is deleted.
  2935 		 * Fires immediately before an object-term relationship is deleted.
  2874 		 *
  2936 		 *
  2875 		 * @since 2.9.0
  2937 		 * @since 2.9.0
  2876 		 * @since 4.7.0 Added the `$taxonomy` parameter.
  2938 		 * @since 4.7.0 Added the `$taxonomy` parameter.
  2877 		 *
  2939 		 *
  2878 		 * @param int   $object_id Object ID.
  2940 		 * @param int    $object_id Object ID.
  2879 		 * @param array $tt_ids    An array of term taxonomy IDs.
  2941 		 * @param array  $tt_ids    An array of term taxonomy IDs.
  2880 		 * @param string $taxonomy  Taxonomy slug.
  2942 		 * @param string $taxonomy  Taxonomy slug.
  2881 		 */
  2943 		 */
  2882 		do_action( 'delete_term_relationships', $object_id, $tt_ids, $taxonomy );
  2944 		do_action( 'delete_term_relationships', $object_id, $tt_ids, $taxonomy );
  2883 
  2945 
  2884 		$deleted = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id ) );
  2946 		$deleted = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id ) );
  2905 
  2967 
  2906 	return false;
  2968 	return false;
  2907 }
  2969 }
  2908 
  2970 
  2909 /**
  2971 /**
  2910  * Will make slug unique, if it isn't already.
  2972  * Makes term slug unique, if it isn't already.
  2911  *
  2973  *
  2912  * The `$slug` has to be unique global to every taxonomy, meaning that one
  2974  * The `$slug` has to be unique global to every taxonomy, meaning that one
  2913  * taxonomy term can't have a matching slug with another taxonomy term. Each
  2975  * taxonomy term can't have a matching slug with another taxonomy term. Each
  2914  * slug has to be globally unique for every taxonomy.
  2976  * slug has to be globally unique for every taxonomy.
  2915  *
  2977  *
  3008 	 */
  3070 	 */
  3009 	return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug );
  3071 	return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug );
  3010 }
  3072 }
  3011 
  3073 
  3012 /**
  3074 /**
  3013  * Update term based on arguments provided.
  3075  * Updates term based on arguments provided.
  3014  *
  3076  *
  3015  * The `$args` will indiscriminately override all values with the same field name.
  3077  * The `$args` will indiscriminately override all values with the same field name.
  3016  * Care must be taken to not override important information need to update or
  3078  * Care must be taken to not override important information need to update or
  3017  * update will fail (or perhaps create a new term, neither would be acceptable).
  3079  * update will fail (or perhaps create a new term, neither would be acceptable).
  3018  *
  3080  *
  3203 	 * Fires immediately after a term is updated in the database, but before its
  3265 	 * Fires immediately after a term is updated in the database, but before its
  3204 	 * term-taxonomy relationship is updated.
  3266 	 * term-taxonomy relationship is updated.
  3205 	 *
  3267 	 *
  3206 	 * @since 2.9.0
  3268 	 * @since 2.9.0
  3207 	 *
  3269 	 *
  3208 	 * @param int    $term_id  Term ID
  3270 	 * @param int    $term_id  Term ID.
  3209 	 * @param string $taxonomy Taxonomy slug.
  3271 	 * @param string $taxonomy Taxonomy slug.
  3210 	 */
  3272 	 */
  3211 	do_action( 'edited_terms', $term_id, $taxonomy );
  3273 	do_action( 'edited_terms', $term_id, $taxonomy );
  3212 
  3274 
  3213 	/**
  3275 	/**
  3312 		'term_taxonomy_id' => $tt_id,
  3374 		'term_taxonomy_id' => $tt_id,
  3313 	);
  3375 	);
  3314 }
  3376 }
  3315 
  3377 
  3316 /**
  3378 /**
  3317  * Enable or disable term counting.
  3379  * Enables or disables term counting.
  3318  *
  3380  *
  3319  * @since 2.5.0
  3381  * @since 2.5.0
  3320  *
  3382  *
  3321  * @param bool $defer Optional. Enable if true, disable if false.
  3383  * @param bool $defer Optional. Enable if true, disable if false.
  3322  * @return bool Whether term counting is enabled or disabled.
  3384  * @return bool Whether term counting is enabled or disabled.
  3379 
  3441 
  3380 	return wp_update_term_count_now( $terms, $taxonomy );
  3442 	return wp_update_term_count_now( $terms, $taxonomy );
  3381 }
  3443 }
  3382 
  3444 
  3383 /**
  3445 /**
  3384  * Perform term count update immediately.
  3446  * Performs term count update immediately.
  3385  *
  3447  *
  3386  * @since 2.5.0
  3448  * @since 2.5.0
  3387  *
  3449  *
  3388  * @param array  $terms    The term_taxonomy_id of terms to update.
  3450  * @param array  $terms    The term_taxonomy_id of terms to update.
  3389  * @param string $taxonomy The context of the term.
  3451  * @param string $taxonomy The context of the term.
  3448 		$object_ids = array( $object_ids );
  3510 		$object_ids = array( $object_ids );
  3449 	}
  3511 	}
  3450 
  3512 
  3451 	$taxonomies = get_object_taxonomies( $object_type );
  3513 	$taxonomies = get_object_taxonomies( $object_type );
  3452 
  3514 
  3453 	foreach ( $object_ids as $id ) {
  3515 	foreach ( $taxonomies as $taxonomy ) {
  3454 		foreach ( $taxonomies as $taxonomy ) {
  3516 		wp_cache_delete_multiple( $object_ids, "{$taxonomy}_relationships" );
  3455 			wp_cache_delete( $id, "{$taxonomy}_relationships" );
  3517 	}
  3456 		}
  3518 
  3457 	}
  3519 	wp_cache_delete( 'last_changed', 'terms' );
  3458 
  3520 
  3459 	/**
  3521 	/**
  3460 	 * Fires after the object term cache has been cleaned.
  3522 	 * Fires after the object term cache has been cleaned.
  3461 	 *
  3523 	 *
  3462 	 * @since 2.5.0
  3524 	 * @since 2.5.0
  3466 	 */
  3528 	 */
  3467 	do_action( 'clean_object_term_cache', $object_ids, $object_type );
  3529 	do_action( 'clean_object_term_cache', $object_ids, $object_type );
  3468 }
  3530 }
  3469 
  3531 
  3470 /**
  3532 /**
  3471  * Will remove all of the term IDs from the cache.
  3533  * Removes all of the term IDs from the cache.
  3472  *
  3534  *
  3473  * @since 2.3.0
  3535  * @since 2.3.0
  3474  *
  3536  *
  3475  * @global wpdb $wpdb                           WordPress database abstraction object.
  3537  * @global wpdb $wpdb                           WordPress database abstraction object.
  3476  * @global bool $_wp_suspend_cache_invalidation
  3538  * @global bool $_wp_suspend_cache_invalidation
  3501 		$ids    = array();
  3563 		$ids    = array();
  3502 
  3564 
  3503 		foreach ( (array) $terms as $term ) {
  3565 		foreach ( (array) $terms as $term ) {
  3504 			$taxonomies[] = $term->taxonomy;
  3566 			$taxonomies[] = $term->taxonomy;
  3505 			$ids[]        = $term->term_id;
  3567 			$ids[]        = $term->term_id;
  3506 			wp_cache_delete( $term->term_id, 'terms' );
  3568 		}
  3507 		}
  3569 		wp_cache_delete_multiple( $ids, 'terms' );
  3508 
       
  3509 		$taxonomies = array_unique( $taxonomies );
  3570 		$taxonomies = array_unique( $taxonomies );
  3510 	} else {
  3571 	} else {
       
  3572 		wp_cache_delete_multiple( $ids, 'terms' );
  3511 		$taxonomies = array( $taxonomy );
  3573 		$taxonomies = array( $taxonomy );
  3512 
       
  3513 		foreach ( $taxonomies as $taxonomy ) {
       
  3514 			foreach ( $ids as $id ) {
       
  3515 				wp_cache_delete( $id, 'terms' );
       
  3516 			}
       
  3517 		}
       
  3518 	}
  3574 	}
  3519 
  3575 
  3520 	foreach ( $taxonomies as $taxonomy ) {
  3576 	foreach ( $taxonomies as $taxonomy ) {
  3521 		if ( $clean_taxonomy ) {
  3577 		if ( $clean_taxonomy ) {
  3522 			clean_taxonomy_cache( $taxonomy );
  3578 			clean_taxonomy_cache( $taxonomy );
  3537 
  3593 
  3538 	wp_cache_set( 'last_changed', microtime(), 'terms' );
  3594 	wp_cache_set( 'last_changed', microtime(), 'terms' );
  3539 }
  3595 }
  3540 
  3596 
  3541 /**
  3597 /**
  3542  * Clean the caches for a taxonomy.
  3598  * Cleans the caches for a taxonomy.
  3543  *
  3599  *
  3544  * @since 4.9.0
  3600  * @since 4.9.0
  3545  *
  3601  *
  3546  * @param string $taxonomy Taxonomy slug.
  3602  * @param string $taxonomy Taxonomy slug.
  3547  */
  3603  */
  3548 function clean_taxonomy_cache( $taxonomy ) {
  3604 function clean_taxonomy_cache( $taxonomy ) {
  3549 	wp_cache_delete( 'all_ids', $taxonomy );
  3605 	wp_cache_delete( 'all_ids', $taxonomy );
  3550 	wp_cache_delete( 'get', $taxonomy );
  3606 	wp_cache_delete( 'get', $taxonomy );
       
  3607 	wp_cache_delete( 'last_changed', 'terms' );
  3551 
  3608 
  3552 	// Regenerate cached hierarchy.
  3609 	// Regenerate cached hierarchy.
  3553 	delete_option( "{$taxonomy}_children" );
  3610 	delete_option( "{$taxonomy}_children" );
  3554 	_get_term_hierarchy( $taxonomy );
  3611 	_get_term_hierarchy( $taxonomy );
  3555 
  3612 
  3685 				$object_terms[ $id ][ $taxonomy ] = array();
  3742 				$object_terms[ $id ][ $taxonomy ] = array();
  3686 			}
  3743 			}
  3687 		}
  3744 		}
  3688 	}
  3745 	}
  3689 
  3746 
       
  3747 	$cache_values = array();
  3690 	foreach ( $object_terms as $id => $value ) {
  3748 	foreach ( $object_terms as $id => $value ) {
  3691 		foreach ( $value as $taxonomy => $terms ) {
  3749 		foreach ( $value as $taxonomy => $terms ) {
  3692 			wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
  3750 			$cache_values[ $taxonomy ][ $id ] = $terms;
  3693 		}
  3751 		}
  3694 	}
  3752 	}
  3695 }
  3753 	foreach ( $cache_values as $taxonomy => $data ) {
  3696 
  3754 		wp_cache_add_multiple( $data, "{$taxonomy}_relationships" );
  3697 /**
  3755 	}
  3698  * Updates Terms to Taxonomy in cache.
  3756 }
       
  3757 
       
  3758 /**
       
  3759  * Updates terms in cache.
  3699  *
  3760  *
  3700  * @since 2.3.0
  3761  * @since 2.3.0
  3701  *
  3762  *
  3702  * @param WP_Term[] $terms    Array of term objects to change.
  3763  * @param WP_Term[] $terms    Array of term objects to change.
  3703  * @param string    $taxonomy Not used.
  3764  * @param string    $taxonomy Not used.
  3704  */
  3765  */
  3705 function update_term_cache( $terms, $taxonomy = '' ) {
  3766 function update_term_cache( $terms, $taxonomy = '' ) {
       
  3767 	$data = array();
  3706 	foreach ( (array) $terms as $term ) {
  3768 	foreach ( (array) $terms as $term ) {
  3707 		// Create a copy in case the array was passed by reference.
  3769 		// Create a copy in case the array was passed by reference.
  3708 		$_term = clone $term;
  3770 		$_term = clone $term;
  3709 
  3771 
  3710 		// Object ID should not be cached.
  3772 		// Object ID should not be cached.
  3711 		unset( $_term->object_id );
  3773 		unset( $_term->object_id );
  3712 
  3774 
  3713 		wp_cache_add( $term->term_id, $_term, 'terms' );
  3775 		$data[ $term->term_id ] = $_term;
  3714 	}
  3776 	}
       
  3777 	wp_cache_add_multiple( $data, 'terms' );
  3715 }
  3778 }
  3716 
  3779 
  3717 //
  3780 //
  3718 // Private.
  3781 // Private.
  3719 //
  3782 //
  3720 
  3783 
  3721 /**
  3784 /**
  3722  * Retrieves children of taxonomy as Term IDs.
  3785  * Retrieves children of taxonomy as term IDs.
  3723  *
  3786  *
  3724  * @access private
  3787  * @access private
  3725  * @since 2.3.0
  3788  * @since 2.3.0
  3726  *
  3789  *
  3727  * @param string $taxonomy Taxonomy name.
  3790  * @param string $taxonomy Taxonomy name.
  3728  * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
  3791  * @return array Empty if $taxonomy isn't hierarchical or returns children as term IDs.
  3729  */
  3792  */
  3730 function _get_term_hierarchy( $taxonomy ) {
  3793 function _get_term_hierarchy( $taxonomy ) {
  3731 	if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
  3794 	if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
  3732 		return array();
  3795 		return array();
  3733 	}
  3796 	}
  3755 
  3818 
  3756 	return $children;
  3819 	return $children;
  3757 }
  3820 }
  3758 
  3821 
  3759 /**
  3822 /**
  3760  * Get the subset of $terms that are descendants of $term_id.
  3823  * Gets the subset of $terms that are descendants of $term_id.
  3761  *
  3824  *
  3762  * If `$terms` is an array of objects, then _get_term_children() returns an array of objects.
  3825  * If `$terms` is an array of objects, then _get_term_children() returns an array of objects.
  3763  * If `$terms` is an array of IDs, then _get_term_children() returns an array of IDs.
  3826  * If `$terms` is an array of IDs, then _get_term_children() returns an array of IDs.
  3764  *
  3827  *
  3765  * @access private
  3828  * @access private
  3831 
  3894 
  3832 	return $term_list;
  3895 	return $term_list;
  3833 }
  3896 }
  3834 
  3897 
  3835 /**
  3898 /**
  3836  * Add count of children to parent count.
  3899  * Adds count of children to parent count.
  3837  *
  3900  *
  3838  * Recalculates term counts by including items from child terms. Assumes all
  3901  * Recalculates term counts by including items from child terms. Assumes all
  3839  * relevant children are already in the $terms argument.
  3902  * relevant children are already in the $terms argument.
  3840  *
  3903  *
  3841  * @access private
  3904  * @access private
  3925 
  3988 
  3926 	$non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' );
  3989 	$non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' );
  3927 	if ( ! empty( $non_cached_ids ) ) {
  3990 	if ( ! empty( $non_cached_ids ) ) {
  3928 		$fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );
  3991 		$fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );
  3929 
  3992 
  3930 		update_term_cache( $fresh_terms, $update_meta_cache );
  3993 		update_term_cache( $fresh_terms );
  3931 
  3994 
  3932 		if ( $update_meta_cache ) {
  3995 		if ( $update_meta_cache ) {
  3933 			update_termmeta_cache( $non_cached_ids );
  3996 			update_termmeta_cache( $non_cached_ids );
  3934 		}
  3997 		}
  3935 	}
  3998 	}
  3938 //
  4001 //
  3939 // Default callbacks.
  4002 // Default callbacks.
  3940 //
  4003 //
  3941 
  4004 
  3942 /**
  4005 /**
  3943  * Will update term count based on object types of the current taxonomy.
  4006  * Updates term count based on object types of the current taxonomy.
  3944  *
  4007  *
  3945  * Private function for the default callback for post_tag and category
  4008  * Private function for the default callback for post_tag and category
  3946  * taxonomies.
  4009  * taxonomies.
  3947  *
  4010  *
  3948  * @access private
  4011  * @access private
  3949  * @since 2.3.0
  4012  * @since 2.3.0
  3950  *
  4013  *
  3951  * @global wpdb $wpdb WordPress database abstraction object.
  4014  * @global wpdb $wpdb WordPress database abstraction object.
  3952  *
  4015  *
  3953  * @param int[]       $terms    List of Term taxonomy IDs.
  4016  * @param int[]       $terms    List of term taxonomy IDs.
  3954  * @param WP_Taxonomy $taxonomy Current taxonomy object of terms.
  4017  * @param WP_Taxonomy $taxonomy Current taxonomy object of terms.
  3955  */
  4018  */
  3956 function _update_post_term_count( $terms, $taxonomy ) {
  4019 function _update_post_term_count( $terms, $taxonomy ) {
  3957 	global $wpdb;
  4020 	global $wpdb;
  3958 
  4021 
  4008 		do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
  4071 		do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
  4009 	}
  4072 	}
  4010 }
  4073 }
  4011 
  4074 
  4012 /**
  4075 /**
  4013  * Will update term count based on number of objects.
  4076  * Updates term count based on number of objects.
  4014  *
  4077  *
  4015  * Default callback for the 'link_category' taxonomy.
  4078  * Default callback for the 'link_category' taxonomy.
  4016  *
  4079  *
  4017  * @since 3.3.0
  4080  * @since 3.3.0
  4018  *
  4081  *
  4035 		do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
  4098 		do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
  4036 	}
  4099 	}
  4037 }
  4100 }
  4038 
  4101 
  4039 /**
  4102 /**
  4040  * Create a new term for a term_taxonomy item that currently shares its term
  4103  * Creates a new term for a term_taxonomy item that currently shares its term
  4041  * with another term_taxonomy.
  4104  * with another term_taxonomy.
  4042  *
  4105  *
  4043  * @ignore
  4106  * @ignore
  4044  * @since 4.2.0
  4107  * @since 4.2.0
  4045  * @since 4.3.0 Introduced `$record` parameter. Also, `$term_id` and
  4108  * @since 4.3.0 Introduced `$record` parameter. Also, `$term_id` and
  4282 	delete_option( $lock_name );
  4345 	delete_option( $lock_name );
  4283 }
  4346 }
  4284 
  4347 
  4285 /**
  4348 /**
  4286  * In order to avoid the _wp_batch_split_terms() job being accidentally removed,
  4349  * In order to avoid the _wp_batch_split_terms() job being accidentally removed,
  4287  * check that it's still scheduled while we haven't finished splitting terms.
  4350  * checks that it's still scheduled while we haven't finished splitting terms.
  4288  *
  4351  *
  4289  * @ignore
  4352  * @ignore
  4290  * @since 4.3.0
  4353  * @since 4.3.0
  4291  */
  4354  */
  4292 function _wp_check_for_scheduled_split_terms() {
  4355 function _wp_check_for_scheduled_split_terms() {
  4294 		wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_split_shared_term_batch' );
  4357 		wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_split_shared_term_batch' );
  4295 	}
  4358 	}
  4296 }
  4359 }
  4297 
  4360 
  4298 /**
  4361 /**
  4299  * Check default categories when a term gets split to see if any of them need to be updated.
  4362  * Checks default categories when a term gets split to see if any of them need to be updated.
  4300  *
  4363  *
  4301  * @ignore
  4364  * @ignore
  4302  * @since 4.2.0
  4365  * @since 4.2.0
  4303  *
  4366  *
  4304  * @param int    $term_id          ID of the formerly shared term.
  4367  * @param int    $term_id          ID of the formerly shared term.
  4317 		}
  4380 		}
  4318 	}
  4381 	}
  4319 }
  4382 }
  4320 
  4383 
  4321 /**
  4384 /**
  4322  * Check menu items when a term gets split to see if any of them need to be updated.
  4385  * Checks menu items when a term gets split to see if any of them need to be updated.
  4323  *
  4386  *
  4324  * @ignore
  4387  * @ignore
  4325  * @since 4.2.0
  4388  * @since 4.2.0
  4326  *
  4389  *
  4327  * @global wpdb $wpdb WordPress database abstraction object.
  4390  * @global wpdb $wpdb WordPress database abstraction object.
  4353 		}
  4416 		}
  4354 	}
  4417 	}
  4355 }
  4418 }
  4356 
  4419 
  4357 /**
  4420 /**
  4358  * If the term being split is a nav_menu, change associations.
  4421  * If the term being split is a nav_menu, changes associations.
  4359  *
  4422  *
  4360  * @ignore
  4423  * @ignore
  4361  * @since 4.3.0
  4424  * @since 4.3.0
  4362  *
  4425  *
  4363  * @param int    $term_id          ID of the formerly shared term.
  4426  * @param int    $term_id          ID of the formerly shared term.
  4379 	}
  4442 	}
  4380 	set_theme_mod( 'nav_menu_locations', $locations );
  4443 	set_theme_mod( 'nav_menu_locations', $locations );
  4381 }
  4444 }
  4382 
  4445 
  4383 /**
  4446 /**
  4384  * Get data about terms that previously shared a single term_id, but have since been split.
  4447  * Gets data about terms that previously shared a single term_id, but have since been split.
  4385  *
  4448  *
  4386  * @since 4.2.0
  4449  * @since 4.2.0
  4387  *
  4450  *
  4388  * @param int $old_term_id Term ID. This is the old, pre-split term ID.
  4451  * @param int $old_term_id Term ID. This is the old, pre-split term ID.
  4389  * @return array Array of new term IDs, keyed by taxonomy.
  4452  * @return array Array of new term IDs, keyed by taxonomy.
  4398 
  4461 
  4399 	return $terms;
  4462 	return $terms;
  4400 }
  4463 }
  4401 
  4464 
  4402 /**
  4465 /**
  4403  * Get the new term ID corresponding to a previously split term.
  4466  * Gets the new term ID corresponding to a previously split term.
  4404  *
  4467  *
  4405  * @since 4.2.0
  4468  * @since 4.2.0
  4406  *
  4469  *
  4407  * @param int    $old_term_id Term ID. This is the old, pre-split term ID.
  4470  * @param int    $old_term_id Term ID. This is the old, pre-split term ID.
  4408  * @param string $taxonomy    Taxonomy that the term belongs to.
  4471  * @param string $taxonomy    Taxonomy that the term belongs to.
  4420 
  4483 
  4421 	return $term_id;
  4484 	return $term_id;
  4422 }
  4485 }
  4423 
  4486 
  4424 /**
  4487 /**
  4425  * Determine whether a term is shared between multiple taxonomies.
  4488  * Determines whether a term is shared between multiple taxonomies.
  4426  *
  4489  *
  4427  * Shared taxonomy terms began to be split in 4.3, but failed cron tasks or
  4490  * Shared taxonomy terms began to be split in 4.3, but failed cron tasks or
  4428  * other delays in upgrade routines may cause shared terms to remain.
  4491  * other delays in upgrade routines may cause shared terms to remain.
  4429  *
  4492  *
  4430  * @since 4.4.0
  4493  * @since 4.4.0
  4444 
  4507 
  4445 	return $tt_count > 1;
  4508 	return $tt_count > 1;
  4446 }
  4509 }
  4447 
  4510 
  4448 /**
  4511 /**
  4449  * Generate a permalink for a taxonomy term archive.
  4512  * Generates a permalink for a taxonomy term archive.
  4450  *
  4513  *
  4451  * @since 2.5.0
  4514  * @since 2.5.0
  4452  *
  4515  *
  4453  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  4516  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  4454  *
  4517  *
  4558 	 */
  4621 	 */
  4559 	return apply_filters( 'term_link', $termlink, $term, $taxonomy );
  4622 	return apply_filters( 'term_link', $termlink, $term, $taxonomy );
  4560 }
  4623 }
  4561 
  4624 
  4562 /**
  4625 /**
  4563  * Display the taxonomies of a post with available options.
  4626  * Displays the taxonomies of a post with available options.
  4564  *
  4627  *
  4565  * This function can be used within the loop to display the taxonomies for a
  4628  * This function can be used within the loop to display the taxonomies for a
  4566  * post without specifying the Post ID. You can also use it outside the Loop to
  4629  * post without specifying the Post ID. You can also use it outside the Loop to
  4567  * display the taxonomies for a specific post.
  4630  * display the taxonomies for a specific post.
  4568  *
  4631  *
  4570  *
  4633  *
  4571  * @param array $args {
  4634  * @param array $args {
  4572  *     Arguments about which post to use and how to format the output. Shares all of the arguments
  4635  *     Arguments about which post to use and how to format the output. Shares all of the arguments
  4573  *     supported by get_the_taxonomies(), in addition to the following.
  4636  *     supported by get_the_taxonomies(), in addition to the following.
  4574  *
  4637  *
  4575  *     @type  int|WP_Post $post   Post ID or object to get taxonomies of. Default current post.
  4638  *     @type int|WP_Post $post   Post ID or object to get taxonomies of. Default current post.
  4576  *     @type  string      $before Displays before the taxonomies. Default empty string.
  4639  *     @type string      $before Displays before the taxonomies. Default empty string.
  4577  *     @type  string      $sep    Separates each taxonomy. Default is a space.
  4640  *     @type string      $sep    Separates each taxonomy. Default is a space.
  4578  *     @type  string      $after  Displays after the taxonomies. Default empty string.
  4641  *     @type string      $after  Displays after the taxonomies. Default empty string.
  4579  * }
  4642  * }
  4580  */
  4643  */
  4581 function the_taxonomies( $args = array() ) {
  4644 function the_taxonomies( $args = array() ) {
  4582 	$defaults = array(
  4645 	$defaults = array(
  4583 		'post'   => 0,
  4646 		'post'   => 0,
  4590 
  4653 
  4591 	echo $parsed_args['before'] . implode( $parsed_args['sep'], get_the_taxonomies( $parsed_args['post'], $parsed_args ) ) . $parsed_args['after'];
  4654 	echo $parsed_args['before'] . implode( $parsed_args['sep'], get_the_taxonomies( $parsed_args['post'], $parsed_args ) ) . $parsed_args['after'];
  4592 }
  4655 }
  4593 
  4656 
  4594 /**
  4657 /**
  4595  * Retrieve all taxonomies associated with a post.
  4658  * Retrieves all taxonomies associated with a post.
  4596  *
  4659  *
  4597  * This function can be used within the loop. It will also return an array of
  4660  * This function can be used within the loop. It will also return an array of
  4598  * the taxonomies with links to the taxonomy and name.
  4661  * the taxonomies with links to the taxonomy and name.
  4599  *
  4662  *
  4600  * @since 2.5.0
  4663  * @since 2.5.0
  4658 	}
  4721 	}
  4659 	return $taxonomies;
  4722 	return $taxonomies;
  4660 }
  4723 }
  4661 
  4724 
  4662 /**
  4725 /**
  4663  * Retrieve all taxonomy names for the given post.
  4726  * Retrieves all taxonomy names for the given post.
  4664  *
  4727  *
  4665  * @since 2.5.0
  4728  * @since 2.5.0
  4666  *
  4729  *
  4667  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  4730  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  4668  * @return string[] An array of all taxonomy names for the given post.
  4731  * @return string[] An array of all taxonomy names for the given post.
  4672 
  4735 
  4673 	return get_object_taxonomies( $post );
  4736 	return get_object_taxonomies( $post );
  4674 }
  4737 }
  4675 
  4738 
  4676 /**
  4739 /**
  4677  * Determine if the given object is associated with any of the given terms.
  4740  * Determines if the given object is associated with any of the given terms.
  4678  *
  4741  *
  4679  * The given terms are checked against the object's terms' term_ids, names and slugs.
  4742  * The given terms are checked against the object's terms' term_ids, names and slugs.
  4680  * Terms given as integers will only be checked against the object's terms' term_ids.
  4743  * Terms given as integers will only be checked against the object's terms' term_ids.
  4681  * If no terms are given, determines if object is associated with any terms in the given taxonomy.
  4744  * If no terms are given, determines if object is associated with any terms in the given taxonomy.
  4682  *
  4745  *
  4747 
  4810 
  4748 	return false;
  4811 	return false;
  4749 }
  4812 }
  4750 
  4813 
  4751 /**
  4814 /**
  4752  * Determine if the given object type is associated with the given taxonomy.
  4815  * Determines if the given object type is associated with the given taxonomy.
  4753  *
  4816  *
  4754  * @since 3.0.0
  4817  * @since 3.0.0
  4755  *
  4818  *
  4756  * @param string $object_type Object type string.
  4819  * @param string $object_type Object type string.
  4757  * @param string $taxonomy    Single taxonomy name.
  4820  * @param string $taxonomy    Single taxonomy name.
  4764 	}
  4827 	}
  4765 	return in_array( $taxonomy, $taxonomies, true );
  4828 	return in_array( $taxonomy, $taxonomies, true );
  4766 }
  4829 }
  4767 
  4830 
  4768 /**
  4831 /**
  4769  * Get an array of ancestor IDs for a given object.
  4832  * Gets an array of ancestor IDs for a given object.
  4770  *
  4833  *
  4771  * @since 3.1.0
  4834  * @since 3.1.0
  4772  * @since 4.1.0 Introduced the `$resource_type` argument.
  4835  * @since 4.1.0 Introduced the `$resource_type` argument.
  4773  *
  4836  *
  4774  * @param int    $object_id     Optional. The ID of the object. Default 0.
  4837  * @param int    $object_id     Optional. The ID of the object. Default 0.
  4820 	 */
  4883 	 */
  4821 	return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type, $resource_type );
  4884 	return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type, $resource_type );
  4822 }
  4885 }
  4823 
  4886 
  4824 /**
  4887 /**
  4825  * Returns the term's parent's term_ID.
  4888  * Returns the term's parent's term ID.
  4826  *
  4889  *
  4827  * @since 3.1.0
  4890  * @since 3.1.0
  4828  *
  4891  *
  4829  * @param int    $term_id  Term ID.
  4892  * @param int    $term_id  Term ID.
  4830  * @param string $taxonomy Taxonomy name.
  4893  * @param string $taxonomy Taxonomy name.