Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: taxonomy.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Core Taxonomy API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Taxonomy
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
//
[8] Fix | Delete
// Taxonomy registration.
[9] Fix | Delete
//
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Creates the initial taxonomies.
[13] Fix | Delete
*
[14] Fix | Delete
* This function fires twice: in wp-settings.php before plugins are loaded (for
[15] Fix | Delete
* backward compatibility reasons), and again on the {@see 'init'} action. We must
[16] Fix | Delete
* avoid registering rewrite rules before the {@see 'init'} action.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 2.8.0
[19] Fix | Delete
*
[20] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[21] Fix | Delete
*/
[22] Fix | Delete
function create_initial_taxonomies() {
[23] Fix | Delete
global $wp_rewrite;
[24] Fix | Delete
[25] Fix | Delete
if ( ! did_action( 'init' ) ) {
[26] Fix | Delete
$rewrite = array(
[27] Fix | Delete
'category' => false,
[28] Fix | Delete
'post_tag' => false,
[29] Fix | Delete
'post_format' => false,
[30] Fix | Delete
);
[31] Fix | Delete
} else {
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Filters the post formats rewrite base.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 3.1.0
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $context Context of the rewrite base. Default 'type'.
[39] Fix | Delete
*/
[40] Fix | Delete
$post_format_base = apply_filters( 'post_format_rewrite_base', 'type' );
[41] Fix | Delete
$rewrite = array(
[42] Fix | Delete
'category' => array(
[43] Fix | Delete
'hierarchical' => true,
[44] Fix | Delete
'slug' => get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category',
[45] Fix | Delete
'with_front' => ! get_option( 'category_base' ) || $wp_rewrite->using_index_permalinks(),
[46] Fix | Delete
'ep_mask' => EP_CATEGORIES,
[47] Fix | Delete
),
[48] Fix | Delete
'post_tag' => array(
[49] Fix | Delete
'hierarchical' => false,
[50] Fix | Delete
'slug' => get_option( 'tag_base' ) ? get_option( 'tag_base' ) : 'tag',
[51] Fix | Delete
'with_front' => ! get_option( 'tag_base' ) || $wp_rewrite->using_index_permalinks(),
[52] Fix | Delete
'ep_mask' => EP_TAGS,
[53] Fix | Delete
),
[54] Fix | Delete
'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false,
[55] Fix | Delete
);
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
register_taxonomy(
[59] Fix | Delete
'category',
[60] Fix | Delete
'post',
[61] Fix | Delete
array(
[62] Fix | Delete
'hierarchical' => true,
[63] Fix | Delete
'query_var' => 'category_name',
[64] Fix | Delete
'rewrite' => $rewrite['category'],
[65] Fix | Delete
'public' => true,
[66] Fix | Delete
'show_ui' => true,
[67] Fix | Delete
'show_admin_column' => true,
[68] Fix | Delete
'_builtin' => true,
[69] Fix | Delete
'capabilities' => array(
[70] Fix | Delete
'manage_terms' => 'manage_categories',
[71] Fix | Delete
'edit_terms' => 'edit_categories',
[72] Fix | Delete
'delete_terms' => 'delete_categories',
[73] Fix | Delete
'assign_terms' => 'assign_categories',
[74] Fix | Delete
),
[75] Fix | Delete
'show_in_rest' => true,
[76] Fix | Delete
'rest_base' => 'categories',
[77] Fix | Delete
'rest_controller_class' => 'WP_REST_Terms_Controller',
[78] Fix | Delete
)
[79] Fix | Delete
);
[80] Fix | Delete
[81] Fix | Delete
register_taxonomy(
[82] Fix | Delete
'post_tag',
[83] Fix | Delete
'post',
[84] Fix | Delete
array(
[85] Fix | Delete
'hierarchical' => false,
[86] Fix | Delete
'query_var' => 'tag',
[87] Fix | Delete
'rewrite' => $rewrite['post_tag'],
[88] Fix | Delete
'public' => true,
[89] Fix | Delete
'show_ui' => true,
[90] Fix | Delete
'show_admin_column' => true,
[91] Fix | Delete
'_builtin' => true,
[92] Fix | Delete
'capabilities' => array(
[93] Fix | Delete
'manage_terms' => 'manage_post_tags',
[94] Fix | Delete
'edit_terms' => 'edit_post_tags',
[95] Fix | Delete
'delete_terms' => 'delete_post_tags',
[96] Fix | Delete
'assign_terms' => 'assign_post_tags',
[97] Fix | Delete
),
[98] Fix | Delete
'show_in_rest' => true,
[99] Fix | Delete
'rest_base' => 'tags',
[100] Fix | Delete
'rest_controller_class' => 'WP_REST_Terms_Controller',
[101] Fix | Delete
)
[102] Fix | Delete
);
[103] Fix | Delete
[104] Fix | Delete
register_taxonomy(
[105] Fix | Delete
'nav_menu',
[106] Fix | Delete
'nav_menu_item',
[107] Fix | Delete
array(
[108] Fix | Delete
'public' => false,
[109] Fix | Delete
'hierarchical' => false,
[110] Fix | Delete
'labels' => array(
[111] Fix | Delete
'name' => __( 'Navigation Menus' ),
[112] Fix | Delete
'singular_name' => __( 'Navigation Menu' ),
[113] Fix | Delete
),
[114] Fix | Delete
'query_var' => false,
[115] Fix | Delete
'rewrite' => false,
[116] Fix | Delete
'show_ui' => false,
[117] Fix | Delete
'_builtin' => true,
[118] Fix | Delete
'show_in_nav_menus' => false,
[119] Fix | Delete
)
[120] Fix | Delete
);
[121] Fix | Delete
[122] Fix | Delete
register_taxonomy(
[123] Fix | Delete
'link_category',
[124] Fix | Delete
'link',
[125] Fix | Delete
array(
[126] Fix | Delete
'hierarchical' => false,
[127] Fix | Delete
'labels' => array(
[128] Fix | Delete
'name' => __( 'Link Categories' ),
[129] Fix | Delete
'singular_name' => __( 'Link Category' ),
[130] Fix | Delete
'search_items' => __( 'Search Link Categories' ),
[131] Fix | Delete
'popular_items' => null,
[132] Fix | Delete
'all_items' => __( 'All Link Categories' ),
[133] Fix | Delete
'edit_item' => __( 'Edit Link Category' ),
[134] Fix | Delete
'update_item' => __( 'Update Link Category' ),
[135] Fix | Delete
'add_new_item' => __( 'Add New Link Category' ),
[136] Fix | Delete
'new_item_name' => __( 'New Link Category Name' ),
[137] Fix | Delete
'separate_items_with_commas' => null,
[138] Fix | Delete
'add_or_remove_items' => null,
[139] Fix | Delete
'choose_from_most_used' => null,
[140] Fix | Delete
'back_to_items' => __( '&larr; Go to Link Categories' ),
[141] Fix | Delete
),
[142] Fix | Delete
'capabilities' => array(
[143] Fix | Delete
'manage_terms' => 'manage_links',
[144] Fix | Delete
'edit_terms' => 'manage_links',
[145] Fix | Delete
'delete_terms' => 'manage_links',
[146] Fix | Delete
'assign_terms' => 'manage_links',
[147] Fix | Delete
),
[148] Fix | Delete
'query_var' => false,
[149] Fix | Delete
'rewrite' => false,
[150] Fix | Delete
'public' => false,
[151] Fix | Delete
'show_ui' => true,
[152] Fix | Delete
'_builtin' => true,
[153] Fix | Delete
)
[154] Fix | Delete
);
[155] Fix | Delete
[156] Fix | Delete
register_taxonomy(
[157] Fix | Delete
'post_format',
[158] Fix | Delete
'post',
[159] Fix | Delete
array(
[160] Fix | Delete
'public' => true,
[161] Fix | Delete
'hierarchical' => false,
[162] Fix | Delete
'labels' => array(
[163] Fix | Delete
'name' => _x( 'Formats', 'post format' ),
[164] Fix | Delete
'singular_name' => _x( 'Format', 'post format' ),
[165] Fix | Delete
),
[166] Fix | Delete
'query_var' => true,
[167] Fix | Delete
'rewrite' => $rewrite['post_format'],
[168] Fix | Delete
'show_ui' => false,
[169] Fix | Delete
'_builtin' => true,
[170] Fix | Delete
'show_in_nav_menus' => current_theme_supports( 'post-formats' ),
[171] Fix | Delete
)
[172] Fix | Delete
);
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Retrieves a list of registered taxonomy names or objects.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 3.0.0
[179] Fix | Delete
*
[180] Fix | Delete
* @global array $wp_taxonomies The registered taxonomies.
[181] Fix | Delete
*
[182] Fix | Delete
* @param array $args Optional. An array of `key => value` arguments to match against the taxonomy objects.
[183] Fix | Delete
* Default empty array.
[184] Fix | Delete
* @param string $output Optional. The type of output to return in the array. Accepts either taxonomy 'names'
[185] Fix | Delete
* or 'objects'. Default 'names'.
[186] Fix | Delete
* @param string $operator Optional. The logical operation to perform. Accepts 'and' or 'or'. 'or' means only
[187] Fix | Delete
* one element from the array needs to match; 'and' means all elements must match.
[188] Fix | Delete
* Default 'and'.
[189] Fix | Delete
* @return string[]|WP_Taxonomy[] An array of taxonomy names or objects.
[190] Fix | Delete
*/
[191] Fix | Delete
function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) {
[192] Fix | Delete
global $wp_taxonomies;
[193] Fix | Delete
[194] Fix | Delete
$field = ( 'names' === $output ) ? 'name' : false;
[195] Fix | Delete
[196] Fix | Delete
return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field );
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
[201] Fix | Delete
* a post object or post type name.
[202] Fix | Delete
*
[203] Fix | Delete
* Example:
[204] Fix | Delete
*
[205] Fix | Delete
* $taxonomies = get_object_taxonomies( 'post' );
[206] Fix | Delete
*
[207] Fix | Delete
* This results in:
[208] Fix | Delete
*
[209] Fix | Delete
* Array( 'category', 'post_tag' )
[210] Fix | Delete
*
[211] Fix | Delete
* @since 2.3.0
[212] Fix | Delete
*
[213] Fix | Delete
* @global array $wp_taxonomies The registered taxonomies.
[214] Fix | Delete
*
[215] Fix | Delete
* @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
[216] Fix | Delete
* @param string $output Optional. The type of output to return in the array. Accepts either
[217] Fix | Delete
* 'names' or 'objects'. Default 'names'.
[218] Fix | Delete
* @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
[219] Fix | Delete
*/
[220] Fix | Delete
function get_object_taxonomies( $object, $output = 'names' ) {
[221] Fix | Delete
global $wp_taxonomies;
[222] Fix | Delete
[223] Fix | Delete
if ( is_object( $object ) ) {
[224] Fix | Delete
if ( 'attachment' === $object->post_type ) {
[225] Fix | Delete
return get_attachment_taxonomies( $object, $output );
[226] Fix | Delete
}
[227] Fix | Delete
$object = $object->post_type;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
$object = (array) $object;
[231] Fix | Delete
[232] Fix | Delete
$taxonomies = array();
[233] Fix | Delete
foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) {
[234] Fix | Delete
if ( array_intersect( $object, (array) $tax_obj->object_type ) ) {
[235] Fix | Delete
if ( 'names' === $output ) {
[236] Fix | Delete
$taxonomies[] = $tax_name;
[237] Fix | Delete
} else {
[238] Fix | Delete
$taxonomies[ $tax_name ] = $tax_obj;
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return $taxonomies;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Retrieves the taxonomy object of $taxonomy.
[248] Fix | Delete
*
[249] Fix | Delete
* The get_taxonomy function will first check that the parameter string given
[250] Fix | Delete
* is a taxonomy object and if it is, it will return it.
[251] Fix | Delete
*
[252] Fix | Delete
* @since 2.3.0
[253] Fix | Delete
*
[254] Fix | Delete
* @global array $wp_taxonomies The registered taxonomies.
[255] Fix | Delete
*
[256] Fix | Delete
* @param string $taxonomy Name of taxonomy object to return.
[257] Fix | Delete
* @return WP_Taxonomy|false The Taxonomy Object or false if $taxonomy doesn't exist.
[258] Fix | Delete
*/
[259] Fix | Delete
function get_taxonomy( $taxonomy ) {
[260] Fix | Delete
global $wp_taxonomies;
[261] Fix | Delete
[262] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[263] Fix | Delete
return false;
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
return $wp_taxonomies[ $taxonomy ];
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Determines whether the taxonomy name exists.
[271] Fix | Delete
*
[272] Fix | Delete
* Formerly is_taxonomy(), introduced in 2.3.0.
[273] Fix | Delete
*
[274] Fix | Delete
* For more information on this and similar theme functions, check out
[275] Fix | Delete
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
[276] Fix | Delete
* Conditional Tags} article in the Theme Developer Handbook.
[277] Fix | Delete
*
[278] Fix | Delete
* @since 3.0.0
[279] Fix | Delete
*
[280] Fix | Delete
* @global array $wp_taxonomies The registered taxonomies.
[281] Fix | Delete
*
[282] Fix | Delete
* @param string $taxonomy Name of taxonomy object.
[283] Fix | Delete
* @return bool Whether the taxonomy exists.
[284] Fix | Delete
*/
[285] Fix | Delete
function taxonomy_exists( $taxonomy ) {
[286] Fix | Delete
global $wp_taxonomies;
[287] Fix | Delete
[288] Fix | Delete
return isset( $wp_taxonomies[ $taxonomy ] );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* Determines whether the taxonomy object is hierarchical.
[293] Fix | Delete
*
[294] Fix | Delete
* Checks to make sure that the taxonomy is an object first. Then Gets the
[295] Fix | Delete
* object, and finally returns the hierarchical value in the object.
[296] Fix | Delete
*
[297] Fix | Delete
* A false return value might also mean that the taxonomy does not exist.
[298] Fix | Delete
*
[299] Fix | Delete
* For more information on this and similar theme functions, check out
[300] Fix | Delete
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
[301] Fix | Delete
* Conditional Tags} article in the Theme Developer Handbook.
[302] Fix | Delete
*
[303] Fix | Delete
* @since 2.3.0
[304] Fix | Delete
*
[305] Fix | Delete
* @param string $taxonomy Name of taxonomy object.
[306] Fix | Delete
* @return bool Whether the taxonomy is hierarchical.
[307] Fix | Delete
*/
[308] Fix | Delete
function is_taxonomy_hierarchical( $taxonomy ) {
[309] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[310] Fix | Delete
return false;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
$taxonomy = get_taxonomy( $taxonomy );
[314] Fix | Delete
return $taxonomy->hierarchical;
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
/**
[318] Fix | Delete
* Creates or modifies a taxonomy object.
[319] Fix | Delete
*
[320] Fix | Delete
* Note: Do not use before the {@see 'init'} hook.
[321] Fix | Delete
*
[322] Fix | Delete
* A simple function for creating or modifying a taxonomy object based on
[323] Fix | Delete
* the parameters given. If modifying an existing taxonomy object, note
[324] Fix | Delete
* that the `$object_type` value from the original registration will be
[325] Fix | Delete
* overwritten.
[326] Fix | Delete
*
[327] Fix | Delete
* @since 2.3.0
[328] Fix | Delete
* @since 4.2.0 Introduced `show_in_quick_edit` argument.
[329] Fix | Delete
* @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
[330] Fix | Delete
* @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
[331] Fix | Delete
* @since 4.5.0 Introduced `publicly_queryable` argument.
[332] Fix | Delete
* @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
[333] Fix | Delete
* arguments to register the Taxonomy in REST API.
[334] Fix | Delete
* @since 5.1.0 Introduced `meta_box_sanitize_cb` argument.
[335] Fix | Delete
* @since 5.4.0 Added the registered taxonomy object as a return value.
[336] Fix | Delete
* @since 5.5.0 Introduced `default_term` argument.
[337] Fix | Delete
*
[338] Fix | Delete
* @global array $wp_taxonomies Registered taxonomies.
[339] Fix | Delete
*
[340] Fix | Delete
* @param string $taxonomy Taxonomy key, must not exceed 32 characters.
[341] Fix | Delete
* @param array|string $object_type Object type or array of object types with which the taxonomy should be associated.
[342] Fix | Delete
* @param array|string $args {
[343] Fix | Delete
* Optional. Array or query string of arguments for registering a taxonomy.
[344] Fix | Delete
*
[345] Fix | Delete
* @type string[] $labels An array of labels for this taxonomy. By default, Tag labels are
[346] Fix | Delete
* used for non-hierarchical taxonomies, and Category labels are used
[347] Fix | Delete
* for hierarchical taxonomies. See accepted values in
[348] Fix | Delete
* get_taxonomy_labels(). Default empty array.
[349] Fix | Delete
* @type string $description A short descriptive summary of what the taxonomy is for. Default empty.
[350] Fix | Delete
* @type bool $public Whether a taxonomy is intended for use publicly either via
[351] Fix | Delete
* the admin interface or by front-end users. The default settings
[352] Fix | Delete
* of `$publicly_queryable`, `$show_ui`, and `$show_in_nav_menus`
[353] Fix | Delete
* are inherited from `$public`.
[354] Fix | Delete
* @type bool $publicly_queryable Whether the taxonomy is publicly queryable.
[355] Fix | Delete
* If not set, the default is inherited from `$public`
[356] Fix | Delete
* @type bool $hierarchical Whether the taxonomy is hierarchical. Default false.
[357] Fix | Delete
* @type bool $show_ui Whether to generate and allow a UI for managing terms in this taxonomy in
[358] Fix | Delete
* the admin. If not set, the default is inherited from `$public`
[359] Fix | Delete
* (default true).
[360] Fix | Delete
* @type bool $show_in_menu Whether to show the taxonomy in the admin menu. If true, the taxonomy is
[361] Fix | Delete
* shown as a submenu of the object type menu. If false, no menu is shown.
[362] Fix | Delete
* `$show_ui` must be true. If not set, default is inherited from `$show_ui`
[363] Fix | Delete
* (default true).
[364] Fix | Delete
* @type bool $show_in_nav_menus Makes this taxonomy available for selection in navigation menus. If not
[365] Fix | Delete
* set, the default is inherited from `$public` (default true).
[366] Fix | Delete
* @type bool $show_in_rest Whether to include the taxonomy in the REST API. Set this to true
[367] Fix | Delete
* for the taxonomy to be available in the block editor.
[368] Fix | Delete
* @type string $rest_base To change the base url of REST API route. Default is $taxonomy.
[369] Fix | Delete
* @type string $rest_controller_class REST API Controller class name. Default is 'WP_REST_Terms_Controller'.
[370] Fix | Delete
* @type bool $show_tagcloud Whether to list the taxonomy in the Tag Cloud Widget controls. If not set,
[371] Fix | Delete
* the default is inherited from `$show_ui` (default true).
[372] Fix | Delete
* @type bool $show_in_quick_edit Whether to show the taxonomy in the quick/bulk edit panel. It not set,
[373] Fix | Delete
* the default is inherited from `$show_ui` (default true).
[374] Fix | Delete
* @type bool $show_admin_column Whether to display a column for the taxonomy on its post type listing
[375] Fix | Delete
* screens. Default false.
[376] Fix | Delete
* @type bool|callable $meta_box_cb Provide a callback function for the meta box display. If not set,
[377] Fix | Delete
* post_categories_meta_box() is used for hierarchical taxonomies, and
[378] Fix | Delete
* post_tags_meta_box() is used for non-hierarchical. If false, no meta
[379] Fix | Delete
* box is shown.
[380] Fix | Delete
* @type callable $meta_box_sanitize_cb Callback function for sanitizing taxonomy data saved from a meta
[381] Fix | Delete
* box. If no callback is defined, an appropriate one is determined
[382] Fix | Delete
* based on the value of `$meta_box_cb`.
[383] Fix | Delete
* @type string[] $capabilities {
[384] Fix | Delete
* Array of capabilities for this taxonomy.
[385] Fix | Delete
*
[386] Fix | Delete
* @type string $manage_terms Default 'manage_categories'.
[387] Fix | Delete
* @type string $edit_terms Default 'manage_categories'.
[388] Fix | Delete
* @type string $delete_terms Default 'manage_categories'.
[389] Fix | Delete
* @type string $assign_terms Default 'edit_posts'.
[390] Fix | Delete
* }
[391] Fix | Delete
* @type bool|array $rewrite {
[392] Fix | Delete
* Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent
[393] Fix | Delete
* rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:
[394] Fix | Delete
*
[395] Fix | Delete
* @type string $slug Customize the permastruct slug. Default `$taxonomy` key.
[396] Fix | Delete
* @type bool $with_front Should the permastruct be prepended with WP_Rewrite::$front. Default true.
[397] Fix | Delete
* @type bool $hierarchical Either hierarchical rewrite tag or not. Default false.
[398] Fix | Delete
* @type int $ep_mask Assign an endpoint mask. Default `EP_NONE`.
[399] Fix | Delete
* }
[400] Fix | Delete
* @type string|bool $query_var Sets the query var key for this taxonomy. Default `$taxonomy` key. If
[401] Fix | Delete
* false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a
[402] Fix | Delete
* string, the query `?{query_var}={term_slug}` will be valid.
[403] Fix | Delete
* @type callable $update_count_callback Works much like a hook, in that it will be called when the count is
[404] Fix | Delete
* updated. Default _update_post_term_count() for taxonomies attached
[405] Fix | Delete
* to post types, which confirms that the objects are published before
[406] Fix | Delete
* counting them. Default _update_generic_term_count() for taxonomies
[407] Fix | Delete
* attached to other object types, such as users.
[408] Fix | Delete
* @type string|array $default_term {
[409] Fix | Delete
* Default term to be used for the taxonomy.
[410] Fix | Delete
*
[411] Fix | Delete
* @type string $name Name of default term.
[412] Fix | Delete
* @type string $slug Slug for default term. Default empty.
[413] Fix | Delete
* @type string $description Description for default term. Default empty.
[414] Fix | Delete
* }
[415] Fix | Delete
* @type bool $sort Whether terms in this taxonomy should be sorted in the order they are
[416] Fix | Delete
* provided to `wp_set_object_terms()`. Default null which equates to false.
[417] Fix | Delete
* @type array $args Array of arguments to automatically use inside `wp_get_object_terms()`
[418] Fix | Delete
* for this taxonomy.
[419] Fix | Delete
* @type bool $_builtin This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
[420] Fix | Delete
* Default false.
[421] Fix | Delete
* }
[422] Fix | Delete
* @return WP_Taxonomy|WP_Error The registered taxonomy object on success, WP_Error object on failure.
[423] Fix | Delete
*/
[424] Fix | Delete
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
[425] Fix | Delete
global $wp_taxonomies;
[426] Fix | Delete
[427] Fix | Delete
if ( ! is_array( $wp_taxonomies ) ) {
[428] Fix | Delete
$wp_taxonomies = array();
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
$args = wp_parse_args( $args );
[432] Fix | Delete
[433] Fix | Delete
if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) {
[434] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2.0' );
[435] Fix | Delete
return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) );
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
$taxonomy_object = new WP_Taxonomy( $taxonomy, $object_type, $args );
[439] Fix | Delete
$taxonomy_object->add_rewrite_rules();
[440] Fix | Delete
[441] Fix | Delete
$wp_taxonomies[ $taxonomy ] = $taxonomy_object;
[442] Fix | Delete
[443] Fix | Delete
$taxonomy_object->add_hooks();
[444] Fix | Delete
[445] Fix | Delete
// Add default term.
[446] Fix | Delete
if ( ! empty( $taxonomy_object->default_term ) ) {
[447] Fix | Delete
$term = term_exists( $taxonomy_object->default_term['name'], $taxonomy );
[448] Fix | Delete
if ( $term ) {
[449] Fix | Delete
update_option( 'default_term_' . $taxonomy_object->name, $term['term_id'] );
[450] Fix | Delete
} else {
[451] Fix | Delete
$term = wp_insert_term(
[452] Fix | Delete
$taxonomy_object->default_term['name'],
[453] Fix | Delete
$taxonomy,
[454] Fix | Delete
array(
[455] Fix | Delete
'slug' => sanitize_title( $taxonomy_object->default_term['slug'] ),
[456] Fix | Delete
'description' => $taxonomy_object->default_term['description'],
[457] Fix | Delete
)
[458] Fix | Delete
);
[459] Fix | Delete
[460] Fix | Delete
// Update `term_id` in options.
[461] Fix | Delete
if ( ! is_wp_error( $term ) ) {
[462] Fix | Delete
update_option( 'default_term_' . $taxonomy_object->name, $term['term_id'] );
[463] Fix | Delete
}
[464] Fix | Delete
}
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
/**
[468] Fix | Delete
* Fires after a taxonomy is registered.
[469] Fix | Delete
*
[470] Fix | Delete
* @since 3.3.0
[471] Fix | Delete
*
[472] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[473] Fix | Delete
* @param array|string $object_type Object type or array of object types.
[474] Fix | Delete
* @param array $args Array of taxonomy registration arguments.
[475] Fix | Delete
*/
[476] Fix | Delete
do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );
[477] Fix | Delete
[478] Fix | Delete
return $taxonomy_object;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
/**
[482] Fix | Delete
* Unregisters a taxonomy.
[483] Fix | Delete
*
[484] Fix | Delete
* Can not be used to unregister built-in taxonomies.
[485] Fix | Delete
*
[486] Fix | Delete
* @since 4.5.0
[487] Fix | Delete
*
[488] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[489] Fix | Delete
* @global array $wp_taxonomies List of taxonomies.
[490] Fix | Delete
*
[491] Fix | Delete
* @param string $taxonomy Taxonomy name.
[492] Fix | Delete
* @return true|WP_Error True on success, WP_Error on failure or if the taxonomy doesn't exist.
[493] Fix | Delete
*/
[494] Fix | Delete
function unregister_taxonomy( $taxonomy ) {
[495] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[496] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function