Ticket #25150: 25150.patch
File 25150.patch, 17.4 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
1102 1102 * * Defaults to false. 1103 1103 * * While the default settings of exclude_from_search, publicly_queryable, show_ui, and show_in_nav_menus are 1104 1104 * 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. 1105 1106 * - exclude_from_search - Whether to exclude posts with this post type from front end search results. 1106 1107 * * If not set, the opposite of public's current value is used. 1107 1108 * - publicly_queryable - Whether queries can be performed on the front end for the post type as part of parse_request(). … … 1111 1112 * * If not set, the default is inherited from public. 1112 1113 * - show_ui - Whether to generate a default UI for managing this post type in the admin. 1113 1114 * * 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.1116 1115 * - show_in_menu - Where to show the post type in the admin menu. 1117 1116 * * If true, the post type is shown in its own top level menu. 1118 1117 * * If false, no menu is shown … … 1120 1119 * be placed as a sub menu of that. 1121 1120 * * show_ui must be true. 1122 1121 * * 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. 1123 1124 * - show_in_admin_bar - Makes this post type available via the admin bar. 1124 1125 * * If not set, the default is inherited from show_in_menu 1125 1126 * - menu_position - The position in the menu order the post type should appear. … … 1133 1134 * * By default the capability_type is used as a base to construct capabilities. 1134 1135 * * You can see accepted values in {@link get_post_type_capabilities()}. 1135 1136 * - 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.1137 1137 * - supports - An alias for calling add_post_type_support() directly. Defaults to title and editor. 1138 1138 * * See {@link add_post_type_support()} for documentation. 1139 1139 * - register_meta_box_cb - Provide a callback function that will be called when setting up the … … 1166 1166 * 1167 1167 * @since 2.9.0 1168 1168 * @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 1169 1171 * 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. 1171 1173 * @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. 1173 1175 */ 1174 1176 function register_post_type( $post_type, $args = array() ) { 1175 1177 global $wp_post_types, $wp_rewrite, $wp; 1176 1178 1177 if ( ! is_array($wp_post_types) )1179 if ( ! is_array( $wp_post_types ) ) 1178 1180 $wp_post_types = array(); 1179 1181 1180 1182 // Args prefixed with an underscore are reserved for internal use. 1181 1183 $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', 1191 1209 ); 1192 $args = wp_parse_args( $args, $defaults);1210 $args = wp_parse_args( $args, $defaults ); 1193 1211 $args = (object) $args; 1194 1212 1195 $post_type = sanitize_key( $post_type);1213 $post_type = sanitize_key( $post_type ); 1196 1214 $args->name = $post_type; 1197 1215 1198 1216 if ( strlen( $post_type ) > 20 ) 1199 1217 return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) ); 1200 1218 1201 1219 // If not set, default to the setting for public. 1202 1220 if ( null === $args->publicly_queryable ) … … 1214 1232 if ( null === $args->show_in_admin_bar ) 1215 1233 $args->show_in_admin_bar = true === $args->show_in_menu; 1216 1234 1217 // Whether to show this type in nav-menus.php. Defaultsto the setting for public.1235 // If not set, default to the setting for public. 1218 1236 if ( null === $args->show_in_nav_menus ) 1219 1237 $args->show_in_nav_menus = $args->public; 1220 1238 … … 1226 1244 if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) ) 1227 1245 $args->map_meta_cap = true; 1228 1246 1247 // If not set, default to false. 1229 1248 if ( null === $args->map_meta_cap ) 1230 1249 $args->map_meta_cap = false; 1231 1250 1232 1251 $args->cap = get_post_type_capabilities( $args ); 1233 unset( $args->capabilities);1252 unset( $args->capabilities ); 1234 1253 1235 1254 if ( is_array( $args->capability_type ) ) 1236 1255 $args->capability_type = $args->capability_type[0]; 1237 1256 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 ); 1241 1260 } elseif ( false !== $args->supports ) { 1242 1261 // Add default features 1243 add_post_type_support( $post_type, array('title', 'editor'));1262 add_post_type_support( $post_type, array( 'title', 'editor' ) ); 1244 1263 } 1245 1264 1246 if ( false !== $args->query_var && ! empty($wp) ) {1265 if ( false !== $args->query_var && ! empty( $wp ) ) { 1247 1266 if ( true === $args->query_var ) 1248 1267 $args->query_var = $post_type; 1249 1268 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 ); 1252 1271 } 1253 1272 1254 if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure') ) ) {1273 if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { 1255 1274 if ( ! is_array( $args->rewrite ) ) 1256 1275 $args->rewrite = array(); 1257 1276 if ( empty( $args->rewrite['slug'] ) ) … … 1270 1289 } 1271 1290 1272 1291 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=" ); 1274 1293 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=" ); 1276 1295 1277 1296 if ( $args->has_archive ) { 1278 1297 $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; … … 1297 1316 } 1298 1317 1299 1318 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 ); 1301 1320 1302 1321 $args->labels = get_post_type_labels( $args ); 1303 1322 $args->label = $args->labels->name; 1304 1323 1305 $wp_post_types[ $post_type] = $args;1324 $wp_post_types[ $post_type ] = $args; 1306 1325 1307 1326 add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); 1308 1327 1309 foreach ( $args->taxonomies as $taxonomy ) {1328 foreach ( $args->taxonomies as $taxonomy ) 1310 1329 register_taxonomy_for_object_type( $taxonomy, $post_type ); 1311 }1312 1330 1313 1331 do_action( 'registered_post_type', $post_type, $args ); 1314 1332 -
src/wp-includes/taxonomy.php
270 270 * 271 271 * Optional $args contents: 272 272 * 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! 274 305 * 275 * hierarchical - has some defined purpose at other parts of the API and is a276 * 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 confirms280 * 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 customize284 * permastruct; default will use $taxonomy as slug.285 *286 * query_var - false to prevent queries, or string to customize query var287 * (?$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 WordPress306 * @subpackage Taxonomy307 306 * @since 2.3.0 308 307 * @uses $wp_taxonomies Inserts new taxonomy object into the list 309 308 * @uses $wp Adds query vars 310 309 * 311 * @param string $taxonomy Name of taxonomy object310 * @param string $taxonomy Taxonomy key, must not exceed 32 characters. 312 311 * @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. 314 313 * @return null|WP_Error WP_Error if errors, otherwise null. 315 314 */ 316 315 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 317 316 global $wp_taxonomies, $wp; 318 317 319 if ( ! is_array( $wp_taxonomies) )318 if ( ! is_array( $wp_taxonomies ) ) 320 319 $wp_taxonomies = array(); 321 320 322 321 $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, 324 332 '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, 335 334 ); 336 $args = wp_parse_args( $args, $defaults);335 $args = wp_parse_args( $args, $defaults ); 337 336 338 337 if ( strlen( $taxonomy ) > 32 ) 339 338 return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) ); 340 339 341 if ( false !== $args['query_var'] && ! empty($wp) ) {340 if ( false !== $args['query_var'] && ! empty( $wp ) ) { 342 341 if ( true === $args['query_var'] ) 343 342 $args['query_var'] = $taxonomy; 344 343 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'] ); 347 346 } 348 347 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 ), 352 351 'with_front' => true, 353 352 'hierarchical' => false, 354 353 'ep_mask' => EP_NONE, 355 ) );354 ) ); 356 355 357 356 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) 358 357 $tag = '(.+?)'; … … 363 362 add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); 364 363 } 365 364 366 if ( is_null($args['show_ui']) ) 365 // If not set, default to the setting for public. 366 if ( null === $args['show_ui'] ) 367 367 $args['show_ui'] = $args['public']; 368 368 369 // Whether to show this type in nav-menus.php. Defaultsto the setting for public.369 // If not set, default to the setting for public. 370 370 if ( null === $args['show_in_nav_menus'] ) 371 371 $args['show_in_nav_menus'] = $args['public']; 372 372 373 if ( is_null($args['show_tagcloud']) ) 373 // If not set, default to the setting for show_ui. 374 if ( null === $args['show_tagcloud'] ) 374 375 $args['show_tagcloud'] = $args['show_ui']; 375 376 376 377 $default_caps = array( … … 383 384 unset( $args['capabilities'] ); 384 385 385 386 $args['name'] = $taxonomy; 386 $args['object_type'] = array_unique( (array)$object_type );387 $args['object_type'] = array_unique( (array) $object_type ); 387 388 388 389 $args['labels'] = get_taxonomy_labels( (object) $args ); 389 390 $args['label'] = $args['labels']->name; 390 391 391 $wp_taxonomies[ $taxonomy] = (object) $args;392 $wp_taxonomies[ $taxonomy ] = (object) $args; 392 393 393 394 // 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' ); 395 396 396 397 do_action( 'registered_taxonomy', $taxonomy, $object_type, $args ); 397 398 }