Changeset 25130 for trunk/src/wp-includes/post.php
- Timestamp:
- 08/26/2013 08:23:34 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r25097 r25130 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. … … 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. … … 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 … … 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. … … 1167 1167 * @since 2.9.0 1168 1168 * @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. 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. … … 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; … … 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'));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 ) ) { 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);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' ) ) ) { 1255 1274 if ( ! is_array( $args->rewrite ) ) 1256 1275 $args->rewrite = array(); … … 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 ) { … … 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 );
Note: See TracChangeset
for help on using the changeset viewer.