Ticket #12706: 12706.2.diff
File 12706.2.diff, 3.9 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
920 920 * @param array|string $args See above description. 921 921 */ 922 922 function register_post_status($post_status, $args = array()) { 923 global $wp_post_statuses ;923 global $wp_post_statuses, $wp_post_types; 924 924 925 925 if (!is_array($wp_post_statuses)) 926 926 $wp_post_statuses = array(); … … 980 980 981 981 $wp_post_statuses[$post_status] = $args; 982 982 983 // Add status to already registered post types 984 if ( ! empty( $wp_post_types ) ) 985 foreach ( $wp_post_types as $key => $post_type ) 986 if ( ! array_key_exists( $post_status, $post_type->statuses ) ) 987 $wp_post_types[ $key ]->statuses[ $post_status ] = $args; 988 983 989 return $args; 984 990 } 985 991 … … 996 1002 * @param string $post_status The name of a registered post status 997 1003 * @return object A post status object 998 1004 */ 999 function get_post_status_object( $post_status ) {1005 function get_post_status_object( $post_status, $object_type = null ) { 1000 1006 global $wp_post_statuses; 1001 1007 1002 if ( empty($wp_post_statuses[$post_status]) ) 1003 return null; 1008 $status_object = null; 1004 1009 1005 return $wp_post_statuses[$post_status]; 1010 if ( $object_type ) { 1011 $post_type = get_post_type_object( $object_type ); 1012 if ( $post_type && ! empty( $post_type->statuses[ $post_status ] ) ) 1013 $status_object = $post_type->statuses[ $post_status ]; 1014 } 1015 1016 if ( ! empty( $wp_post_statuses[ $post_status ] ) ) 1017 $status = $wp_post_statuses[ $post_status ]; 1018 1019 // Search across all post types 1020 foreach ( get_post_types( array(), 'objects' ) as $post_type ) { 1021 if ( ! empty( $post_type->statuses[ $post_status ] ) ) { 1022 $status_object = $post_type->statuses[ $post_status ]; 1023 break; 1024 } 1025 } 1026 1027 return $status_object; 1006 1028 } 1007 1029 1008 1030 /** … … 1021 1043 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 1022 1044 * @return array A list of post status names or objects 1023 1045 */ 1024 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {1046 function get_post_stati( $args = array(), $output = 'names', $operator = 'and', $object_type = null ) { 1025 1047 global $wp_post_statuses; 1026 1048 1027 1049 $field = ('names' == $output) ? 'name' : false; 1028 1050 1029 return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); 1051 $statuses = $wp_post_statuses; 1052 1053 if ( ! empty( $args['object_type'] ) ) { 1054 $post_type = get_post_type_object( $args['object_type'] ); 1055 if ( $post_type ) 1056 $statuses = $post_type->statuses; 1057 1058 unset( $args['object_type'] ); 1059 } 1060 1061 return wp_filter_object_list( $statuses, $args, $operator, $field ); 1030 1062 } 1031 1063 1032 1064 /** … … 1211 1243 * @return object|WP_Error the registered post type object, or an error object 1212 1244 */ 1213 1245 function register_post_type( $post_type, $args = array() ) { 1214 global $wp_post_types, $wp_rewrite, $wp ;1246 global $wp_post_types, $wp_rewrite, $wp, $wp_post_statuses; 1215 1247 1216 1248 if ( !is_array($wp_post_types) ) 1217 1249 $wp_post_types = array(); … … 1227 1259 'can_export' => true, 1228 1260 'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 1229 1261 'delete_with_user' => null, 1262 'statuses' => null, 1230 1263 ); 1231 1264 $args = wp_parse_args($args, $defaults); 1232 1265 $args = (object) $args; … … 1336 1369 if ( $args->register_meta_box_cb ) 1337 1370 add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); 1338 1371 1372 if ( null === $args->statuses ) 1373 $args->statuses = array(); 1374 1375 // @todo: when combined with register_post_status, sanitize $status similar to how register_post_status does it 1376 foreach ( $args->statuses as $key => $status ) 1377 $args->statuses[ $key ] = (object) $status; 1378 1379 // Legacy post statuses 1380 if ( ! empty( $wp_post_statuses ) ) 1381 foreach ( $wp_post_statuses as $key => $post_status ) 1382 if ( empty( $args->statuses[ $key ] ) ) 1383 $args->statuses[ $key ] = $post_status; 1384 1339 1385 $args->labels = get_post_type_labels( $args ); 1340 1386 $args->label = $args->labels->name; 1341 1387