Make WordPress Core


Ignore:
Timestamp:
08/26/2013 08:23:34 PM (12 years ago)
Author:
ocean90
Message:

Improve inline docs for register_post_type() and register_taxonomy().

  • register_taxonomy: Use the same doc format for the associative array arg as used for register_post_type()
  • register_taxonomy: Improve docs for _builtin, capabilities, hierarchical and rewrite args
  • register_taxonomy: Use the same order in $defaults as in docblock
  • register_taxonomy: Replace is_null with null ===, to be consistent
  • register_post_type: Use the same order in $defaults as in docblock
  • register_post_type: Improve docs for @uses and default fallbacks

And while we're on it: Whitespaces.

fixes #25150.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r25108 r25130  
    271271 * Optional $args contents:
    272272 *
    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 *
    307306 * @since 2.3.0
    308307 * @uses $wp_taxonomies Inserts new taxonomy object into the list
    309308 * @uses $wp Adds query vars
    310309 *
    311  * @param string $taxonomy Name of taxonomy object
     310 * @param string $taxonomy Taxonomy key, must not exceed 32 characters.
    312311 * @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.
    314313 * @return null|WP_Error WP_Error if errors, otherwise null.
    315314 */
     
    317316    global $wp_taxonomies, $wp;
    318317
    319     if ( ! is_array($wp_taxonomies) )
     318    if ( ! is_array( $wp_taxonomies ) )
    320319        $wp_taxonomies = array();
    321320
    322321    $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,
    324332        '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,
    335334    );
    336     $args = wp_parse_args($args, $defaults);
     335    $args = wp_parse_args( $args, $defaults );
    337336
    338337    if ( strlen( $taxonomy ) > 32 )
    339338        return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) );
    340339
    341     if ( false !== $args['query_var'] && !empty($wp) ) {
     340    if ( false !== $args['query_var'] && ! empty( $wp ) ) {
    342341        if ( true === $args['query_var'] )
    343342            $args['query_var'] = $taxonomy;
    344343        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 ),
    352351            'with_front' => true,
    353352            'hierarchical' => false,
    354353            'ep_mask' => EP_NONE,
    355         ));
     354        ) );
    356355
    357356        if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] )
     
    364363    }
    365364
    366     if ( is_null($args['show_ui']) )
     365    // If not set, default to the setting for public.
     366    if ( null === $args['show_ui'] )
    367367        $args['show_ui'] = $args['public'];
    368368
    369     // Whether to show this type in nav-menus.php. Defaults to the setting for public.
     369    // If not set, default to the setting for public.
    370370    if ( null === $args['show_in_nav_menus'] )
    371371        $args['show_in_nav_menus'] = $args['public'];
    372372
    373     if ( is_null($args['show_tagcloud']) )
     373    // If not set, default to the setting for show_ui.
     374    if ( null === $args['show_tagcloud'] )
    374375        $args['show_tagcloud'] = $args['show_ui'];
    375376
     
    384385
    385386    $args['name'] = $taxonomy;
    386     $args['object_type'] =  array_unique( (array)$object_type );
     387    $args['object_type'] = array_unique( (array) $object_type );
    387388
    388389    $args['labels'] = get_taxonomy_labels( (object) $args );
    389390    $args['label'] = $args['labels']->name;
    390391
    391     $wp_taxonomies[$taxonomy] = (object) $args;
     392    $wp_taxonomies[ $taxonomy ] = (object) $args;
    392393
    393394    // 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' );
    395396
    396397    do_action( 'registered_taxonomy', $taxonomy, $object_type, $args );
Note: See TracChangeset for help on using the changeset viewer.