Ticket #36224: 36224.3.diff
File 36224.3.diff, 22.2 KB (added by , 8 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 6a80f06..0aab1ef 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..f5ee05a
- + 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 { 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 * Capabilities for this taxonomy. 155 * 156 * @since 4.6.0 157 * @access public 158 * @var array 159 */ 160 public $cap; 161 162 /** 163 * Rewrites information for this taxonomy. 164 * 165 * @since 4.6.0 166 * @access public 167 * @var array|false 168 */ 169 public $rewrite; 170 171 /** 172 * Query var string for this taxonomy. 173 * 174 * @since 4.6.0 175 * @access public 176 * @var string|false 177 */ 178 public $query_var; 179 180 /** 181 * Function that will be called when the count is updated. 182 * 183 * @since 4.6.0 184 * @access public 185 * @var callable 186 */ 187 public $update_count_callback; 188 189 /** 190 * Whether it is a built-in taxonomy. 191 * 192 * @since 4.6.0 193 * @access public 194 * @var bool 195 */ 196 public $_builtin; 197 198 /** 199 * Constructor. 200 * 201 * @since 4.6.0 202 * @access public 203 * 204 * @global WP $wp WP instance. 205 * 206 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 207 * @param array|string $object_type Name of the object type for the taxonomy object. 208 * @param array|string $args Optional. Array or query string of arguments for registering a taxonomy. 209 * Default empty array. 210 */ 211 public function __construct( $taxonomy, $object_type, $args = array() ) { 212 $this->name = $taxonomy; 213 214 $this->set_props( $object_type, $args ); 215 } 216 217 /** 218 * Sets taxonomy properties. 219 * 220 * @since 4.6.0 221 * @access public 222 * 223 * @param array|string $object_type Name of the object type for the taxonomy object. 224 * @param array|string $args Array or query string of arguments for registering a taxonomy. 225 */ 226 public function set_props( $object_type, $args ) { 227 $args = wp_parse_args( $args ); 228 229 /** 230 * Filters the arguments for registering a taxonomy. 231 * 232 * @since 4.4.0 233 * 234 * @param array $args Array of arguments for registering a taxonomy. 235 * @param string $taxonomy Taxonomy key. 236 * @param array $object_type Array of names of object types for the taxonomy. 237 */ 238 $args = apply_filters( 'register_taxonomy_args', $args, $this->name, (array) $object_type ); 239 240 $defaults = array( 241 'labels' => array(), 242 'description' => '', 243 'public' => true, 244 'publicly_queryable' => null, 245 'hierarchical' => false, 246 'show_ui' => null, 247 'show_in_menu' => null, 248 'show_in_nav_menus' => null, 249 'show_tagcloud' => null, 250 'show_in_quick_edit' => null, 251 'show_admin_column' => false, 252 'meta_box_cb' => null, 253 'capabilities' => array(), 254 'rewrite' => true, 255 'query_var' => $this->name, 256 'update_count_callback' => '', 257 '_builtin' => false, 258 ); 259 260 $args = array_merge( $defaults, $args ); 261 262 // If not set, default to the setting for public. 263 if ( null === $args['publicly_queryable'] ) { 264 $args['publicly_queryable'] = $args['public']; 265 } 266 267 if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) ) { 268 if ( true === $args['query_var'] ) { 269 $args['query_var'] = $this->name; 270 } else { 271 $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); 272 } 273 } else { 274 // Force query_var to false for non-public taxonomies. 275 $args['query_var'] = false; 276 } 277 278 if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 279 $args['rewrite'] = wp_parse_args( $args['rewrite'], array( 280 'with_front' => true, 281 'hierarchical' => false, 282 'ep_mask' => EP_NONE, 283 ) ); 284 285 if ( empty( $args['rewrite']['slug'] ) ) { 286 $args['rewrite']['slug'] = sanitize_title_with_dashes( $this->name ); 287 } 288 } 289 290 // If not set, default to the setting for public. 291 if ( null === $args['show_ui'] ) { 292 $args['show_ui'] = $args['public']; 293 } 294 295 // If not set, default to the setting for show_ui. 296 if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) { 297 $args['show_in_menu'] = $args['show_ui']; 298 } 299 300 // If not set, default to the setting for public. 301 if ( null === $args['show_in_nav_menus'] ) { 302 $args['show_in_nav_menus'] = $args['public']; 303 } 304 305 // If not set, default to the setting for show_ui. 306 if ( null === $args['show_tagcloud'] ) { 307 $args['show_tagcloud'] = $args['show_ui']; 308 } 309 310 // If not set, default to the setting for show_ui. 311 if ( null === $args['show_in_quick_edit'] ) { 312 $args['show_in_quick_edit'] = $args['show_ui']; 313 } 314 315 $default_caps = array( 316 'manage_terms' => 'manage_categories', 317 'edit_terms' => 'manage_categories', 318 'delete_terms' => 'manage_categories', 319 'assign_terms' => 'edit_posts', 320 ); 321 322 $args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] ); 323 unset( $args['capabilities'] ); 324 325 $args['object_type'] = array_unique( (array) $object_type ); 326 327 // If not set, use the default meta box 328 if ( null === $args['meta_box_cb'] ) { 329 if ( $args['hierarchical'] ) { 330 $args['meta_box_cb'] = 'post_categories_meta_box'; 331 } else { 332 $args['meta_box_cb'] = 'post_tags_meta_box'; 333 } 334 } 335 336 foreach ( $args as $property_name => $property_value ) { 337 $this->$property_name = $property_value; 338 } 339 340 $this->labels = get_taxonomy_labels( $this ); 341 $this->label = $this->labels->name; 342 } 343 344 /** 345 * Adds the necessary rewrite rules for the taxonomy. 346 * 347 * @since 4.6.0 348 * @access public 349 * 350 * @global WP $wp Current WordPress environment instance. 351 */ 352 public function add_rewrite_rules() { 353 /* @var WP $wp */ 354 global $wp; 355 356 // Non-publicly queryable taxonomies should not register query vars, except in the admin. 357 if ( false !== $this->query_var && $wp ) { 358 $wp->add_query_var( $this->query_var ); 359 } 360 361 if ( false !== $this->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 362 if ( $this->hierarchical && $this->rewrite['hierarchical'] ) { 363 $tag = '(.+?)'; 364 } else { 365 $tag = '([^/]+)'; 366 } 367 368 add_rewrite_tag( "%$this->name%", $tag, $this->query_var ? "{$this->query_var}=" : "taxonomy=$this->name&term=" ); 369 add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $this->rewrite ); 370 } 371 } 372 373 /** 374 * Removes any rewrite rules, permastructs, and rules for the taxonomy. 375 * 376 * @since 4.6.0 377 * @access public 378 * 379 * @global WP $wp Current WordPress environment instance. 380 */ 381 public function remove_rewrite_rules() { 382 /* @var WP $wp */ 383 global $wp; 384 385 // Remove query var. 386 if ( false !== $this->query_var ) { 387 $wp->remove_query_var( $this->query_var ); 388 } 389 390 // Remove rewrite tags and permastructs. 391 if ( false !== $this->rewrite ) { 392 remove_rewrite_tag( "%$this->name%" ); 393 remove_permastruct( $this->name ); 394 } 395 } 396 397 /** 398 * Registers the ajax callback for the metabox. 399 * 400 * @since 4.6.0 401 * @access public 402 */ 403 public function add_hooks() { 404 add_filter( 'wp_ajax_add-' . $this->name, '_wp_ajax_add_hierarchical_term' ); 405 } 406 407 /** 408 * Removes the ajax callback for the metabox. 409 * 410 * @since 4.6.0 411 * @access public 412 */ 413 public function remove_hooks() { 414 remove_filter( 'wp_ajax_add-' . $this->name, '_wp_ajax_add_hierarchical_term' ); 415 } 416 } -
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 bdabf98..d0f27e3 100644
class wp_xmlrpc_server extends IXR_Server { 708 708 * 709 709 * @since 3.4.0 710 710 * 711 * @param array $_taxonomy An array of taxonomy data.712 * @param object$taxonomy Taxonomy object.713 * @param array $fields The subset of taxonomy fields to return.711 * @param array $_taxonomy An array of taxonomy data. 712 * @param WP_Taxonomy $taxonomy Taxonomy object. 713 * @param array $fields The subset of taxonomy fields to return. 714 714 */ 715 715 return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); 716 716 } -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index a51658f..8edd684 100644
function get_object_taxonomies( $object, $output = 'names' ) { 211 211 * @global array $wp_taxonomies The registered taxonomies. 212 212 * 213 213 * @param string $taxonomy Name of taxonomy object to return. 214 * @return object|false The Taxonomy Object or false if $taxonomy doesn't exist.214 * @return WP_Taxonomy|false The Taxonomy Object or false if $taxonomy doesn't exist. 215 215 */ 216 216 function get_taxonomy( $taxonomy ) { 217 217 global $wp_taxonomies; … … function is_taxonomy_hierarchical($taxonomy) { 278 278 * @since 4.5.0 Introduced `publicly_queryable` argument. 279 279 * 280 280 * @global array $wp_taxonomies Registered taxonomies. 281 * @global WP $wp WP instance.282 281 * 283 282 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 284 283 * @param array|string $object_type Name of the object type for the taxonomy object. … … function is_taxonomy_hierarchical($taxonomy) { 349 348 * @return WP_Error|void WP_Error, if errors. 350 349 */ 351 350 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 352 global $wp_taxonomies , $wp;351 global $wp_taxonomies; 353 352 354 if ( ! is_array( $wp_taxonomies ) ) 353 if ( ! is_array( $wp_taxonomies ) ) { 355 354 $wp_taxonomies = array(); 356 357 $args = wp_parse_args( $args ); 358 359 /** 360 * Filters 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 ); 355 } 390 356 391 357 if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) { 392 358 _doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2' ); 393 359 return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) ); 394 360 } 395 361 396 // If not set, default to the setting for public. 397 if ( null === $args['publicly_queryable'] ) { 398 $args['publicly_queryable'] = $args['public']; 399 } 400 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 ) ); 362 $taxonomy_object = new WP_Taxonomy( $taxonomy, $object_type, $args ); 363 $taxonomy_object->add_rewrite_rules(); 419 364 420 if ( empty( $args['rewrite']['slug'] ) ) 421 $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy ); 365 $wp_taxonomies[ $taxonomy ] = $taxonomy_object; 422 366 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']; 447 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 479 add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' ); 367 $taxonomy_object->add_hooks(); 480 368 481 369 /** 482 370 * Fires after a taxonomy is registered. … … function unregister_taxonomy( $taxonomy ) { 508 396 return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); 509 397 } 510 398 511 $taxonomy_ args= get_taxonomy( $taxonomy );399 $taxonomy_object = get_taxonomy( $taxonomy ); 512 400 513 401 // Do not allow unregistering internal taxonomies. 514 if ( $taxonomy_ args->_builtin ) {402 if ( $taxonomy_object->_builtin ) { 515 403 return new WP_Error( 'invalid_taxonomy', __( 'Unregistering a built-in taxonomy is not allowed' ) ); 516 404 } 517 405 518 global $wp, $wp_taxonomies; 406 $taxonomy_object->remove_rewrite_rules(); 407 $taxonomy_object->remove_hooks(); 519 408 520 // Remove query var. 521 if ( false !== $taxonomy_args->query_var ) { 522 $wp->remove_query_var( $taxonomy_args->query_var ); 523 } 524 525 // Remove rewrite tags and permastructs. 526 if ( false !== $taxonomy_args->rewrite ) { 527 remove_rewrite_tag( "%$taxonomy%" ); 528 remove_permastruct( $taxonomy ); 529 } 530 531 // Unregister callback handling for metabox. 532 remove_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' ); 409 global $wp_taxonomies; 533 410 534 411 // Remove the taxonomy. 535 412 unset( $wp_taxonomies[ $taxonomy ] ); … … function unregister_taxonomy( $taxonomy ) { 579 456 * @since 4.3.0 Added the `no_terms` label. 580 457 * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels. 581 458 * 582 * @param object$tax Taxonomy object.459 * @param WP_Taxonomy $tax Taxonomy object. 583 460 * @return object object with all the labels as member variables. 584 461 */ 585 462 function get_taxonomy_labels( $tax ) { -
src/wp-settings.php
diff --git src/wp-settings.php src/wp-settings.php index ae7a173..ce59856 100644
require( ABSPATH . WPINC . '/cron.php' ); 181 181 require( ABSPATH . WPINC . '/deprecated.php' ); 182 182 require( ABSPATH . WPINC . '/script-loader.php' ); 183 183 require( ABSPATH . WPINC . '/taxonomy.php' ); 184 require( ABSPATH . WPINC . '/class-wp-taxonomy.php' ); 184 185 require( ABSPATH . WPINC . '/class-wp-term.php' ); 185 186 require( ABSPATH . WPINC . '/class-wp-term-query.php' ); 186 187 require( ABSPATH . WPINC . '/class-wp-tax-query.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..377808c
- + 1 <?php 2 3 /** 4 * @group taxonomy 5 */ 6 class Tests_WP_Taxonomy extends WP_UnitTestCase { 7 public function test_instances() { 8 global $wp_taxonomies; 9 10 foreach ( $wp_taxonomies as $taxonomy ) { 11 $this->assertInstanceOf( 'WP_Taxonomy', $taxonomy ); 12 } 13 } 14 15 public function test_does_not_add_query_var_if_not_public() { 16 $this->set_permalink_structure( '/%postname%' ); 17 18 /* @var WP $wp */ 19 global $wp; 20 21 $taxonomy = rand_str(); 22 $taxonomy_object = new WP_Taxonomy( $taxonomy, 'post' ); 23 24 $taxonomy_object->add_rewrite_rules(); 25 $this->assertFalse( in_array( 'foobar', $wp->public_query_vars ) ); 26 } 27 28 public function test_adds_query_var_if_public() { 29 $this->set_permalink_structure( '/%postname%' ); 30 31 /* @var WP $wp */ 32 global $wp; 33 34 $taxonomy = rand_str(); 35 $taxonomy_object = new WP_Taxonomy( $taxonomy, 'post', array( 36 'public' => true, 37 'rewrite' => false, 38 'query_var' => 'foobar', 39 ) ); 40 41 $taxonomy_object->add_rewrite_rules(); 42 $in_array = in_array( 'foobar', $wp->public_query_vars ); 43 44 $taxonomy_object->remove_rewrite_rules(); 45 $in_array_after = in_array( 'foobar', $wp->public_query_vars ); 46 47 $this->assertTrue( $in_array ); 48 $this->assertFalse( $in_array_after ); 49 } 50 51 public function test_adds_rewrite_rules() { 52 $this->set_permalink_structure( '/%postname%' ); 53 54 /* @var WP_Rewrite $wp_rewrite */ 55 global $wp_rewrite; 56 57 $taxonomy = rand_str(); 58 $taxonomy_object = new WP_Taxonomy( $taxonomy, 'post', array( 59 'public' => true, 60 'rewrite' => true, 61 ) ); 62 63 $taxonomy_object->add_rewrite_rules(); 64 $rewrite_tags = $wp_rewrite->rewritecode; 65 66 $taxonomy_object->remove_rewrite_rules(); 67 $rewrite_tags_after = $wp_rewrite->rewritecode; 68 69 $this->assertTrue( false !== array_search( "%$taxonomy%", $rewrite_tags ) ); 70 $this->assertFalse( array_search( "%$taxonomy%", $rewrite_tags_after ) ); 71 } 72 73 public function test_adds_ajax_callback() { 74 $taxonomy = rand_str(); 75 $taxonomy_object = new WP_Taxonomy( $taxonomy, 'post', array( 76 'public' => true, 77 'rewrite' => true, 78 ) ); 79 80 $taxonomy_object->add_hooks(); 81 $has_action = has_action( "wp_ajax_add-$taxonomy", '_wp_ajax_add_hierarchical_term' ); 82 83 $taxonomy_object->remove_hooks(); 84 $has_action_after = has_action( "wp_ajax_add-$taxonomy", '_wp_ajax_add_hierarchical_term' ); 85 86 $this->assertSame( 10, $has_action ); 87 $this->assertFalse( $has_action_after ); 88 89 } 90 }