Changeset 25130 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 08/26/2013 08:23:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r25108 r25130 271 271 * Optional $args contents: 272 272 * 273 * label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used. 274 * 275 * hierarchical - has some defined purpose at other parts of the API and is a 276 * boolean value. 277 * 278 * update_count_callback - works much like a hook, in that it will be called when the count is updated. 279 * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms 280 * that the objects are published before counting them. 281 * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links. 282 * 283 * rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize 284 * permastruct; default will use $taxonomy as slug. 285 * 286 * query_var - false to prevent queries, or string to customize query var 287 * (?$query_var=$term); default will use $taxonomy as query var. 288 * 289 * public - If the taxonomy should be publicly queryable; //@TODO not implemented. 290 * defaults to true. 291 * 292 * show_ui - If the WordPress UI admin tags UI should apply to this taxonomy; 293 * defaults to public. 294 * 295 * show_in_nav_menus - true makes this taxonomy available for selection in navigation menus. 296 * Defaults to public. 297 * 298 * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget; 299 * defaults to show_ui which defaults to public. 300 * 301 * labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones. 302 * 303 * description - A short descriptive summary of what the taxonomy is for. Defaults to blank. 304 * 305 * @package WordPress 306 * @subpackage Taxonomy 273 * - label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used. 274 * - labels - An array of labels for this taxonomy. 275 * * By default tag labels are used for non-hierarchical types and category labels for hierarchical ones. 276 * * You can see accepted values in {@link get_taxonomy_labels()}. 277 * - description - A short descriptive summary of what the taxonomy is for. Defaults to blank. 278 * - public - If the taxonomy should be publicly queryable; //@TODO not implemented. 279 * * Defaults to true. 280 * - hierarchical - Whether the taxonomy is hierarchical (e.g. category). Defaults to false. 281 * - show_ui -Whether to generate a default UI for managing this taxonomy in the admin. 282 * * If not set, the default is inherited from public. 283 * - show_in_nav_menus - Makes this taxonomy available for selection in navigation menus. 284 * * If not set, the default is inherited from public. 285 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget. 286 * * If not set, the default is inherited from show_ui. 287 * - capabilities - Array of capabilities for this taxonomy. 288 * * You can see accepted values in this function. 289 * - rewrite - Triggers the handling of rewrites for this taxonomy. Defaults to true, using $taxonomy as slug. 290 * * To prevent rewrite, set to false. 291 * * To specify rewrite rules, an array can be passed with any of these keys 292 * * 'slug' => string Customize the permastruct slug. Defaults to $taxonomy key 293 * * 'with_front' => bool Should the permastruct be prepended with WP_Rewrite::$front. Defaults to true. 294 * * 'hierarchical' => bool Either hierarchical rewrite tag or not. Defaults to false. 295 * * 'ep_mask' => const Assign an endpoint mask. 296 * * If not specified, defaults to EP_NONE. 297 * - query_var - Sets the query_var key for this taxonomy. Defaults to $taxonomy key 298 * * If false, a taxonomy cannot be loaded at ?{query_var}={term_slug} 299 * * If specified as a string, the query ?{query_var_string}={term_slug} will be valid. 300 * - update_count_callback - Works much like a hook, in that it will be called when the count is updated. 301 * * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms 302 * that the objects are published before counting them. 303 * * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links. 304 * - _builtin - true if this taxonomy is a native or "built-in" taxonomy. THIS IS FOR INTERNAL USE ONLY! 305 * 307 306 * @since 2.3.0 308 307 * @uses $wp_taxonomies Inserts new taxonomy object into the list 309 308 * @uses $wp Adds query vars 310 309 * 311 * @param string $taxonomy Name of taxonomy object310 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 312 311 * @param array|string $object_type Name of the object type for the taxonomy object. 313 * @param array|string $args See above description for the two keys values.312 * @param array|string $args See optional args description above. 314 313 * @return null|WP_Error WP_Error if errors, otherwise null. 315 314 */ … … 317 316 global $wp_taxonomies, $wp; 318 317 319 if ( ! is_array( $wp_taxonomies) )318 if ( ! is_array( $wp_taxonomies ) ) 320 319 $wp_taxonomies = array(); 321 320 322 321 $defaults = array( 323 'hierarchical' => false, 322 'labels' => array(), 323 'description' => '', 324 'public' => true, 325 'hierarchical' => false, 326 'show_ui' => null, 327 'show_in_nav_menus' => null, 328 'show_tagcloud' => null, 329 'capabilities' => array(), 330 'rewrite' => true, 331 'query_var' => $taxonomy, 324 332 'update_count_callback' => '', 325 'rewrite' => true, 326 'query_var' => $taxonomy, 327 'public' => true, 328 'show_ui' => null, 329 'show_tagcloud' => null, 330 '_builtin' => false, 331 'labels' => array(), 332 'capabilities' => array(), 333 'show_in_nav_menus' => null, 334 'description' => '', 333 '_builtin' => false, 335 334 ); 336 $args = wp_parse_args( $args, $defaults);335 $args = wp_parse_args( $args, $defaults ); 337 336 338 337 if ( strlen( $taxonomy ) > 32 ) 339 338 return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) ); 340 339 341 if ( false !== $args['query_var'] && ! empty($wp) ) {340 if ( false !== $args['query_var'] && ! empty( $wp ) ) { 342 341 if ( true === $args['query_var'] ) 343 342 $args['query_var'] = $taxonomy; 344 343 else 345 $args['query_var'] = sanitize_title_with_dashes( $args['query_var']);346 $wp->add_query_var( $args['query_var']);347 } 348 349 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure') ) ) {350 $args['rewrite'] = wp_parse_args( $args['rewrite'], array(351 'slug' => sanitize_title_with_dashes( $taxonomy),344 $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); 345 $wp->add_query_var( $args['query_var'] ); 346 } 347 348 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 349 $args['rewrite'] = wp_parse_args( $args['rewrite'], array( 350 'slug' => sanitize_title_with_dashes( $taxonomy ), 352 351 'with_front' => true, 353 352 'hierarchical' => false, 354 353 'ep_mask' => EP_NONE, 355 ) );354 ) ); 356 355 357 356 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) … … 364 363 } 365 364 366 if ( is_null($args['show_ui']) ) 365 // If not set, default to the setting for public. 366 if ( null === $args['show_ui'] ) 367 367 $args['show_ui'] = $args['public']; 368 368 369 // Whether to show this type in nav-menus.php. Defaultsto the setting for public.369 // If not set, default to the setting for public. 370 370 if ( null === $args['show_in_nav_menus'] ) 371 371 $args['show_in_nav_menus'] = $args['public']; 372 372 373 if ( is_null($args['show_tagcloud']) ) 373 // If not set, default to the setting for show_ui. 374 if ( null === $args['show_tagcloud'] ) 374 375 $args['show_tagcloud'] = $args['show_ui']; 375 376 … … 384 385 385 386 $args['name'] = $taxonomy; 386 $args['object_type'] = array_unique( (array)$object_type );387 $args['object_type'] = array_unique( (array) $object_type ); 387 388 388 389 $args['labels'] = get_taxonomy_labels( (object) $args ); 389 390 $args['label'] = $args['labels']->name; 390 391 391 $wp_taxonomies[ $taxonomy] = (object) $args;392 $wp_taxonomies[ $taxonomy ] = (object) $args; 392 393 393 394 // register callback handling for metabox 394 add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');395 add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' ); 395 396 396 397 do_action( 'registered_taxonomy', $taxonomy, $object_type, $args );
Note: See TracChangeset
for help on using the changeset viewer.