WordPress.org

Make WordPress Core

Ticket #36224: 36224.2.diff

File 36224.2.diff, 21.5 KB (added by swissspidy, 5 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() { 
    136136         *
    137137         * @since 4.0.0
    138138         *
    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.
    142142         */
    143143        $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
    144144
  • 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..45f9f6e
    - +  
     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 */
     15final 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         * 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        {
     209         *                                  Optional. Array or query string of arguments for registering a taxonomy.
     210         */
     211        public function __construct( $taxonomy, $object_type, $args ) {
     212                global $wp;
     213
     214                $args = wp_parse_args( $args );
     215
     216                /**
     217                 * Filter the arguments for registering a taxonomy.
     218                 *
     219                 * @since 4.4.0
     220                 *
     221                 * @param array  $args        Array of arguments for registering a taxonomy.
     222                 * @param string $taxonomy    Taxonomy key.
     223                 * @param array  $object_type Array of names of object types for the taxonomy.
     224                 */
     225                $args = apply_filters( 'register_taxonomy_args', $args, $taxonomy, (array) $object_type );
     226
     227                $defaults = array(
     228                        'labels'                => array(),
     229                        'description'           => '',
     230                        'public'                => true,
     231                        'publicly_queryable'    => null,
     232                        'hierarchical'          => false,
     233                        'show_ui'               => null,
     234                        'show_in_menu'          => null,
     235                        'show_in_nav_menus'     => null,
     236                        'show_tagcloud'         => null,
     237                        'show_in_quick_edit'    => null,
     238                        'show_admin_column'     => false,
     239                        'meta_box_cb'           => null,
     240                        'capabilities'          => array(),
     241                        'rewrite'               => true,
     242                        'query_var'             => $taxonomy,
     243                        'update_count_callback' => '',
     244                        '_builtin'              => false,
     245                );
     246                $args = array_merge( $defaults, $args );
     247
     248                // If not set, default to the setting for public.
     249                if ( null === $args['publicly_queryable'] ) {
     250                        $args['publicly_queryable'] = $args['public'];
     251                }
     252
     253                // Non-publicly queryable taxonomies should not register query vars, except in the admin.
     254                if ( false !== $args['query_var'] && ( is_admin() || false !== $args['publicly_queryable'] ) && ! empty( $wp ) ) {
     255                        if ( true === $args['query_var'] ) {
     256                                $args['query_var'] = $taxonomy;
     257                        } else {
     258                                $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
     259                        }
     260                        $wp->add_query_var( $args['query_var'] );
     261                } else {
     262                        // Force query_var to false for non-public taxonomies.
     263                        $args['query_var'] = false;
     264                }
     265
     266                if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
     267                        $args['rewrite'] = wp_parse_args( $args['rewrite'], array(
     268                                'with_front'   => true,
     269                                'hierarchical' => false,
     270                                'ep_mask'      => EP_NONE,
     271                        ) );
     272
     273                        if ( empty( $args['rewrite']['slug'] ) ) {
     274                                $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy );
     275                        }
     276
     277                        if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) {
     278                                $tag = '(.+?)';
     279                        } else {
     280                                $tag = '([^/]+)';
     281                        }
     282
     283                        add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" );
     284                        add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] );
     285                }
     286
     287                // If not set, default to the setting for public.
     288                if ( null === $args['show_ui'] ) {
     289                        $args['show_ui'] = $args['public'];
     290                }
     291
     292                // If not set, default to the setting for show_ui.
     293                if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) {
     294                        $args['show_in_menu'] = $args['show_ui'];
     295                }
     296
     297                // If not set, default to the setting for public.
     298                if ( null === $args['show_in_nav_menus'] ) {
     299                        $args['show_in_nav_menus'] = $args['public'];
     300                }
     301
     302                // If not set, default to the setting for show_ui.
     303                if ( null === $args['show_tagcloud'] ) {
     304                        $args['show_tagcloud'] = $args['show_ui'];
     305                }
     306
     307                // If not set, default to the setting for show_ui.
     308                if ( null === $args['show_in_quick_edit'] ) {
     309                        $args['show_in_quick_edit'] = $args['show_ui'];
     310                }
     311
     312                $default_caps = array(
     313                        'manage_terms' => 'manage_categories',
     314                        'edit_terms'   => 'manage_categories',
     315                        'delete_terms' => 'manage_categories',
     316                        'assign_terms' => 'edit_posts',
     317                );
     318                $args['cap']  = (object) array_merge( $default_caps, $args['capabilities'] );
     319                unset( $args['capabilities'] );
     320
     321                $args['name']        = $taxonomy;
     322                $args['object_type'] = array_unique( (array) $object_type );
     323
     324                $args['labels'] = get_taxonomy_labels( (object) $args );
     325                $args['label']  = $args['labels']->name;
     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 $key => $value ) {
     337                        $this->$key = $value;
     338                }
     339        }
     340
     341        /**
     342         * Retrieves the taxonomy object of `$taxonomy`.
     343         *
     344         * @since 4.6.0
     345         * @access public
     346         * @static
     347         *
     348         * @global array $wp_taxonomies The registered taxonomies.
     349         *
     350         * @param string $taxonomy Name of taxonomy object to return.
     351         * @return WP_Taxonomy|false The Taxonomy object or false if taxonomy does not exist.
     352         */
     353        public static function get_instance( $taxonomy ) {
     354                global $wp_taxonomies;
     355
     356                if ( ! taxonomy_exists( $taxonomy ) )
     357                        return false;
     358
     359                return $wp_taxonomies[$taxonomy];
     360        }
     361
     362        /**
     363         * Method to implement ArrayAccess for taxonomy arguments.
     364         *
     365         * @since 4.6.0
     366         * @access public
     367         *
     368         * @param mixed $offset
     369         * @param mixed $value
     370         */
     371        public function offsetSet( $offset, $value ) {
     372                if ( $this->offsetExists( $offset ) ) {
     373                        $this->$offset = $value;
     374                }
     375        }
     376
     377        /**
     378         * Method to implement ArrayAccess for taxonomy arguments.
     379         *
     380         * @since 4.6.0
     381         * @access public
     382         *
     383         * @param mixed $offset
     384         */
     385        public function offsetUnset( $offset ) {
     386                if ( $this->offsetExists( $offset ) ) {
     387                        unset( $this->$offset );
     388                }
     389        }
     390
     391        /**
     392         * Method to implement ArrayAccess for taxonomy arguments.
     393         *
     394         * @since 4.6.0
     395         * @access public
     396         *
     397         * @param mixed $offset
     398         * @return bool
     399         */
     400        public function offsetExists( $offset ) {
     401                return property_exists( $this, $offset );
     402        }
     403
     404        /**
     405         * Method to implement ArrayAccess for taxonomy arguments.
     406         *
     407         * @since 4.6.0
     408         * @access public
     409         *
     410         * @param mixed $offset
     411         * @return mixed
     412         */
     413        public function offsetGet( $offset ) {
     414                if ( $this->offsetExists( $offset ) ) {
     415                        return $this->$offset;
     416                }
     417        }
     418}
  • 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 { 
    695695                 *
    696696                 * @since 3.4.0
    697697                 *
    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.
    701701                 */
    702702                return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields );
    703703        }
  • src/wp-includes/link-template.php

    diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php
    index 11c4e40..c6a24f9 100644
    function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) { 
    922922        }
    923923
    924924        $tax = get_taxonomy( $term->taxonomy );
     925        var_dump($term->taxonomy,$tax->cap,current_user_can( $tax->cap->edit_terms ) );
    925926        if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) {
    926927                return;
    927928        }
  • 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' ) 
    162162 * Example:
    163163 *
    164164 *     $taxonomies = get_object_taxonomies( 'post' );
    165  * 
     165 *
    166166 * This results in:
    167  * 
     167 *
    168168 *     Array( 'category', 'post_tag' )
    169169 *
    170170 * @since 2.3.0
    function get_object_taxonomies( $object, $output = 'names' ) { 
    208208 *
    209209 * @since 2.3.0
    210210 *
    211  * @global array $wp_taxonomies The registered taxonomies.
    212  *
    213211 * @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.
    215213 */
    216214function 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 );
    223216}
    224217
    225218/**
    function is_taxonomy_hierarchical($taxonomy) { 
    276269 * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen.
    277270 * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front end.
    278271 * @since 4.5.0 Introduced `publicly_queryable` argument.
     272 * @since 4.6.0 The function now returns the registered taxonomy object on success.
    279273 *
    280274 * @global array $wp_taxonomies Registered taxonomies.
    281  * @global WP    $wp            WP instance.
    282275 *
    283276 * @param string       $taxonomy    Taxonomy key, must not exceed 32 characters.
    284277 * @param array|string $object_type Name of the object type for the taxonomy object.
    function is_taxonomy_hierarchical($taxonomy) { 
    346339 *     @type bool          $_builtin              This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY!
    347340 *                                                Default false.
    348341 * }
    349  * @return WP_Error|void WP_Error, if errors.
     342 * @return WP_Taxonomy|WP_Error The registered taxonomy object, or an error object.
    350343 */
    351344function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
    352         global $wp_taxonomies, $wp;
     345        global $wp_taxonomies;
    353346
    354         if ( ! is_array( $wp_taxonomies ) )
     347        if ( ! is_array( $wp_taxonomies ) ) {
    355348                $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        }
    390350
    391351        if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) {
    392352                _doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2' );
    393353                return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) );
    394354        }
    395355
    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 );
    400357
    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;
    447359
    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.
    479361        add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' );
    480362
    481363        /**
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    483365         *
    484366         * @since 3.3.0
    485367         *
    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.
    489371         */
    490         do_action( 'registered_taxonomy', $taxonomy, $object_type, $args );
     372        do_action( 'registered_taxonomy', $taxonomy, $object_type, $taxonomy_object );
     373
     374        return $taxonomy_object;
    491375}
    492376
    493377/**
    function unregister_taxonomy( $taxonomy ) { 
    579463 * @since 4.3.0 Added the `no_terms` label.
    580464 * @since 4.4.0 Added the `items_list_navigation` and `items_list` labels.
    581465 *
    582  * @param object $tax Taxonomy object.
     466 * @param object|WP_Taxonomy $tax Custom-something object or WP_Taxonomy object.
    583467 * @return object object with all the labels as member variables.
    584468 */
    585469function 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' ); 
    166166require( ABSPATH . WPINC . '/deprecated.php' );
    167167require( ABSPATH . WPINC . '/script-loader.php' );
    168168require( ABSPATH . WPINC . '/taxonomy.php' );
     169require( ABSPATH . WPINC . '/class-wp-taxonomy.php' );
    169170require( ABSPATH . WPINC . '/class-wp-term.php' );
    170171require( ABSPATH . WPINC . '/class-wp-tax-query.php' );
    171172require( 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 */
     6class 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}