WordPress.org

Make WordPress Core

Ticket #12706: 12706.9.patch

File 12706.9.patch, 6.0 KB (added by Mosterd3d, 3 years ago)

Fix custom post status

  • src/wp-admin/includes/meta-boxes.php

     
    3838<div id="minor-publishing-actions">
    3939<div id="save-action">
    4040<?php
    41 if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) {
    42         $private_style = '';
    43         if ( 'private' == $post->post_status ) {
    44                 $private_style = 'style="display:none"';
    45         }
     41$btnHideArray = array( 'publish','future','private' );
     42if ( !in_array( $post->post_status, $btnHideArray ) ) {
     43    submit_button( 'Save '.ucfirst($post->post_status),'secondary','save',false,array( 'id' => 'save-post' ));
     44}
    4645?>
    47 <input <?php echo $private_style; ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Draft' ); ?>" class="button" />
    4846<span class="spinner"></span>
    49 <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?>
    50 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save as Pending' ); ?>" class="button" />
    51 <span class="spinner"></span>
    52 <?php } ?>
    5347</div>
    5448<?php if ( is_post_type_viewable( $post_type_object ) ) : ?>
    5549<div id="preview-action">
     
    8983
    9084<div class="misc-pub-section misc-pub-post-status">
    9185<?php _e( 'Status:' ); ?> <span id="post-status-display">
    92                         <?php
    93 
    94                         switch ( $post->post_status ) {
    95                                 case 'private':
    96                                         _e( 'Privately Published' );
    97                                         break;
    98                                 case 'publish':
    99                                         _e( 'Published' );
    100                                         break;
    101                                 case 'future':
    102                                         _e( 'Scheduled' );
    103                                         break;
    104                                 case 'pending':
    105                                         _e( 'Pending Review' );
    106                                         break;
    107                                 case 'draft':
    108                                 case 'auto-draft':
    109                                         _e( 'Draft' );
    110                                         break;
    111                         }
     86<?php
     87global $wp_post_statuses, $allowed_post_status;
     88foreach( $wp_post_statuses as $key => $wp_post_status ) {
     89    if( $key == $post->post_status ) {
     90        $allowed_post_status = $wp_post_status->show_in_admin_status_list;
     91        echo __( $wp_post_status->label );
     92    }
     93}
    11294?>
    11395</span>
    114 <?php
    115 if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) {
    116         $private_style = '';
    117         if ( 'private' == $post->post_status ) {
    118                 $private_style = 'style="display:none"';
    119         }
    120 ?>
    121 <a href="#post_status" <?php echo $private_style; ?> class="edit-post-status hide-if-no-js" role="button"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit status' ); ?></span></a>
    122 
     96<?php if ( $allowed_post_status && ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish )) { ?>
     97<a href="#post_status" <?php if ( 'private' == $post->post_status ) { ?>style="display:none;" <?php } ?> class="edit-post-status hide-if-no-js" role="button"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit status' ); ?></span></a>
    12398<div id="post-status-select" class="hide-if-js">
    12499<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 ); ?>" />
    125100<label for="post_status" class="screen-reader-text"><?php _e( 'Set status' ); ?></label>
    126101<select name="post_status" id="post_status">
    127 <?php if ( 'publish' == $post->post_status ) : ?>
    128 <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e( 'Published' ); ?></option>
    129 <?php elseif ( 'private' == $post->post_status ) : ?>
    130 <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e( 'Privately Published' ); ?></option>
    131 <?php elseif ( 'future' == $post->post_status ) : ?>
    132 <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e( 'Scheduled' ); ?></option>
    133 <?php endif; ?>
    134 <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e( 'Pending Review' ); ?></option>
    135 <?php if ( 'auto-draft' == $post->post_status ) : ?>
    136 <option<?php selected( $post->post_status, 'auto-draft' ); ?> value='draft'><?php _e( 'Draft' ); ?></option>
    137 <?php else : ?>
    138 <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e( 'Draft' ); ?></option>
    139 <?php endif; ?>
     102<?php
     103$ppf = array( 'publish','private','future' );
     104foreach( $wp_post_statuses as $key => $wp_post_status ){
     105    $show = $wp_post_status->show_in_admin_status_list ? ( in_array( $key, $ppf ) ? ( $post->post_status === $key ? true : false ) : ( $key === 'trash' ? false : true )) : false ;
     106    if( $show ) {
     107        echo "<option " . selected( $post->post_status, $key, false ) . "  value='" . $key . "'>" . __( $wp_post_status->label ) . "</option>";
     108    }
     109}
     110?>
    140111</select>
    141112<a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e( 'OK' ); ?></a>
    142113<a href="#post_status" class="cancel-post-status hide-if-no-js button-cancel"><?php _e( 'Cancel' ); ?></a>
  • src/wp-admin/js/post.js

     
    796796                        $('#post-status-display').html($('option:selected', postStatus).text());
    797797
    798798                        // Show or hide the "Save Draft" button.
    799                         if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
    800                                 $('#save-post').hide();
    801                         } else {
    802                                 $('#save-post').show();
    803                                 if ( $('option:selected', postStatus).val() == 'pending' ) {
    804                                         $('#save-post').show().val( postL10n.savePending );
    805                                 } else {
    806                                         $('#save-post').show().val( postL10n.saveDraft );
    807                                 }
     799                        var postStatusVal = $('option:selected', postStatus).val();
     800            var phrase = postStatusVal === 'pending' ? postL10n.savePending : 'Save '+ $('option:selected', postStatus).val();
     801                        if ( postStatusVal === 'private' || postStatusVal === 'publish' ) {
     802                $('#save-post').hide();
    808803                        }
     804            else {
     805                $('#save-post').show().val( phrase );
     806            }
    809807                        return true;
    810808                };
    811809