Make WordPress Core

Ticket #12706: 12706.2.diff

File 12706.2.diff, 3.9 KB (added by kovshenin, 12 years ago)
  • wp-includes/post.php

     
    920920 * @param array|string $args See above description.
    921921 */
    922922function register_post_status($post_status, $args = array()) {
    923         global $wp_post_statuses;
     923        global $wp_post_statuses, $wp_post_types;
    924924
    925925        if (!is_array($wp_post_statuses))
    926926                $wp_post_statuses = array();
     
    980980
    981981        $wp_post_statuses[$post_status] = $args;
    982982
     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
    983989        return $args;
    984990}
    985991
     
    9961002 * @param string $post_status The name of a registered post status
    9971003 * @return object A post status object
    9981004 */
    999 function get_post_status_object( $post_status ) {
     1005function get_post_status_object( $post_status, $object_type = null ) {
    10001006        global $wp_post_statuses;
    10011007
    1002         if ( empty($wp_post_statuses[$post_status]) )
    1003                 return null;
     1008        $status_object = null;
    10041009
    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;
    10061028}
    10071029
    10081030/**
     
    10211043 *  from the array needs to match; 'and' means all elements must match. The default is 'and'.
    10221044 * @return array A list of post status names or objects
    10231045 */
    1024 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
     1046function get_post_stati( $args = array(), $output = 'names', $operator = 'and', $object_type = null ) {
    10251047        global $wp_post_statuses;
    10261048
    10271049        $field = ('names' == $output) ? 'name' : false;
    10281050
    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 );
    10301062}
    10311063
    10321064/**
     
    12111243 * @return object|WP_Error the registered post type object, or an error object
    12121244 */
    12131245function 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;
    12151247
    12161248        if ( !is_array($wp_post_types) )
    12171249                $wp_post_types = array();
     
    12271259                'can_export' => true,
    12281260                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
    12291261                'delete_with_user' => null,
     1262                'statuses' => null,
    12301263        );
    12311264        $args = wp_parse_args($args, $defaults);
    12321265        $args = (object) $args;
     
    13361369        if ( $args->register_meta_box_cb )
    13371370                add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
    13381371
     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
    13391385        $args->labels = get_post_type_labels( $args );
    13401386        $args->label = $args->labels->name;
    13411387