WordPress.org

Make WordPress Core

Ticket #12567: poststatus.diff

File poststatus.diff, 16.0 KB (added by johnkolbert, 3 years ago)

Second version DIFF file

  • wp-includes/post.php

     
    1515 * Creates the initial post types when 'init' action is fired. 
    1616 */ 
    1717function create_initial_post_types() { 
     18 
    1819        register_post_type( 'post', array(      'label' => __('Posts'), 
    1920                                                                                'singular_label' => __('Post'), 
    2021                                                                                'public' => true, 
     
    7374                                                                                                'rewrite' => false, 
    7475                                                                                                'query_var' => false, 
    7576                                                                                        ) ); 
    76  
     77                                                                                                                                                                         
    7778        register_post_status( 'publish', array( 'label' => _x('Published', 'post'), 
    7879                                                                                        'public' => true, 
    7980                                                                                        '_builtin' => true, /* internal use only. */ 
     
    8990        register_post_status( 'draft', array(   'label' => _x('Draft', 'post'), 
    9091                                                                                        'protected' => true, 
    9192                                                                                        '_builtin' => true, /* internal use only. */ 
    92                                                                                         'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>') 
     93                                                                                        'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>'), 
     94                                                                                        'show_in_select_ui' => true 
    9395                                                                                ) ); 
    9496 
    9597        register_post_status( 'pending', array( 'label' => _x('Pending', 'post'), 
    9698                                                                                        'protected' => true, 
    9799                                                                                        '_builtin' => true, /* internal use only. */ 
    98                                                                                         'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>') 
     100                                                                                        'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>'), 
     101                                                                                        'show_in_select_ui' => true, 
     102                                                                                        'display_label' => 'Pending Review' 
    99103                                                                                ) ); 
    100104 
    101105        register_post_status( 'private', array( 'label' => _x('Private', 'post'), 
     
    114118        register_post_status( 'auto-draft', array(      'label' => 'auto-draft', 
    115119                                                                                        'internal' => true, 
    116120                                                                                        '_builtin' => true, /* internal use only. */ 
     121                                                                                        'display_label' => 'Draft' 
    117122                                                                                ) ); 
    118123 
    119124        register_post_status( 'inherit', array( 'label' => 'inherit', 
     
    521526        return $status; 
    522527} 
    523528 
     529function post_type_can_have_status($post_type, $status){ 
     530        global $wp_post_statuses; 
     531         
     532        $post_type_object = get_post_type_object($post_type); 
     533         
     534        if( $status == 'draft') : 
     535                $return = true; 
     536        elseif( is_array($post_type_object->allowed_status) ) : 
     537                if( in_array($status, $post_type_object->allowed_status) )  
     538                        $return = true; 
     539                else 
     540                        $return = false; 
     541        else :   
     542                $status_obj = $wp_post_statuses[$status]; 
     543                 
     544                if( empty($status_obj) ) 
     545                        $return = false; 
     546                elseif( is_array($status_obj->post_type) ){ 
     547                        if( in_array($post_type, $status_obj->post_type) ) 
     548                                $return = true; 
     549                        else 
     550                                $return = false; 
     551                }elseif( $status_obj->internal === true ) 
     552                        $return = false; 
     553                else 
     554                        $return = true; 
     555         
     556        endif; 
     557         
     558        return $return; 
     559} 
     560 
     561         
     562 
     563 
     564 
    524565/** 
    525566 * Register a post type. Do not use before init. 
    526567 * 
     
    550591                $wp_post_statuses = array(); 
    551592 
    552593        // Args prefixed with an underscore are reserved for internal use. 
    553         $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'show_in_admin_all' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, 'single_view_cap' => null); 
     594        $defaults = array('post_type' => false, 'edit_cap' => null, 'show_in_select_ui' => false, 'display_label' => false, 'label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'show_in_admin_all' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, 'single_view_cap' => null); 
    554595        $args = wp_parse_args($args, $defaults); 
    555596        $args = (object) $args; 
    556597 
    557598        $post_status = sanitize_user($post_status, true); 
    558599        $args->name = $post_status; 
    559600 
     601        if ( null === $args->post_type ) 
     602                $args->post_type = false;  
     603         
     604        if ( null === $args->edit_cap ) 
     605                $args->edit_cap = null; 
     606         
     607        if ( null === $args->show_in_select_ui ) 
     608                $args->show_in_select_ui = false; 
     609 
    560610        if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) 
    561611                $args->internal = true; 
    562612 
     
    589639 
    590640        if ( false === $args->label ) 
    591641                $args->label = $post_status; 
     642                 
     643        if ( null === $args->display_label || $args->display_label == false ) 
     644                $args->display_label = $args->label; 
    592645 
    593646        if ( false === $args->label_count ) 
    594647                $args->label_count = array( $args->label, $args->label ); 
     
    797850                $wp_post_types = array(); 
    798851 
    799852        // Args prefixed with an underscore are reserved for internal use. 
    800         $defaults = array('label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'permalink_epmask' => EP_PERMALINK ); 
     853        $defaults = array('allowed_status' => false, 'label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'permalink_epmask' => EP_PERMALINK ); 
    801854        $args = wp_parse_args($args, $defaults); 
    802855        $args = (object) $args; 
    803856 
    804857        $post_type = sanitize_user($post_type, true); 
    805858        $args->name = $post_type; 
     859         
     860        if( null === $args->allowed_status || empty($args->allowed_status) ) 
     861                $args->status_restrict = false; 
    806862 
    807863        // If not set, default to the setting for public. 
    808864        if ( null === $args->publicly_queryable ) 
  • wp-includes/script-loader.php

     
    301301                        'updatePage' => __('Update Page'), 
    302302                        'savePending' => __('Save as Pending'), 
    303303                        'saveDraft' => __('Save Draft'), 
     304                        'saveDefault' => __('Save'), 
    304305                        'private' => __('Private'), 
    305306                        'public' => __('Public'), 
    306307                        'publicSticky' => __('Public, Sticky'), 
  • wp-admin/includes/meta-boxes.php

     
    1010 * @param object $post 
    1111 */ 
    1212function post_submit_meta_box($post) { 
    13         global $action; 
     13        global $action, $wp_post_statuses; 
    1414 
    1515        $post_type = $post->post_type; 
    1616        $post_type_object = get_post_type_object($post_type); 
     
    2727 
    2828<div id="minor-publishing-actions"> 
    2929<div id="save-action"> 
     30<?php if( post_type_can_have_status($post_type, 'publish') ) : ?> 
    3031<?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status )  { ?> 
    3132<input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" tabindex="4" class="button button-highlighted" /> 
    3233<?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> 
    3334<input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" tabindex="4" class="button button-highlighted" /> 
    3435<?php } ?> 
     36<?php endif; ?> 
    3537</div> 
    3638 
    3739<div id="preview-action"> 
     
    5254</div><?php // /minor-publishing-actions ?> 
    5355 
    5456<div id="misc-publishing-actions"> 
    55  
    5657<div class="misc-pub-section<?php if ( !$can_publish ) { echo ' misc-pub-section-last'; } ?>"><label for="post_status"><?php _e('Status:') ?></label> 
    5758<span id="post-status-display"> 
    58 <?php 
    59 switch ( $post->post_status ) { 
    60         case 'private': 
    61                 _e('Privately Published'); 
    62                 break; 
    63         case 'publish': 
    64                 _e('Published'); 
    65                 break; 
    66         case 'future': 
    67                 _e('Scheduled'); 
    68                 break; 
    69         case 'pending': 
    70                 _e('Pending Review'); 
    71                 break; 
    72         case 'draft': 
    73         case 'auto-draft': 
    74                 _e('Draft'); 
    75                 break; 
    76         case 'auto-draft': 
    77                 _e('Unsaved'); 
    78                 break; 
    79 } 
     59<?php  
     60        $status = get_post_status_object($post->post_status); 
     61        if($status->label == 'auto-draft' ) _e('Draft'); 
     62        else _e($status->label);  
    8063?> 
    8164</span> 
    8265<?php if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) { ?> 
     
    8467 
    8568<div id="post-status-select" class="hide-if-js"> 
    8669<input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ('auto-draft' == $post->post_status ) ? 'draft' : $post->post_status); ?>" /> 
     70 
    8771<select name='post_status' id='post_status' tabindex='4'> 
    88 <?php if ( 'publish' == $post->post_status ) : ?> 
    89 <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e('Published') ?></option> 
    90 <?php elseif ( 'private' == $post->post_status ) : ?> 
    91 <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option> 
    92 <?php elseif ( 'future' == $post->post_status ) : ?> 
    93 <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e('Scheduled') ?></option> 
    94 <?php endif; ?> 
    95 <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e('Pending Review') ?></option> 
    96 <?php if ( 'auto-draft' == $post->post_status ) : ?> 
    97 <option<?php selected( $post->post_status, 'auto-draft' ); ?> value='draft'><?php _e('Draft') ?></option> 
    98 <?php else : ?> 
    99 <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e('Draft') ?></option> 
    100 <?php endif; ?> 
     72 
     73        <?php output_post_status_select( $post->post_type, $post->ID ); ?> 
     74 
    10175</select> 
    10276 <a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e('OK'); ?></a> 
    10377 <a href="#post_status" class="cancel-post-status hide-if-no-js"><?php _e('Cancel'); ?></a> 
     
    10680<?php } ?> 
    10781</div><?php // /misc-pub-section ?> 
    10882 
     83<?php if( post_type_can_have_status($post->post_type, 'private') ) : ?> 
    10984<div class="misc-pub-section " id="visibility"> 
    11085<?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php 
    11186 
     
    151126</div> 
    152127<?php } ?> 
    153128 
    154 </div><?php // /misc-pub-section ?> 
     129</div> 
     130<?php endif; // /misc-pub-section for visbility ?> 
    155131 
    156132 
    157 <?php 
     133<?php  
     134 
    158135// translators: Publish box date formt, see http://php.net/date 
    159136$datef = __( 'M j, Y @ G:i' ); 
    160137if ( 0 != $post->ID ) { 
     
    177154 
    178155if ( $can_publish ) : // Contributors don't get to choose the date of publish ?> 
    179156<div class="misc-pub-section curtime misc-pub-section-last"> 
     157<?php if(post_type_can_have_status($post_type, 'future') ) : ?> 
    180158        <span id="timestamp"> 
    181159        <?php printf($stamp, $date); ?></span> 
    182160        <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a> 
    183         <div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'),1,4); ?></div> 
    184 </div><?php // /misc-pub-section ?> 
    185161<?php endif; ?> 
    186162 
     163        <div id="timestampdiv" <?php if(!post_type_can_have_status($post_type, 'future')) echo 'style="display: none;"'; ?> class="hide-if-js"><?php touch_time(($action == 'edit'),1,4); ?></div> 
     164</div><?php // /misc-pub-section ?> 
     165<?php endif; //end future post status ?> 
     166 
    187167<?php do_action('post_submitbox_misc_actions'); ?> 
    188168</div> 
    189169<div class="clear"></div> 
     
    206186<div id="publishing-action"> 
    207187<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" id="ajax-loading" style="visibility:hidden;" alt="" /> 
    208188<?php 
     189if( post_type_can_have_status($post_type, 'publish') === true ) : 
    209190if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) { 
    210191        if ( $can_publish ) : 
    211192                if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?> 
     
    224205                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update') ?>" /> 
    225206                <input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php esc_attr_e('Update') ?>" /> 
    226207<?php 
    227 } ?> 
     208}  
     209else: ?> 
     210                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Save') ?>" /> 
     211                <input name="save" type="submit" class="button-primary" id="save_post" tabindex="5" accesskey="p" value="<?php esc_attr_e('Save') ?>" /> 
     212<?php endif; ?> 
    228213</div> 
    229214<div class="clear"></div> 
    230215</div> 
  • wp-admin/includes/template.php

     
    88 * @subpackage Administration 
    99 */ 
    1010 
     11function output_post_status_select( $post_type, $id = null, $view_defaults = false ){ 
     12        global $wp_post_statuses; 
     13         
     14        $post = (!empty($id)) ? get_post( $id ) : null; 
     15        //$post_type = $post->post_type; 
     16        $post_type_object = get_post_type_object($post_type); 
     17 
     18         
     19        foreach( $wp_post_statuses as $status => $args ): 
     20                if($status == 'auto-draft') continue; 
     21                 
     22                if(post_type_can_have_status($post_type, $status)){ 
     23                 
     24                        if( $view_defaults === true && in_array($status, array('publish', 'draft')) ) 
     25                                $continue = true; 
     26                         
     27                        if( $status == $post->post_status || $args->show_in_select_ui === true || $continue === true ) { 
     28 
     29                                $allowed_edit = true; 
     30                                         
     31                                if(     isset($args->edit_cap) && !current_user_can($args->edit_cap) ) 
     32                                        $allowed_edit = false; 
     33                                if( $allowed_edit === true ) { ?> 
     34                                         
     35                                        <option<?php ( isset($post) ) ? selected( $post->post_status, $status ) : ''; ?> value='<?php echo ($status == 'auto-draft') ? 'draft' : $status; ?>'><?php _e($args->display_label); ?></option>; 
     36<?php                   } 
     37                        } 
     38                } 
     39                unset($continue); 
     40        endforeach; 
     41} 
     42 
    1143/** 
    1244 * {@internal Missing Short Description}} 
    1345 * 
     
    847879 * @param string $screen 
    848880 */ 
    849881function inline_edit_row( $screen ) { 
    850         global $current_user, $mode; 
     882        global $current_user, $mode, $wp_post_statuses, $posts; 
    851883 
    852884        if ( is_string($screen) ) { 
    853885                $screen = array('id' => 'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen ); 
     
    10991131<?php if ( $bulk ) : ?> 
    11001132                                        <option value="-1"><?php _e('&mdash; No Change &mdash;'); ?></option> 
    11011133<?php endif; // $bulk ?> 
    1102                                 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?> 
    1103                                         <option value="publish"><?php _e( 'Published' ); ?></option> 
    1104                                         <option value="future"><?php _e( 'Scheduled' ); ?></option> 
    1105 <?php if ( $bulk ) : ?> 
    1106                                         <option value="private"><?php _e('Private') ?></option> 
    1107 <?php endif; // $bulk ?> 
    1108                                 <?php endif; ?> 
    1109                                         <option value="pending"><?php _e( 'Pending Review' ); ?></option> 
    1110                                         <option value="draft"><?php _e( 'Draft' ); ?></option> 
     1134 
     1135                                        <?php output_post_status_select( $screen->post_type, null, true); ?> 
     1136                                         
    11111137                                </select> 
    11121138                        </label> 
    11131139 
     
    11641190                <br class="clear" /> 
    11651191        </p> 
    11661192        </td></tr> 
    1167 <?php 
     1193<?php  
    11681194        $bulk++; 
    11691195        } ?> 
    11701196        </tbody></table></form> 
  • wp-admin/js/post.dev.js

     
    432432                                $('#save-post').hide(); 
    433433                        } else { 
    434434                                $('#save-post').show(); 
    435                                 if ( $('option:selected', postStatus).val() == 'pending' ) { 
    436                                         $('#save-post').show().val( postL10n.savePending ); 
     435                                if ( $('option:selected', postStatus).val() == 'draft' ) { 
     436                                        $('#save-post').show().val( postL10n.saveDraft ); 
    437437                                } else { 
    438                                         $('#save-post').show().val( postL10n.saveDraft ); 
     438                                        $('#save-post').show().val( postL10n.saveDefault ); 
    439439                                } 
    440440                        } 
    441441                        return true;