Ticket #36224: 36224.diff
File 36224.diff, 20.3 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index 34d179c..2effada 100644
function wp_ajax_ajax_tag_search() { 136 136 * 137 137 * @since 4.0.0 138 138 * 139 * @param int $characters The minimum number of characters required. Default 2.140 * @param object$tax The taxonomy object.141 * @param string $s The search term.139 * @param int $characters The minimum number of characters required. Default 2. 140 * @param WP_Taxonomy $tax The taxonomy object. 141 * @param string $s The search term. 142 142 */ 143 143 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s ); 144 144 -
new file src/wp-includes/class-wp-taxonomy.php
diff --git src/wp-includes/class-wp-taxonomy.php src/wp-includes/class-wp-taxonomy.php new file mode 100644 index 0000000..30fa9a1
- + 1 <?php 2 /** 3 * Taxonomy API: WP_Taxonomy class 4 * 5 * @package WordPress 6 * @subpackage Taxonomy 7 * @since 4.6.0 8 */ 9 10 /** 11 * Core class used for interacting with taxonomies. 12 * 13 * @since 4.6.0 14 */ 15 final class WP_Taxonomy implements ArrayAccess { 16 /** 17 * Taxonomy key. 18 * 19 * @since 4.6.0 20 * @access public 21 * @var string 22 */ 23 public $name; 24 25 /** 26 * Name of the taxonomy shown in the menu. Usually plural. 27 * 28 * @since 4.6.0 29 * @access public 30 * @var string 31 */ 32 public $label; 33 34 /** 35 * An array of labels for this taxonomy. 36 * 37 * @since 4.6.0 38 * @access public 39 * @var array 40 */ 41 public $labels = array(); 42 43 /** 44 * A short descriptive summary of what the taxonomy is for. 45 * 46 * @since 4.6.0 47 * @access public 48 * @var string 49 */ 50 public $description = ''; 51 52 /** 53 * Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. 54 * 55 * @since 4.6.0 56 * @access public 57 * @var bool 58 */ 59 public $public = true; 60 61 /** 62 * Whether the taxonomy is publicly queryable. 63 * 64 * @since 4.6.0 65 * @access public 66 * @var bool 67 */ 68 public $publicly_queryable = true; 69 70 /** 71 * Whether the taxonomy is hierarchical. 72 * 73 * @since 4.6.0 74 * @access public 75 * @var bool 76 */ 77 public $hierarchical = false; 78 79 /** 80 * Whether to generate and allow a UI for managing terms in this taxonomy in the admin. 81 * 82 * @since 4.6.0 83 * @access public 84 * @var bool 85 */ 86 public $show_ui = true; 87 88 /** 89 * Whether to show the taxonomy in the admin menu. 90 * 91 * If true, the taxonomy is shown as a submenu of the object type menu. If false, no menu is shown. 92 * 93 * @since 4.6.0 94 * @access public 95 * @var bool 96 */ 97 public $show_in_menu = true; 98 99 /** 100 * Whether the taxonomy is available for selection in navigation menus. 101 * 102 * @since 4.6.0 103 * @access public 104 * @var bool 105 */ 106 public $show_in_nav_menus = true; 107 108 /** 109 * Whether to list the taxonomy in the tag cloud widget controls. 110 * 111 * @since 4.6.0 112 * @access public 113 * @var bool 114 */ 115 public $show_tagcloud = true; 116 117 /** 118 * Whether to show the taxonomy in the quick/bulk edit panel. 119 * 120 * @since 4.6.0 121 * @access public 122 * @var bool 123 */ 124 public $show_in_quick_edit = true; 125 126 /** 127 * Whether to display a column for the taxonomy on its post type listing screens. 128 * 129 * @since 4.6.0 130 * @access public 131 * @var bool 132 */ 133 public $show_admin_column = false; 134 135 /** 136 * The callback function for the meta box display. 137 * 138 * @since 4.6.0 139 * @access public 140 * @var bool|callable 141 */ 142 public $meta_box_cb = null; 143 144 /** 145 * An array of object types this taxonomy is registered for. 146 * 147 * @since 4.6.0 148 * @access public 149 * @var array 150 */ 151 public $object_type = null; 152 153 /** 154 * Constructor. 155 * 156 * @since 4.6.0 157 * @access public 158 * 159 * @global WP $wp WP instance. 160 * 161 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 162 * @param array|string $object_type Name of the object type for the taxonomy object. 163 * @param array|string $args { 164 * Optional. Array or query string of arguments for registering a taxonomy. 165 */ 166 public function __construct( $taxonomy, $object_type, $args ) { 167 global $wp; 168 169 $args = wp_parse_args( $args ); 170 171 /** 172 * Filter the arguments for registering a taxonomy. 173 * 174 * @since 4.4.0 175 * 176 * @param array $args Array of arguments for registering a taxonomy. 177 * @param string $taxonomy Taxonomy key. 178 * @param array $object_type Array of names of object types for the taxonomy. 179 */ 180 $args = apply_filters( 'register_taxonomy_args', $args, $taxonomy, (array) $object_type ); 181 182 $defaults = array( 183 'labels' => array(), 184 'description' => '', 185 'public' => true, 186 'publicly_queryable' => null, 187 'hierarchical' => false, 188 'show_ui' => null, 189 'show_in_menu' => null, 190 'show_in_nav_menus' => null, 191 'show_tagcloud' => null, 192 'show_in_quick_edit' => null, 193 'show_admin_column' => false, 194 'meta_box_cb' => null, 195 'capabilities' => array(), 196 'rewrite' => true, 197 'query_var' => $taxonomy, 198 'update_count_callback' => '', 199 '_builtin' => false, 200 ); 201 $args = array_merge( $defaults, $args ); 202 203 // If not set, default to the setting for public. 204 if ( null === $args['publicly_queryable'] ) { 205 $args['publicly_queryable'] = $args['public']; 206 } 207 208 // Non-publicly queryable taxonomies should not register query vars, except in the admin. 209 if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) && ! empty( $wp ) ) { 210 if ( true === $args['query_var'] ) { 211 $args['query_var'] = $taxonomy; 212 } else { 213 $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); 214 } 215 $wp->add_query_var( $args['query_var'] ); 216 } else { 217 // Force query_var to false for non-public taxonomies. 218 $args['query_var'] = false; 219 } 220 221 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 222 $args['rewrite'] = wp_parse_args( $args['rewrite'], array( 223 'with_front' => true, 224 'hierarchical' => false, 225 'ep_mask' => EP_NONE, 226 ) ); 227 228 if ( empty( $args['rewrite']['slug'] ) ) { 229 $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy ); 230 } 231 232 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) { 233 $tag = '(.+?)'; 234 } else { 235 $tag = '([^/]+)'; 236 } 237 238 add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); 239 add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); 240 } 241 242 // If not set, default to the setting for public. 243 if ( null === $args['show_ui'] ) { 244 $args['show_ui'] = $args['public']; 245 } 246 247 // If not set, default to the setting for show_ui. 248 if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) { 249 $args['show_in_menu'] = $args['show_ui']; 250 } 251 252 // If not set, default to the setting for public. 253 if ( null === $args['show_in_nav_menus'] ) { 254 $args['show_in_nav_menus'] = $args['public']; 255 } 256 257 // If not set, default to the setting for show_ui. 258 if ( null === $args['show_tagcloud'] ) { 259 $args['show_tagcloud'] = $args['show_ui']; 260 } 261 262 // If not set, default to the setting for show_ui. 263 if ( null === $args['show_in_quick_edit'] ) { 264 $args['show_in_quick_edit'] = $args['show_ui']; 265 } 266 267 $default_caps = array( 268 'manage_terms' => 'manage_categories', 269 'edit_terms' => 'manage_categories', 270 'delete_terms' => 'manage_categories', 271 'assign_terms' => 'edit_posts', 272 ); 273 $args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] ); 274 unset( $args['capabilities'] ); 275 276 $args['name'] = $taxonomy; 277 $args['object_type'] = array_unique( (array) $object_type ); 278 279 $args['labels'] = get_taxonomy_labels( (object) $args ); 280 $args['label'] = $args['labels']->name; 281 282 // If not set, use the default meta box 283 if ( null === $args['meta_box_cb'] ) { 284 if ( $args['hierarchical'] ) { 285 $args['meta_box_cb'] = 'post_categories_meta_box'; 286 } else { 287 $args['meta_box_cb'] = 'post_tags_meta_box'; 288 } 289 } 290 291 foreach ( $args as $key => $value ) { 292 $this->$key = $value; 293 } 294 } 295 296 /** 297 * Retrieves the taxonomy object of `$taxonomy`. 298 * 299 * @since 4.6.0 300 * @access public 301 * @static 302 * 303 * @global array $wp_taxonomies The registered taxonomies. 304 * 305 * @param string $taxonomy Name of taxonomy object to return. 306 * @return WP_Taxonomy|false The Taxonomy object or false if taxonomy does not exist. 307 */ 308 public static function get_instance( $taxonomy ) { 309 global $wp_taxonomies; 310 311 if ( ! taxonomy_exists( $taxonomy ) ) 312 return false; 313 314 return $wp_taxonomies[$taxonomy]; 315 } 316 317 /** 318 * Method to implement ArrayAccess for taxonomy arguments. 319 * 320 * @since 4.6.0 321 * @access public 322 * 323 * @param mixed $offset 324 * @param mixed $value 325 */ 326 public function offsetSet( $offset, $value ) { 327 if ( $this->offsetExists( $offset ) ) { 328 $this->$offset = $value; 329 } 330 } 331 332 /** 333 * Method to implement ArrayAccess for taxonomy arguments. 334 * 335 * @since 4.6.0 336 * @access public 337 * 338 * @param mixed $offset 339 */ 340 public function offsetUnset( $offset ) { 341 if ( $this->offsetExists( $offset ) ) { 342 unset( $this->$offset ); 343 } 344 } 345 346 /** 347 * Method to implement ArrayAccess for taxonomy arguments. 348 * 349 * @since 4.6.0 350 * @access public 351 * 352 * @param mixed $offset 353 * @return bool 354 */ 355 public function offsetExists( $offset ) { 356 return property_exists( $this, $offset ); 357 } 358 359 /** 360 * Method to implement ArrayAccess for taxonomy arguments. 361 * 362 * @since 4.6.0 363 * @access public 364 * 365 * @param mixed $offset 366 * @return mixed 367 */ 368 public function offsetGet( $offset ) { 369 if ( $this->offsetExists( $offset ) ) { 370 return $this->$offset; 371 } 372 } 373 } -
src/wp-includes/class-wp-xmlrpc-server.php
diff --git src/wp-includes/class-wp-xmlrpc-server.php src/wp-includes/class-wp-xmlrpc-server.php index c331591..7058f51 100644
class wp_xmlrpc_server extends IXR_Server { 695 695 * 696 696 * @since 3.4.0 697 697 * 698 * @param array $_taxonomy An array of taxonomy data.699 * @param object$taxonomy Taxonomy object.700 * @param array $fields The subset of taxonomy fields to return.698 * @param array $_taxonomy An array of taxonomy data. 699 * @param WP_Taxonomy $taxonomy Taxonomy object. 700 * @param array $fields The subset of taxonomy fields to return. 701 701 */ 702 702 return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); 703 703 } -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index 8fad3d9..93547fb 100644
function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) 162 162 * Example: 163 163 * 164 164 * $taxonomies = get_object_taxonomies( 'post' ); 165 * 165 * 166 166 * This results in: 167 * 167 * 168 168 * Array( 'category', 'post_tag' ) 169 169 * 170 170 * @since 2.3.0 … … function get_object_taxonomies( $object, $output = 'names' ) { 208 208 * 209 209 * @since 2.3.0 210 210 * 211 * @global array $wp_taxonomies The registered taxonomies.212 *213 211 * @param string $taxonomy Name of taxonomy object to return. 214 * @return object|false The Taxonomy Object or false if $taxonomy doesn't exist.212 * @return WP_Taxonomy|false The Taxonomy object or false if taxonomy does not exist. 215 213 */ 216 214 function get_taxonomy( $taxonomy ) { 217 global $wp_taxonomies; 218 219 if ( ! taxonomy_exists( $taxonomy ) ) 220 return false; 221 222 return $wp_taxonomies[$taxonomy]; 215 return WP_Taxonomy::get_instance( $taxonomy ); 223 216 } 224 217 225 218 /** … … function is_taxonomy_hierarchical($taxonomy) { 276 269 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen. 277 270 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end. 278 271 * @since 4.5.0 Introduced `publicly_queryable` argument. 272 * @since 4.6.0 The function now returns the registered taxonomy object on success. 279 273 * 280 274 * @global array $wp_taxonomies Registered taxonomies. 281 * @global WP $wp WP instance.282 275 * 283 276 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 284 277 * @param array|string $object_type Name of the object type for the taxonomy object. … … function is_taxonomy_hierarchical($taxonomy) { 346 339 * @type bool $_builtin This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY! 347 340 * Default false. 348 341 * } 349 * @return WP_ Error|void WP_Error, if errors.342 * @return WP_Taxonomy|WP_Error The registered taxonomy object, or an error object. 350 343 */ 351 344 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 352 global $wp_taxonomies , $wp;345 global $wp_taxonomies; 353 346 354 if ( ! is_array( $wp_taxonomies ) ) 347 if ( ! is_array( $wp_taxonomies ) ) { 355 348 $wp_taxonomies = array(); 356 357 $args = wp_parse_args( $args ); 358 359 /** 360 * Filter the arguments for registering a taxonomy. 361 * 362 * @since 4.4.0 363 * 364 * @param array $args Array of arguments for registering a taxonomy. 365 * @param string $taxonomy Taxonomy key. 366 * @param array $object_type Array of names of object types for the taxonomy. 367 */ 368 $args = apply_filters( 'register_taxonomy_args', $args, $taxonomy, (array) $object_type ); 369 370 $defaults = array( 371 'labels' => array(), 372 'description' => '', 373 'public' => true, 374 'publicly_queryable' => null, 375 'hierarchical' => false, 376 'show_ui' => null, 377 'show_in_menu' => null, 378 'show_in_nav_menus' => null, 379 'show_tagcloud' => null, 380 'show_in_quick_edit' => null, 381 'show_admin_column' => false, 382 'meta_box_cb' => null, 383 'capabilities' => array(), 384 'rewrite' => true, 385 'query_var' => $taxonomy, 386 'update_count_callback' => '', 387 '_builtin' => false, 388 ); 389 $args = array_merge( $defaults, $args ); 349 } 390 350 391 351 if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) { 392 352 _doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2' ); 393 353 return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) ); 394 354 } 395 355 396 // If not set, default to the setting for public. 397 if ( null === $args['publicly_queryable'] ) { 398 $args['publicly_queryable'] = $args['public']; 399 } 356 $taxonomy_object = new WP_Taxonomy( $taxonomy, $object_type, $args ); 400 357 401 // Non-publicly queryable taxonomies should not register query vars, except in the admin. 402 if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) && ! empty( $wp ) ) { 403 if ( true === $args['query_var'] ) 404 $args['query_var'] = $taxonomy; 405 else 406 $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); 407 $wp->add_query_var( $args['query_var'] ); 408 } else { 409 // Force query_var to false for non-public taxonomies. 410 $args['query_var'] = false; 411 } 412 413 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 414 $args['rewrite'] = wp_parse_args( $args['rewrite'], array( 415 'with_front' => true, 416 'hierarchical' => false, 417 'ep_mask' => EP_NONE, 418 ) ); 419 420 if ( empty( $args['rewrite']['slug'] ) ) 421 $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy ); 422 423 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) 424 $tag = '(.+?)'; 425 else 426 $tag = '([^/]+)'; 427 428 add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); 429 add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); 430 } 431 432 // If not set, default to the setting for public. 433 if ( null === $args['show_ui'] ) 434 $args['show_ui'] = $args['public']; 435 436 // If not set, default to the setting for show_ui. 437 if ( null === $args['show_in_menu' ] || ! $args['show_ui'] ) 438 $args['show_in_menu' ] = $args['show_ui']; 439 440 // If not set, default to the setting for public. 441 if ( null === $args['show_in_nav_menus'] ) 442 $args['show_in_nav_menus'] = $args['public']; 443 444 // If not set, default to the setting for show_ui. 445 if ( null === $args['show_tagcloud'] ) 446 $args['show_tagcloud'] = $args['show_ui']; 358 $wp_taxonomies[ $taxonomy ] = $taxonomy_object; 447 359 448 // If not set, default to the setting for show_ui. 449 if ( null === $args['show_in_quick_edit'] ) { 450 $args['show_in_quick_edit'] = $args['show_ui']; 451 } 452 453 $default_caps = array( 454 'manage_terms' => 'manage_categories', 455 'edit_terms' => 'manage_categories', 456 'delete_terms' => 'manage_categories', 457 'assign_terms' => 'edit_posts', 458 ); 459 $args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] ); 460 unset( $args['capabilities'] ); 461 462 $args['name'] = $taxonomy; 463 $args['object_type'] = array_unique( (array) $object_type ); 464 465 $args['labels'] = get_taxonomy_labels( (object) $args ); 466 $args['label'] = $args['labels']->name; 467 468 // If not set, use the default meta box 469 if ( null === $args['meta_box_cb'] ) { 470 if ( $args['hierarchical'] ) 471 $args['meta_box_cb'] = 'post_categories_meta_box'; 472 else 473 $args['meta_box_cb'] = 'post_tags_meta_box'; 474 } 475 476 $wp_taxonomies[ $taxonomy ] = (object) $args; 477 478 // register callback handling for metabox 360 // Register callback handling for metabox. 479 361 add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' ); 480 362 481 363 /** … … function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 483 365 * 484 366 * @since 3.3.0 485 367 * 486 * @param string $taxonomy Taxonomy slug.487 * @param array|string $object_type Object type or array of object types.488 * @param array $args Array of taxonomy registration arguments.368 * @param string $taxonomy Taxonomy slug. 369 * @param array|string $object_type Object type or array of object types. 370 * @param WP_Taxonomy $taxonomy_object The registered taxonomy object. 489 371 */ 490 do_action( 'registered_taxonomy', $taxonomy, $object_type, $args ); 372 do_action( 'registered_taxonomy', $taxonomy, $object_type, $taxonomy_object ); 373 374 return $taxonomy_object; 491 375 } 492 376 493 377 /** … … function unregister_taxonomy( $taxonomy ) { 579 463 * @since 4.3.0 Added the `no_terms` label. 580 464 * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels. 581 465 * 582 * @param object $taxTaxonomy object.466 * @param object|WP_Taxonomy $tax Custom-something object or WP_Taxonomy object. 583 467 * @return object object with all the labels as member variables. 584 468 */ 585 469 function get_taxonomy_labels( $tax ) { -
src/wp-settings.php
diff --git src/wp-settings.php src/wp-settings.php index a4bb370..d7ecfc3 100644
require( ABSPATH . WPINC . '/cron.php' ); 166 166 require( ABSPATH . WPINC . '/deprecated.php' ); 167 167 require( ABSPATH . WPINC . '/script-loader.php' ); 168 168 require( ABSPATH . WPINC . '/taxonomy.php' ); 169 require( ABSPATH . WPINC . '/class-wp-taxonomy.php' ); 169 170 require( ABSPATH . WPINC . '/class-wp-term.php' ); 170 171 require( ABSPATH . WPINC . '/class-wp-tax-query.php' ); 171 172 require( ABSPATH . WPINC . '/update.php' ); -
new file tests/phpunit/tests/term/wpTaxonomy.php
diff --git tests/phpunit/tests/term/wpTaxonomy.php tests/phpunit/tests/term/wpTaxonomy.php new file mode 100644 index 0000000..d80700a
- + 1 <?php 2 3 /** 4 * @group taxonomy 5 */ 6 class Tests_WP_Taxonomy extends WP_UnitTestCase { 7 public function test_get_instance_invalid_taxonomy() { 8 $this->assertFalse( WP_Taxonomy::get_instance( 'foo' ) ); 9 } 10 11 public function test_get_instance_builtin_taxonomy() { 12 $taxonomy = WP_Taxonomy::get_instance( 'category' ); 13 $this->assertInstanceOf( 'WP_Taxonomy', $taxonomy ); 14 $this->assertEquals( 'category', $taxonomy->name ); 15 16 $taxonomy = WP_Taxonomy::get_instance( 'post_tag' ); 17 $this->assertInstanceOf( 'WP_Taxonomy', $taxonomy ); 18 $this->assertEquals( 'post_tag', $taxonomy->name ); 19 } 20 21 public function test_array_access() { 22 $taxonomy = rand_str(); 23 $taxonomy_object = register_taxonomy( $taxonomy, 'post' ); 24 $this->assertEquals( $taxonomy, $taxonomy_object['name'] ); 25 $this->assertEquals( $taxonomy, $taxonomy_object->name ); 26 } 27 }