create_initial_taxonomies()WP 2.8.0

Creates the initial taxonomies.

This function fires twice: in wp-settings.php before plugins are loaded (for backward compatibility reasons), and again on the init action. We must avoid registering rewrite rules before the init action.

Хуки из функции

Возвращает

null. Ничего (null).

Использование

create_initial_taxonomies();

Заметки

  • Global. WP_Rewrite. $wp_rewrite WordPress rewrite component.

Список изменений

С версии 2.8.0 Введена.
С версии 5.9.0 Added 'wp_template_part_area' taxonomy.

Код create_initial_taxonomies() WP 6.6.2

function create_initial_taxonomies() {
	global $wp_rewrite;

	WP_Taxonomy::reset_default_labels();

	if ( ! did_action( 'init' ) ) {
		$rewrite = array(
			'category'    => false,
			'post_tag'    => false,
			'post_format' => false,
		);
	} else {

		/**
		 * Filters the post formats rewrite base.
		 *
		 * @since 3.1.0
		 *
		 * @param string $context Context of the rewrite base. Default 'type'.
		 */
		$post_format_base = apply_filters( 'post_format_rewrite_base', 'type' );
		$rewrite          = array(
			'category'    => array(
				'hierarchical' => true,
				'slug'         => get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category',
				'with_front'   => ! get_option( 'category_base' ) || $wp_rewrite->using_index_permalinks(),
				'ep_mask'      => EP_CATEGORIES,
			),
			'post_tag'    => array(
				'hierarchical' => false,
				'slug'         => get_option( 'tag_base' ) ? get_option( 'tag_base' ) : 'tag',
				'with_front'   => ! get_option( 'tag_base' ) || $wp_rewrite->using_index_permalinks(),
				'ep_mask'      => EP_TAGS,
			),
			'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false,
		);
	}

	register_taxonomy(
		'category',
		'post',
		array(
			'hierarchical'          => true,
			'query_var'             => 'category_name',
			'rewrite'               => $rewrite['category'],
			'public'                => true,
			'show_ui'               => true,
			'show_admin_column'     => true,
			'_builtin'              => true,
			'capabilities'          => array(
				'manage_terms' => 'manage_categories',
				'edit_terms'   => 'edit_categories',
				'delete_terms' => 'delete_categories',
				'assign_terms' => 'assign_categories',
			),
			'show_in_rest'          => true,
			'rest_base'             => 'categories',
			'rest_controller_class' => 'WP_REST_Terms_Controller',
		)
	);

	register_taxonomy(
		'post_tag',
		'post',
		array(
			'hierarchical'          => false,
			'query_var'             => 'tag',
			'rewrite'               => $rewrite['post_tag'],
			'public'                => true,
			'show_ui'               => true,
			'show_admin_column'     => true,
			'_builtin'              => true,
			'capabilities'          => array(
				'manage_terms' => 'manage_post_tags',
				'edit_terms'   => 'edit_post_tags',
				'delete_terms' => 'delete_post_tags',
				'assign_terms' => 'assign_post_tags',
			),
			'show_in_rest'          => true,
			'rest_base'             => 'tags',
			'rest_controller_class' => 'WP_REST_Terms_Controller',
		)
	);

	register_taxonomy(
		'nav_menu',
		'nav_menu_item',
		array(
			'public'                => false,
			'hierarchical'          => false,
			'labels'                => array(
				'name'          => __( 'Navigation Menus' ),
				'singular_name' => __( 'Navigation Menu' ),
			),
			'query_var'             => false,
			'rewrite'               => false,
			'show_ui'               => false,
			'_builtin'              => true,
			'show_in_nav_menus'     => false,
			'capabilities'          => array(
				'manage_terms' => 'edit_theme_options',
				'edit_terms'   => 'edit_theme_options',
				'delete_terms' => 'edit_theme_options',
				'assign_terms' => 'edit_theme_options',
			),
			'show_in_rest'          => true,
			'rest_base'             => 'menus',
			'rest_controller_class' => 'WP_REST_Menus_Controller',
		)
	);

	register_taxonomy(
		'link_category',
		'link',
		array(
			'hierarchical' => false,
			'labels'       => array(
				'name'                       => __( 'Link Categories' ),
				'singular_name'              => __( 'Link Category' ),
				'search_items'               => __( 'Search Link Categories' ),
				'popular_items'              => null,
				'all_items'                  => __( 'All Link Categories' ),
				'edit_item'                  => __( 'Edit Link Category' ),
				'update_item'                => __( 'Update Link Category' ),
				'add_new_item'               => __( 'Add New Link Category' ),
				'new_item_name'              => __( 'New Link Category Name' ),
				'separate_items_with_commas' => null,
				'add_or_remove_items'        => null,
				'choose_from_most_used'      => null,
				'back_to_items'              => __( '← Go to Link Categories' ),
			),
			'capabilities' => array(
				'manage_terms' => 'manage_links',
				'edit_terms'   => 'manage_links',
				'delete_terms' => 'manage_links',
				'assign_terms' => 'manage_links',
			),
			'query_var'    => false,
			'rewrite'      => false,
			'public'       => false,
			'show_ui'      => true,
			'_builtin'     => true,
		)
	);

	register_taxonomy(
		'post_format',
		'post',
		array(
			'public'            => true,
			'hierarchical'      => false,
			'labels'            => array(
				'name'          => _x( 'Formats', 'post format' ),
				'singular_name' => _x( 'Format', 'post format' ),
			),
			'query_var'         => true,
			'rewrite'           => $rewrite['post_format'],
			'show_ui'           => false,
			'_builtin'          => true,
			'show_in_nav_menus' => current_theme_supports( 'post-formats' ),
		)
	);

	register_taxonomy(
		'wp_theme',
		array( 'wp_template', 'wp_template_part', 'wp_global_styles' ),
		array(
			'public'            => false,
			'hierarchical'      => false,
			'labels'            => array(
				'name'          => __( 'Themes' ),
				'singular_name' => __( 'Theme' ),
			),
			'query_var'         => false,
			'rewrite'           => false,
			'show_ui'           => false,
			'_builtin'          => true,
			'show_in_nav_menus' => false,
			'show_in_rest'      => false,
		)
	);

	register_taxonomy(
		'wp_template_part_area',
		array( 'wp_template_part' ),
		array(
			'public'            => false,
			'hierarchical'      => false,
			'labels'            => array(
				'name'          => __( 'Template Part Areas' ),
				'singular_name' => __( 'Template Part Area' ),
			),
			'query_var'         => false,
			'rewrite'           => false,
			'show_ui'           => false,
			'_builtin'          => true,
			'show_in_nav_menus' => false,
			'show_in_rest'      => false,
		)
	);

	register_taxonomy(
		'wp_pattern_category',
		array( 'wp_block' ),
		array(
			'public'             => false,
			'publicly_queryable' => false,
			'hierarchical'       => false,
			'labels'             => array(
				'name'                       => _x( 'Pattern Categories', 'taxonomy general name' ),
				'singular_name'              => _x( 'Pattern Category', 'taxonomy singular name' ),
				'add_new_item'               => __( 'Add New Category' ),
				'add_or_remove_items'        => __( 'Add or remove pattern categories' ),
				'back_to_items'              => __( '← Go to Pattern Categories' ),
				'choose_from_most_used'      => __( 'Choose from the most used pattern categories' ),
				'edit_item'                  => __( 'Edit Pattern Category' ),
				'item_link'                  => __( 'Pattern Category Link' ),
				'item_link_description'      => __( 'A link to a pattern category.' ),
				'items_list'                 => __( 'Pattern Categories list' ),
				'items_list_navigation'      => __( 'Pattern Categories list navigation' ),
				'new_item_name'              => __( 'New Pattern Category Name' ),
				'no_terms'                   => __( 'No pattern categories' ),
				'not_found'                  => __( 'No pattern categories found.' ),
				'popular_items'              => __( 'Popular Pattern Categories' ),
				'search_items'               => __( 'Search Pattern Categories' ),
				'separate_items_with_commas' => __( 'Separate pattern categories with commas' ),
				'update_item'                => __( 'Update Pattern Category' ),
				'view_item'                  => __( 'View Pattern Category' ),
			),
			'query_var'          => false,
			'rewrite'            => false,
			'show_ui'            => true,
			'_builtin'           => true,
			'show_in_nav_menus'  => false,
			'show_in_rest'       => true,
			'show_admin_column'  => true,
			'show_tagcloud'      => false,
		)
	);
}