Make WordPress Core

Ticket #36492: 36492.diff

File 36492.diff, 3.4 KB (added by flixos90, 7 years ago)

initial patch implementing WP_Post_Status

  • src/wp-includes/post.php

     
    670670 *                                                  e.g. All (12) | Published (9) | My Custom Status (2)
    671671 *                                                  Default is value of $internal.
    672672 * }
    673  * @return object
     673 * @return WP_Post_Status the new post status object
    674674 */
    675675function register_post_status( $post_status, $args = array() ) {
    676676        global $wp_post_statuses;
     
    678678        if (!is_array($wp_post_statuses))
    679679                $wp_post_statuses = array();
    680680
    681         // Args prefixed with an underscore are reserved for internal use.
    682         $defaults = array(
    683                 'label' => false,
    684                 'label_count' => false,
    685                 'exclude_from_search' => null,
    686                 '_builtin' => false,
    687                 'public' => null,
    688                 'internal' => null,
    689                 'protected' => null,
    690                 'private' => null,
    691                 'publicly_queryable' => null,
    692                 'show_in_admin_status_list' => null,
    693                 'show_in_admin_all_list' => null,
    694         );
    695         $args = wp_parse_args($args, $defaults);
    696         $args = (object) $args;
     681        $post_status_object = new WP_Post_Status( $post_status, $args );
    697682
    698         $post_status = sanitize_key($post_status);
    699         $args->name = $post_status;
     683        $wp_post_statuses[ $post_status ] = $post_status_object;
    700684
    701         // Set various defaults.
    702         if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )
    703                 $args->internal = true;
    704 
    705         if ( null === $args->public  )
    706                 $args->public = false;
    707 
    708         if ( null === $args->private  )
    709                 $args->private = false;
    710 
    711         if ( null === $args->protected  )
    712                 $args->protected = false;
    713 
    714         if ( null === $args->internal  )
    715                 $args->internal = false;
    716 
    717         if ( null === $args->publicly_queryable )
    718                 $args->publicly_queryable = $args->public;
    719 
    720         if ( null === $args->exclude_from_search )
    721                 $args->exclude_from_search = $args->internal;
    722 
    723         if ( null === $args->show_in_admin_all_list )
    724                 $args->show_in_admin_all_list = !$args->internal;
    725 
    726         if ( null === $args->show_in_admin_status_list )
    727                 $args->show_in_admin_status_list = !$args->internal;
    728 
    729         if ( false === $args->label )
    730                 $args->label = $post_status;
    731 
    732         if ( false === $args->label_count )
    733                 $args->label_count = array( $args->label, $args->label );
    734 
    735         $wp_post_statuses[$post_status] = $args;
    736 
    737         return $args;
     685        return $post_status_object;
    738686}
    739687
    740688/**
     
    747695 * @see register_post_status()
    748696 *
    749697 * @param string $post_status The name of a registered post status.
    750  * @return object|null A post status object.
     698 * @return WP_Post_Status|null A post status object.
    751699 */
    752700function get_post_status_object( $post_status ) {
    753         global $wp_post_statuses;
    754 
    755         if ( empty($wp_post_statuses[$post_status]) )
    756                 return null;
    757 
    758         return $wp_post_statuses[$post_status];
     701        return WP_Post_Status::get_instance( $post_status );
    759702}
    760703
    761704/**
  • src/wp-settings.php

     
    142142require( ABSPATH . WPINC . '/post.php' );
    143143require( ABSPATH . WPINC . '/class-walker-page.php' );
    144144require( ABSPATH . WPINC . '/class-walker-page-dropdown.php' );
     145require( ABSPATH . WPINC . '/class-wp-post-status.php' );
    145146require( ABSPATH . WPINC . '/class-wp-post.php' );
    146147require( ABSPATH . WPINC . '/post-template.php' );
    147148require( ABSPATH . WPINC . '/revision.php' );