Ticket #12706: 12706.db.2.diff
File 12706.db.2.diff, 32.5 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/class-wp-posts-list-table.php
142 142 $total_posts = array_sum( (array) $num_posts ); 143 143 144 144 // Subtract post types that are not included in the admin all list. 145 foreach ( get_post_stati( array('show_in_admin_all_list' => false ) ) as $state )145 foreach ( get_post_stati( array('show_in_admin_all_list' => false, 'post_type' => $post_type ) ) as $state ) 146 146 $total_posts -= $num_posts->$state; 147 147 148 148 $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : ''; 149 149 $status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>'; 150 150 151 foreach ( get_post_stati(array('show_in_admin_status_list' => true ), 'objects') as $status ) {151 foreach ( get_post_stati(array('show_in_admin_status_list' => true, 'post_type' => $post_type ), 'objects') as $status ) { 152 152 $class = ''; 153 153 154 154 $status_name = $status->name; … … 279 279 } 280 280 281 281 $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; 282 if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future') ) )282 if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, get_post_stati( array( 'protected' => true, 'post_type' => $post_type ) ) ) ) 283 283 $posts_columns['comments'] = '<span class="vers"><div title="' . esc_attr__( 'Comments' ) . '" class="comment-grey-bubble"></div></span>'; 284 284 285 285 $posts_columns['date'] = __( 'Date' ); … … 572 572 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>"; 573 573 } 574 574 if ( $post_type_object->public ) { 575 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future') ) ) {575 if ( in_array( $post->post_status, get_post_stati( array( 'protected' => true, 'post_type' => $post->post_type ) ) ) ) { 576 576 if ( $can_edit_post ) 577 577 $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>'; 578 578 } elseif ( 'trash' != $post->post_status ) { … … 610 610 else 611 611 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>'; 612 612 echo '<br />'; 613 if ( 'publish' == $post->post_status) {613 if ( in_array( $post->post_status, get_post_stati( array( 'public' => true ), $post->post_type ) ) ) { 614 614 _e( 'Published' ); 615 615 } elseif ( 'future' == $post->post_status ) { 616 616 if ( $time_diff > 0 ) … … 972 972 <label class="inline-edit-status alignleft"> 973 973 <span class="title"><?php _e( 'Status' ); ?></span> 974 974 <select name="_status"> 975 <?php if ( $bulk ) : ?> 976 <option value="-1"><?php _e( '— No Change —' ); ?></option> 977 <?php endif; // $bulk ?> 978 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?> 979 <option value="publish"><?php _e( 'Published' ); ?></option> 980 <option value="future"><?php _e( 'Scheduled' ); ?></option> 981 <?php if ( $bulk ) : ?> 982 <option value="private"><?php _e( 'Private' ) ?></option> 983 <?php endif; // $bulk ?> 984 <?php endif; ?> 985 <option value="pending"><?php _e( 'Pending Review' ); ?></option> 986 <option value="draft"><?php _e( 'Draft' ); ?></option> 975 <?php 976 $statuses = array(); 977 if ( $bulk ) 978 $statuses['-1'] = _e( '— No Change —' ); 979 if ( $can_publish ) { 980 $public_stati = get_post_stati( array( 'public' => true, 'post_type' => $screen->post_type ), 'objects' ); 981 foreach( $public_stati as $status ) { 982 $statuses[$status->name] = $status->labels['label']; 983 } 984 if ( $bulk ) { 985 $private_stati = get_post_stati( array( 'private' => true, 'post_type' => $screen->post_type ), 'objects' ); 986 foreach( $private_stati as $status ) { 987 $statuses[$status->name] = $status->labels['label']; 988 } 989 } 990 } 991 $moderation_stati = get_post_stati( array( 'moderation' => true, 'post_type' => $screen->post_type ), 'objects' ); 992 foreach( $moderation_stati as $status ) { 993 $statuses[$status->name] = $status->labels['label']; 994 } 995 foreach( $statuses as $status_key => $status_label ) : ?> 996 <option value="<?php echo esc_attr( $status_key ); ?>"><?php echo esc_html( $status_label ); ?></option> 997 <?php endforeach; ?> 987 998 </select> 988 999 </label> 989 1000 -
wp-admin/includes/post.php
93 93 $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; 94 94 95 95 // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published. 96 // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.96 // Change status from 'publish' to the next available moderation status 97 97 if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) ) 98 if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) ) 99 $post_data['post_status'] = 'pending'; 98 if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) ) { 99 $moderation_statuses = array_values( get_post_stati( array( 'moderation' => true, 'post_type' => $ptype->name ) ) ); 100 $next_status = array_search( $previous_status, $moderation_statuses ) + 1; 101 if ( ! empty( $moderation_statuses[$next_status] ) ) 102 $post_data['post_status'] = $moderation_statuses[$next_status]; 103 else 104 $post_data['post_status'] = $previous_status; 105 } 100 106 101 107 if ( ! isset($post_data['post_status']) ) 102 108 $post_data['post_status'] = $previous_status; … … 172 178 if ( is_wp_error($post_data) ) 173 179 wp_die( $post_data->get_error_message() ); 174 180 if ( ( empty( $post_data['action'] ) || 'autosave' != $post_data['action'] ) && 'auto-draft' == $post_data['post_status'] ) { 175 $post_data['post_status'] = 'draft'; 181 $moderation_statuses = array_shift( array_keys( get_post_stati( array( 'moderation' => true, 'post_type' => $post_data['post_type'] ) ) ) ); 182 $post_data['post_status'] = $moderation_statuses[0]; 176 183 } 177 184 178 185 if ( isset($post_data['visibility']) ) { … … 993 1000 994 1001 // Hack: get_permalink would return ugly permalink for 995 1002 // drafts, so we will fake, that our post is published 996 if ( in_array($post->post_status, array('draft', 'pending')) ) {1003 if ( in_array($post->post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post->post_type ) )) ) { 997 1004 $post->post_status = 'publish'; 998 1005 $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); 999 1006 } -
wp-admin/includes/meta-boxes.php
14 14 15 15 $post_type = $post->post_type; 16 16 $post_type_object = get_post_type_object($post_type); 17 18 if ( 'auto-draft' == $post->post_status ) 19 $post_status = array_shift( get_post_stati( array( 'moderation' => true, 'post_type' => $post->post_type ), 'objects' ) ); 20 else 21 $post_status = get_post_status_object( $post->post_status, $post->post_type ); 22 17 23 $can_publish = current_user_can($post_type_object->cap->publish_posts); 18 24 ?> 19 25 <div class="submitbox" id="submitpost"> … … 27 33 28 34 <div id="minor-publishing-actions"> 29 35 <div id="save-action"> 30 <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> 31 <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'); ?>" class="button" /> 32 <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> 33 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" /> 34 <?php } ?> 36 <?php if ( $post_status->moderation ) : ?> 37 <input type="submit" name="save" id="save-post" value="<?php echo esc_attr( $post_status->labels['save'] ); ?>" class="button" /> 38 <?php endif; ?> 35 39 <span class="spinner"></span> 36 40 </div> 37 41 <?php if ( $post_type_object->public ) : ?> 38 42 <div id="preview-action"> 39 43 <?php 40 if ( 'publish' == $post->post_status) {44 if ( $post_status->public ) { 41 45 $preview_link = esc_url( get_permalink( $post->ID ) ); 42 46 $preview_button = __( 'Preview Changes' ); 43 47 } else { … … 55 59 56 60 <div id="misc-publishing-actions"> 57 61 58 <div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label> 59 <span id="post-status-display"> 60 <?php 61 switch ( $post->post_status ) { 62 case 'private': 63 _e('Privately Published'); 64 break; 65 case 'publish': 66 _e('Published'); 67 break; 68 case 'future': 69 _e('Scheduled'); 70 break; 71 case 'pending': 72 _e('Pending Review'); 73 break; 74 case 'draft': 75 case 'auto-draft': 76 _e('Draft'); 77 break; 78 } 79 ?> 80 </span> 81 <?php if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) { ?> 82 <a href="#post_status" <?php if ( 'private' == $post->post_status ) { ?>style="display:none;" <?php } ?>class="edit-post-status hide-if-no-js"><?php _e('Edit') ?></a> 62 <div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label> 63 <span id="post-status-display"><?php echo esc_html( $post_status->labels['label'] ); ?></span> 83 64 84 <div id="post-status-select" class="hide-if-js"> 85 <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); ?>" /> 86 <select name='post_status' id='post_status'> 87 <?php if ( 'publish' == $post->post_status ) : ?> 88 <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e('Published') ?></option> 89 <?php elseif ( 'private' == $post->post_status ) : ?> 90 <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option> 91 <?php elseif ( 'future' == $post->post_status ) : ?> 92 <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e('Scheduled') ?></option> 93 <?php endif; ?> 94 <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e('Pending Review') ?></option> 95 <?php if ( 'auto-draft' == $post->post_status ) : ?> 96 <option<?php selected( $post->post_status, 'auto-draft' ); ?> value='draft'><?php _e('Draft') ?></option> 97 <?php else : ?> 98 <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e('Draft') ?></option> 99 <?php endif; ?> 100 </select> 65 <?php 66 $dropdown_statuses = array(); 67 // All statuses like 'future', 'publish', and 'private' should appear in dropdown only when post 68 // is in that status 69 if ( ! $post_status->moderation && $can_publish ) 70 $dropdown_statuses[] = $post_status; 71 72 // A post in moderation can be changed to other moderation stati, regardless of publish caps 73 if ( $post_status->moderation ) 74 $dropdown_statuses = array_merge( $dropdown_statuses, get_post_stati( array( 'moderation' => true, 'post_type' => $post->post_type ), 'objects' ) ); 75 76 if ( ! empty( $dropdown_statuses ) && ! $post_status->private ) : ?> 77 <a href="#post_status" class="edit-post-status hide-if-no-js"><?php _e('Edit') ?></a> 78 79 <div id="post-status-select" class="hide-if-js"> 80 <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo $post_status->name; ?>" /> 81 <select name='post_status' id='post_status'> 82 <?php foreach( $dropdown_statuses as $dropdown_status ) : ?> 83 <option <?php selected( $dropdown_status->name, $post_status->name ); ?> value="<?php echo $dropdown_status->name; ?>"><?php echo esc_attr( $dropdown_status->labels['label'] ); ?></option> 84 <?php endforeach; ?> 85 </select> 101 86 <a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e('OK'); ?></a> 102 87 <a href="#post_status" class="cancel-post-status hide-if-no-js"><?php _e('Cancel'); ?></a> 103 88 </div> 104 89 105 <?php }?>90 <?php endif; ?> 106 91 </div><!-- .misc-pub-section --> 107 92 108 93 <div class="misc-pub-section" id="visibility"> 109 94 <?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php 110 95 111 if ( 'private' == $post->post_status) {96 if ( $post_status->private ) { 112 97 $post->post_password = ''; 113 98 $visibility = 'private'; 114 99 $visibility_trans = __('Private'); … … 202 187 <div id="publishing-action"> 203 188 <span class="spinner"></span> 204 189 <?php 205 if ( !in_array( $post->post_status, array('publish', 'future', 'private') )|| 0 == $post->ID ) {190 if ( $post_status->moderation || 0 == $post->ID ) { 206 191 if ( $can_publish ) : 207 192 if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?> 208 193 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" /> … … 212 197 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 213 198 <?php endif; 214 199 else : ?> 215 <input name="original_publish" type="hidden" id="original_publish" value="<?php e sc_attr_e('Submit for Review')?>" />216 <?php submit_button( __( 'Submit for Review' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>200 <input name="original_publish" type="hidden" id="original_publish" value="<?php echo esc_attr( $post_status->labels['save_next'] ); ?>" /> 201 <?php submit_button( $post_status->labels['save_next'], 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 217 202 <?php 218 203 endif; 219 204 } else { ?> -
wp-admin/includes/template.php
577 577 $post = get_post(); 578 578 579 579 if ( $for_post ) 580 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );580 $edit = ! ( in_array($post->post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post->post_type ) ) ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); 581 581 582 582 $tab_index_attribute = ''; 583 583 if ( (int) $tab_index > 0 ) … … 1424 1424 else 1425 1425 $post_status = ''; 1426 1426 1427 if ( !empty( $post->post_password) )1427 if ( !empty( $post->post_password ) ) 1428 1428 $post_states['protected'] = __('Password protected'); 1429 if ( 'private' == $post->post_status && 'private' != $post_status ) 1430 $post_states['private'] = __('Private'); 1431 if ( 'draft' == $post->post_status && 'draft' != $post_status ) 1432 $post_states['draft'] = __('Draft'); 1433 if ( 'pending' == $post->post_status && 'pending' != $post_status ) 1434 /* translators: post state */ 1435 $post_states['pending'] = _x('Pending', 'post state'); 1429 1430 $protected_statuses = get_post_stati( array( 'protected' => true, 'post_type' => $post->post_type ) ); 1431 if ( in_array( $post->post_status, $protected_statuses ) && ! in_array( $post_status, $protected_statuses ) ) 1432 $post_states[$post->post_status] = get_post_status_object( $post->post_status, $post->post_type )->labels['label']; 1433 1436 1434 if ( is_sticky($post->ID) ) 1437 1435 $post_states['sticky'] = __('Sticky'); 1438 1436 -
wp-admin/js/post.js
453 453 $('.edit-post-status', '#misc-publishing-actions').show(); 454 454 } 455 455 $('#post-status-display').html($('option:selected', postStatus).text()); 456 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { 456 var $selectedStatus = postL10n.postStati[$('option:selected', postStatus).val()]; 457 if ( $selectedStatus.private || $selectedStatus.public ) { 457 458 $('#save-post').hide(); 458 459 } else { 459 $('#save-post').show(); 460 if ( $('option:selected', postStatus).val() == 'pending' ) { 461 $('#save-post').show().val( postL10n.savePending ); 462 } else { 463 $('#save-post').show().val( postL10n.saveDraft ); 464 } 460 $('#save-post').show().val( $selectedStatus.labels['save'] ); 465 461 } 466 462 return true; 467 463 } -
wp-includes/post-template.php
109 109 if ( ! empty( $post->post_password ) ) { 110 110 $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) ); 111 111 $title = sprintf( $protected_title_format, $title ); 112 } else if ( isset( $post->post_status ) && 'private' == $post->post_status) {112 } else if ( isset( $post->post_status ) && get_post_status_object( $post->post_status, $post->post_type )->private ) { 113 113 $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) ); 114 114 $title = sprintf( $private_title_format, $title ); 115 115 } … … 698 698 if ( 1 == $i ) { 699 699 $url = get_permalink(); 700 700 } else { 701 if ( '' == get_option('permalink_structure') || in_array( $post->post_status, array('draft', 'pending')) )701 if ( '' == get_option('permalink_structure') || in_array( $post->post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post->post_type ) ) ) ) 702 702 $url = add_query_arg( 'page', $i, get_permalink() ); 703 703 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) 704 704 $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); -
wp-includes/post.php
121 121 ) ); 122 122 123 123 register_post_status( 'draft', array( 124 'label' => _x( 'Draft', 'post' ), 124 'labels' => array( 125 'label' => _x( 'Draft', 'post' ), 126 'save_next' => _x( 'Submit for Review', 'post' ), 127 ), 125 128 'protected' => true, 129 'moderation' => true, 126 130 '_builtin' => true, /* internal use only. */ 127 131 'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), 132 'show_in_admin_status_dropdown' => true, 128 133 ) ); 129 134 130 135 register_post_status( 'pending', array( 131 'label' => _x( 'Pending', 'post' ), 136 'labels' => array( 137 'label' => _x( 'Pending', 'post' ), 138 'save' => _x( 'Save as Pending', 'post' ), 139 ), 132 140 'protected' => true, 141 'moderation' => true, 133 142 '_builtin' => true, /* internal use only. */ 134 143 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), 144 'show_in_admin_status_dropdown' => true, 135 145 ) ); 136 146 137 147 register_post_status( 'private', array( … … 673 683 } 674 684 675 685 /** 686 * WordPress Post Status class. 687 * 688 * @since 3.6.0 689 * 690 */ 691 final class WP_Post_Status { 692 693 /** 694 * 695 * @var string 696 */ 697 public $name = ''; 698 699 /** 700 * 701 * @var string 702 */ 703 public $label = false; 704 705 /** 706 * 707 * @var array 708 */ 709 public $label_count = false; 710 711 /** 712 * 713 * @var labels 714 */ 715 public $labels = array(); 716 717 /** 718 * 719 * @var bool 720 */ 721 public $exclude_from_search = null; 722 723 /** 724 * 725 * @var bool 726 */ 727 public $_builtin = false; 728 729 /** 730 * 731 * @var bool 732 */ 733 public $public = null; 734 735 /** 736 * 737 * @var bool 738 */ 739 public $internal = null; 740 741 /** 742 * 743 * @var bool 744 */ 745 public $protected = null; 746 747 /** 748 * 749 * @var bool 750 */ 751 public $moderation = null; 752 753 /** 754 * 755 * @var bool 756 */ 757 public $private = null; 758 759 /** 760 * 761 * @var array 762 */ 763 public $post_type = null; 764 765 /** 766 * 767 * @var bool 768 */ 769 public $publicly_queryable = null; 770 771 /** 772 * 773 * @var bool 774 */ 775 public $show_in_admin_status_list = null; 776 777 /** 778 * 779 * @var bool 780 */ 781 public $show_in_admin_all_list = null; 782 783 /** 784 * 785 * @var bool 786 */ 787 public $show_in_admin_status_dropdown = false; 788 789 public function __construct( $post_status, $args = array() ) { 790 791 $args = (object) $args; 792 foreach ( get_object_vars( $args ) as $key => $value ) 793 $this->$key = $value; 794 795 $this->name = sanitize_key( $post_status ); 796 797 if ( null === $this->public && null === $this->internal && null === $this->protected && null === $this->private && null === $this->moderation ) 798 $this->internal = true; 799 800 if ( null === $this->public ) 801 $this->public = false; 802 803 if ( null === $this->private ) 804 $this->private = false; 805 806 if ( null === $this->protected ) 807 $this->protected = false; 808 809 if ( null === $this->moderation ) 810 $this->moderation = false; 811 812 if ( null === $this->internal ) 813 $this->internal = false; 814 815 if ( null === $this->publicly_queryable ) 816 $this->publicly_queryable = $this->public; 817 818 if ( null === $this->exclude_from_search ) 819 $this->exclude_from_search = $this->internal; 820 821 if ( null === $this->show_in_admin_all_list ) 822 $this->show_in_admin_all_list = !$this->internal; 823 824 if ( null === $this->show_in_admin_status_list ) 825 $this->show_in_admin_status_list = !$this->internal; 826 827 if ( null === $this->show_in_admin_status_dropdown ) 828 $this->show_in_admin_status_dropdown = $this->moderation; 829 830 if ( empty( $this->labels['label'] ) ) 831 $this->labels['label'] = ( null !== $this->label ) ? $this->label : $post_status; 832 833 if ( empty( $this->labels['label_count'] ) ) 834 $this->labels['label_count'] = ( null !== $this->label_count ) ? $this->label_count : array( $this->label, $this->label ); 835 836 if ( empty( $this->labels['save'] ) ) 837 $this->labels['save'] = sprintf( _x( 'Save %s', 'post'), $this->labels['label'] ); 838 839 if ( empty( $this->labels['save_next'] ) ) 840 $this->labels['save_next'] = _x( 'Submit', 'post'); 841 842 if ( is_string( $this->post_type ) ) 843 $this->post_type = array( $this->post_type ); 844 } 845 } 846 847 /** 676 848 * Retrieve ancestors of a post. 677 849 * 678 850 * @since 2.5.0 … … 920 1092 * @param array|string $args See above description. 921 1093 */ 922 1094 function register_post_status($post_status, $args = array()) { 923 global $wp_post_statuses ;1095 global $wp_post_statuses, $wp_post_types; 924 1096 925 1097 if (!is_array($wp_post_statuses)) 926 1098 $wp_post_statuses = array(); 927 1099 928 // Args prefixed with an underscore are reserved for internal use. 929 $defaults = array( 930 'label' => false, 931 'label_count' => false, 932 'exclude_from_search' => null, 933 '_builtin' => false, 934 'public' => null, 935 'internal' => null, 936 'protected' => null, 937 'private' => null, 938 'publicly_queryable' => null, 939 'show_in_admin_status_list' => null, 940 'show_in_admin_all_list' => null, 941 ); 942 $args = wp_parse_args($args, $defaults); 943 $args = (object) $args; 1100 $args = new WP_Post_Status( $post_status, $args ); 1101 $wp_post_statuses[ $post_status ] = $args; 944 1102 945 $post_status = sanitize_key($post_status); 946 $args->name = $post_status; 1103 // Add status to already registered post types 1104 if ( ! empty( $wp_post_types ) ) 1105 foreach ( $wp_post_types as $key => $post_type ) { 1106 if ( ! empty( $args->post_type ) && ! in_array( $key, $args->post_type ) ) 1107 continue; 947 1108 948 if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) 949 $args->internal = true; 1109 if ( ! array_key_exists( $post_status, $post_type->statuses ) ) 1110 $wp_post_types[ $key ]->statuses[ $post_status ] = $args; 1111 } 950 1112 951 if ( null === $args->public )952 $args->public = false;953 954 if ( null === $args->private )955 $args->private = false;956 957 if ( null === $args->protected )958 $args->protected = false;959 960 if ( null === $args->internal )961 $args->internal = false;962 963 if ( null === $args->publicly_queryable )964 $args->publicly_queryable = $args->public;965 966 if ( null === $args->exclude_from_search )967 $args->exclude_from_search = $args->internal;968 969 if ( null === $args->show_in_admin_all_list )970 $args->show_in_admin_all_list = !$args->internal;971 972 if ( null === $args->show_in_admin_status_list )973 $args->show_in_admin_status_list = !$args->internal;974 975 if ( false === $args->label )976 $args->label = $post_status;977 978 if ( false === $args->label_count )979 $args->label_count = array( $args->label, $args->label );980 981 $wp_post_statuses[$post_status] = $args;982 983 1113 return $args; 984 1114 } 985 1115 … … 996 1126 * @param string $post_status The name of a registered post status 997 1127 * @return object A post status object 998 1128 */ 999 function get_post_status_object( $post_status ) {1129 function get_post_status_object( $post_status, $object_type = null ) { 1000 1130 global $wp_post_statuses; 1001 1131 1002 if ( empty($wp_post_statuses[$post_status]) ) 1003 return null; 1132 $status_object = null; 1004 1133 1005 return $wp_post_statuses[$post_status]; 1134 if ( $object_type ) { 1135 $post_type = get_post_type_object( $object_type ); 1136 if ( $post_type && ! empty( $post_type->statuses[ $post_status ] ) ) 1137 $status_object = $post_type->statuses[ $post_status ]; 1138 } 1139 1140 if ( ! empty( $wp_post_statuses[ $post_status ] ) ) 1141 $status = $wp_post_statuses[ $post_status ]; 1142 1143 // Search across all post types 1144 foreach ( get_post_types( array(), 'objects' ) as $post_type ) { 1145 if ( ! empty( $post_type->statuses[ $post_status ] ) ) { 1146 $status_object = $post_type->statuses[ $post_status ]; 1147 break; 1148 } 1149 } 1150 1151 return $status_object; 1006 1152 } 1007 1153 1008 1154 /** … … 1026 1172 1027 1173 $field = ('names' == $output) ? 'name' : false; 1028 1174 1029 return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); 1175 $statuses = $wp_post_statuses; 1176 1177 if ( ! empty( $args['post_type'] ) ) { 1178 $post_type = get_post_type_object( $args['post_type'] ); 1179 if ( $post_type && ! empty( $post_type->statuses ) ) 1180 $statuses = $post_type->statuses; 1181 1182 unset( $args['post_type'] ); 1183 } 1184 1185 return wp_filter_object_list( $statuses, $args, $operator, $field ); 1030 1186 } 1031 1187 1032 1188 /** … … 1211 1367 * @return object|WP_Error the registered post type object, or an error object 1212 1368 */ 1213 1369 function register_post_type( $post_type, $args = array() ) { 1214 global $wp_post_types, $wp_rewrite, $wp ;1370 global $wp_post_types, $wp_rewrite, $wp, $wp_post_statuses; 1215 1371 1216 1372 if ( !is_array($wp_post_types) ) 1217 1373 $wp_post_types = array(); … … 1227 1383 'can_export' => true, 1228 1384 'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 1229 1385 'delete_with_user' => null, 1386 'statuses' => null, 1230 1387 ); 1231 1388 $args = wp_parse_args($args, $defaults); 1232 1389 $args = (object) $args; … … 1336 1493 if ( $args->register_meta_box_cb ) 1337 1494 add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); 1338 1495 1496 if ( null === $args->statuses ) 1497 $args->statuses = array(); 1498 1499 foreach ( $args->statuses as $post_status => $post_status_args ) 1500 $args->statuses[ $post_status ] = new WP_Post_Status( $post_status, $post_status_args ); 1501 1502 // Legacy post statuses 1503 if ( ! empty( $wp_post_statuses ) ) 1504 foreach ( $wp_post_statuses as $key => $post_status ) 1505 if ( empty( $args->statuses[ $key ] ) ) 1506 $args->statuses[ $key ] = $post_status; 1507 1339 1508 $args->labels = get_post_type_labels( $args ); 1340 1509 $args->label = $args->labels->name; 1341 1510 … … 2142 2311 $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2143 2312 2144 2313 $stats = array(); 2145 foreach ( get_post_stati( ) as $state )2314 foreach ( get_post_stati( array( 'post_type' => $type ) ) as $state ) 2146 2315 $stats[$state] = 0; 2147 2316 2148 2317 foreach ( (array) $count as $row ) … … 2736 2905 if ( empty($post_type) ) 2737 2906 $post_type = 'post'; 2738 2907 2739 if ( empty($post_status) ) 2740 $post_status = 'draft'; 2908 if ( empty($post_status) ) { 2909 $post_status = array_shift( get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ); 2910 } 2741 2911 2742 2912 if ( !empty($post_category) ) 2743 2913 $post_category = array_filter($post_category); // Filter out empty terms … … 2767 2937 if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) 2768 2938 $post_name = ''; 2769 2939 2770 // Create a valid post name. Drafts and pending posts are allowed to have an empty 2771 // post name. 2940 // Create a valid post name. Posts in moderation are allowed to have an empty post_name 2772 2941 if ( empty($post_name) ) { 2773 if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 2942 if ( 'auto-draft' != $post_status 2943 && ! in_array( $post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) 2774 2944 $post_name = sanitize_title($post_title); 2775 2945 else 2776 2946 $post_name = ''; … … 2800 2970 } 2801 2971 2802 2972 if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) { 2803 if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 2973 if ( 'auto-draft' != $post_status 2974 && ! in_array( $post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) 2804 2975 $post_date_gmt = get_gmt_from_date($post_date); 2805 2976 else 2806 2977 $post_date_gmt = '0000-00-00 00:00:00'; … … 2895 3066 $where = array( 'ID' => $post_ID ); 2896 3067 } 2897 3068 2898 if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 3069 if ( empty($data['post_name']) 3070 && 'auto-draft' != $data['post_status'] 3071 && ! in_array( $data['post_status'], get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) { 2899 3072 $data['post_name'] = sanitize_title($data['post_title'], $post_ID); 2900 3073 $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); 2901 3074 } … … 2985 3158 else 2986 3159 $post_cats = $post['post_category']; 2987 3160 2988 // Drafts shouldn't be assigned a date unless explicitly done so by the user 2989 if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && 2990 ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) 3161 // Moderation posts shouldn't be assigned a date unless explicitly done so by the user 3162 if ( isset( $post['post_status'] ) 3163 && ( 'auto-draft' == $post['post_status'] || in_array( $post['post_status'], get_post_stati( array( 'moderation' => true, 'post_type' => $post['post_type'] ) ) ) ) 3164 && empty($postarr['edit_date']) 3165 && ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) 2991 3166 $clear_date = true; 2992 3167 else 2993 3168 $clear_date = false; … … 3084 3259 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 3085 3260 */ 3086 3261 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 3087 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft') ) )3262 if ( 'auto-draft' == $post_status || in_array( $post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) 3088 3263 return $slug; 3089 3264 3090 3265 global $wpdb, $wp_rewrite; … … 3646 3821 // Make sure we have a valid post status 3647 3822 if ( !is_array( $post_status ) ) 3648 3823 $post_status = explode( ',', $post_status ); 3649 if ( array_diff( $post_status, get_post_stati( ) ) )3824 if ( array_diff( $post_status, get_post_stati( array( 'post_type' => $post_type ) ) ) ) 3650 3825 return $pages; 3651 3826 3652 3827 // $args can be whatever, only use the args defined in defaults to compute the key -
wp-includes/link-template.php
114 114 115 115 $permalink = apply_filters('pre_post_link', $permalink, $post, $leavename); 116 116 117 if ( '' != $permalink && !in_array($post->post_status, array ('draft', 'pending', 'auto-draft')) ) {117 if ( '' != $permalink && !in_array($post->post_status, array_merge( array('auto-draft'), get_post_stati( array( 'moderation' => true, 'post_type' => $post->post_type )) ) ) ) { 118 118 $unixtime = strtotime($post->post_date); 119 119 120 120 $category = ''; -
wp-includes/script-loader.php
390 390 'update' => __('Update'), 391 391 'savePending' => __('Save as Pending'), 392 392 'saveDraft' => __('Save Draft'), 393 // @todo these needed to be loaded later than init[0]. custom stati aren't loaded otherwise 394 'postStati' => get_post_stati( array( 'post_type' => get_post_type() ), 'objects' ), 393 395 'private' => __('Private'), 394 396 'public' => __('Public'), 395 397 'publicSticky' => __('Public, Sticky'),