Make WordPress Core

Ticket #25150: 25150.patch

File 25150.patch, 17.4 KB (added by ocean90, 8 years ago)
  • src/wp-includes/post.php

     
    11021102 *     * Defaults to false.
    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.
    11071108 * - publicly_queryable - Whether queries can be performed on the front end for the post type as part of parse_request().
     
    11111112 *     * If not set, the default is inherited from public.
    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.
    11181117 *     * If false, no menu is shown
     
    11201119 *       be placed as a sub menu of that.
    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
    11251126 * - menu_position - The position in the menu order the post type should appear.
     
    11331134 *     * By default the capability_type is used as a base to construct capabilities.
    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.
    11391139 * - register_meta_box_cb - Provide a callback function that will be called when setting up the
     
    11661166 *
    11671167 * @since 2.9.0
    11681168 * @uses $wp_post_types Inserts new post type object into the list
     1169 * @uses $wp_rewrite Gets default feeds
     1170 * @uses $wp Adds query vars
    11691171 *
    1170  * @param string $post_type Post type key, must not exceed 20 characters
     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.
    12021220        if ( null === $args->publicly_queryable )
     
    12141232        if ( null === $args->show_in_admin_bar )
    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;
    12201238
     
    12261244        if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) )
    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'));
     1262                add_post_type_support( $post_type, array( 'title', 'editor' ) );
    12441263        }
    12451264
    1246         if ( false !== $args->query_var && !empty($wp) ) {
     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);
     1269                        $args->query_var = sanitize_title_with_dashes( $args->query_var );
     1270                $wp->add_query_var( $args->query_var );
    12521271        }
    12531272
    1254         if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) {
     1273        if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {
    12551274                if ( ! is_array( $args->rewrite ) )
    12561275                        $args->rewrite = array();
    12571276                if ( empty( $args->rewrite['slug'] ) )
     
    12701289                }
    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 ) {
    12781297                        $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
     
    12971316        }
    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 );
    13081327
    1309         foreach ( $args->taxonomies as $taxonomy ) {
     1328        foreach ( $args->taxonomies as $taxonomy )
    13101329                register_taxonomy_for_object_type( $taxonomy, $post_type );
    1311         }
    13121330
    13131331        do_action( 'registered_post_type', $post_type, $args );
    13141332
  • src/wp-includes/taxonomy.php

     
    270270 *
    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.
     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!
    274305 *
    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
    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 */
    316315function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
    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']);
     344                        $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
     345                $wp->add_query_var( $args['query_var'] );
    347346        }
    348347
    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),
     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'] )
    358357                        $tag = '(.+?)';
     
    363362                add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] );
    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
    376377        $default_caps = array(
     
    383384        unset( $args['capabilities'] );
    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 );
    397398}