Make WordPress Core


Ignore:
Timestamp:
08/26/2013 08:23:34 PM (10 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/post.php

    r25097 r25130  
    11031103 *     * While the default settings of exclude_from_search, publicly_queryable, show_ui, and show_in_nav_menus are
    11041104 *       inherited from public, each does not rely on this relationship and controls a very specific intention.
     1105 * - hierarchical - Whether the post type is hierarchical (e.g. page). Defaults to false.
    11051106 * - exclude_from_search - Whether to exclude posts with this post type from front end search results.
    11061107 *     * If not set, the opposite of public's current value is used.
     
    11121113 * - show_ui - Whether to generate a default UI for managing this post type in the admin.
    11131114 *     * If not set, the default is inherited from public.
    1114  * - show_in_nav_menus - Makes this post type available for selection in navigation menus.
    1115  *     * If not set, the default is inherited from public.
    11161115 * - show_in_menu - Where to show the post type in the admin menu.
    11171116 *     * If true, the post type is shown in its own top level menu.
     
    11211120 *     * show_ui must be true.
    11221121 *     * If not set, the default is inherited from show_ui
     1122 * - show_in_nav_menus - Makes this post type available for selection in navigation menus.
     1123 *     * If not set, the default is inherited from public.
    11231124 * - show_in_admin_bar - Makes this post type available via the admin bar.
    11241125 *     * If not set, the default is inherited from show_in_menu
     
    11341135 *     * You can see accepted values in {@link get_post_type_capabilities()}.
    11351136 * - map_meta_cap - Whether to use the internal default meta capability handling. Defaults to false.
    1136  * - hierarchical - Whether the post type is hierarchical (e.g. page). Defaults to false.
    11371137 * - supports - An alias for calling add_post_type_support() directly. Defaults to title and editor.
    11381138 *     * See {@link add_post_type_support()} for documentation.
     
    11671167 * @since 2.9.0
    11681168 * @uses $wp_post_types Inserts new post type object into the list
    1169  *
    1170  * @param string $post_type Post type key, must not exceed 20 characters
     1169 * @uses $wp_rewrite Gets default feeds
     1170 * @uses $wp Adds query vars
     1171 *
     1172 * @param string $post_type Post type key, must not exceed 20 characters.
    11711173 * @param array|string $args See optional args description above.
    1172  * @return object|WP_Error the registered post type object, or an error object
     1174 * @return object|WP_Error the registered post type object, or an error object.
    11731175 */
    11741176function register_post_type( $post_type, $args = array() ) {
    11751177    global $wp_post_types, $wp_rewrite, $wp;
    11761178
    1177     if ( !is_array($wp_post_types) )
     1179    if ( ! is_array( $wp_post_types ) )
    11781180        $wp_post_types = array();
    11791181
    11801182    // Args prefixed with an underscore are reserved for internal use.
    11811183    $defaults = array(
    1182         'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
    1183         'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null,
    1184         '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false,
    1185         'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
    1186         'supports' => array(), 'register_meta_box_cb' => null,
    1187         'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
    1188         'can_export' => true,
    1189         'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
    1190         'delete_with_user' => null,
     1184        'labels'               => array(),
     1185        'description'          => '',
     1186        'public'               => false,
     1187        'hierarchical'         => false,
     1188        'exclude_from_search'  => null,
     1189        'publicly_queryable'   => null,
     1190        'show_ui'              => null,
     1191        'show_in_menu'         => null,
     1192        'show_in_nav_menus'    => null,
     1193        'show_in_admin_bar'    => null,
     1194        'menu_position'        => null,
     1195        'menu_icon'            => null,
     1196        'capability_type'      => 'post',
     1197        'capabilities'         => array(),
     1198        'map_meta_cap'         => null,
     1199        'supports'             => array(),
     1200        'register_meta_box_cb' => null,
     1201        'taxonomies'           => array(),
     1202        'has_archive'          => false,
     1203        'rewrite'              => true,
     1204        'query_var'            => true,
     1205        'can_export'           => true,
     1206        'delete_with_user'     => null,
     1207        '_builtin'             => false,
     1208        '_edit_link'           => 'post.php?post=%d',
    11911209    );
    1192     $args = wp_parse_args($args, $defaults);
     1210    $args = wp_parse_args( $args, $defaults );
    11931211    $args = (object) $args;
    11941212
    1195     $post_type = sanitize_key($post_type);
     1213    $post_type = sanitize_key( $post_type );
    11961214    $args->name = $post_type;
    11971215
    11981216    if ( strlen( $post_type ) > 20 )
    1199             return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) );
     1217        return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) );
    12001218
    12011219    // If not set, default to the setting for public.
     
    12151233        $args->show_in_admin_bar = true === $args->show_in_menu;
    12161234
    1217     // Whether to show this type in nav-menus.php. Defaults to the setting for public.
     1235    // If not set, default to the setting for public.
    12181236    if ( null === $args->show_in_nav_menus )
    12191237        $args->show_in_nav_menus = $args->public;
     
    12271245        $args->map_meta_cap = true;
    12281246
     1247    // If not set, default to false.
    12291248    if ( null === $args->map_meta_cap )
    12301249        $args->map_meta_cap = false;
    12311250
    12321251    $args->cap = get_post_type_capabilities( $args );
    1233     unset($args->capabilities);
     1252    unset( $args->capabilities );
    12341253
    12351254    if ( is_array( $args->capability_type ) )
    12361255        $args->capability_type = $args->capability_type[0];
    12371256
    1238     if ( ! empty($args->supports) ) {
    1239         add_post_type_support($post_type, $args->supports);
    1240         unset($args->supports);
     1257    if ( ! empty( $args->supports ) ) {
     1258        add_post_type_support( $post_type, $args->supports );
     1259        unset( $args->supports );
    12411260    } elseif ( false !== $args->supports ) {
    12421261        // Add default features
    1243         add_post_type_support($post_type, array('title', 'editor'));
    1244     }
    1245 
    1246     if ( false !== $args->query_var && !empty($wp) ) {
     1262        add_post_type_support( $post_type, array( 'title', 'editor' ) );
     1263    }
     1264
     1265    if ( false !== $args->query_var && ! empty( $wp ) ) {
    12471266        if ( true === $args->query_var )
    12481267            $args->query_var = $post_type;
    12491268        else
    1250             $args->query_var = sanitize_title_with_dashes($args->query_var);
    1251         $wp->add_query_var($args->query_var);
    1252     }
    1253 
    1254     if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) {
     1269            $args->query_var = sanitize_title_with_dashes( $args->query_var );
     1270        $wp->add_query_var( $args->query_var );
     1271    }
     1272
     1273    if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
    12551274        if ( ! is_array( $args->rewrite ) )
    12561275            $args->rewrite = array();
     
    12711290
    12721291        if ( $args->hierarchical )
    1273             add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
     1292            add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" );
    12741293        else
    1275             add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
     1294            add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" );
    12761295
    12771296        if ( $args->has_archive ) {
     
    12981317
    12991318    if ( $args->register_meta_box_cb )
    1300         add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
     1319        add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 );
    13011320
    13021321    $args->labels = get_post_type_labels( $args );
    13031322    $args->label = $args->labels->name;
    13041323
    1305     $wp_post_types[$post_type] = $args;
     1324    $wp_post_types[ $post_type ] = $args;
    13061325
    13071326    add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 );
Note: See TracChangeset for help on using the changeset viewer.