Ticket #12706: 12706.db.1.diff
File 12706.db.1.diff, 17.4 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
123 123 register_post_status( 'draft', array( 124 124 'label' => _x( 'Draft', 'post' ), 125 125 'protected' => true, 126 'moderation' => true, 126 127 '_builtin' => true, /* internal use only. */ 127 128 'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), 129 'show_in_admin_status_dropdown' => true, 128 130 ) ); 129 131 130 132 register_post_status( 'pending', array( 131 133 'label' => _x( 'Pending', 'post' ), 132 134 'protected' => true, 135 'moderation' => true, 133 136 '_builtin' => true, /* internal use only. */ 134 137 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), 138 'show_in_admin_status_dropdown' => true, 135 139 ) ); 136 140 137 141 register_post_status( 'private', array( … … 673 677 } 674 678 675 679 /** 680 * WordPress Post Status class. 681 * 682 * @since 3.6.0 683 * 684 */ 685 final class WP_Post_Status { 686 687 /** 688 * 689 * @var string 690 */ 691 public $name = ''; 692 693 /** 694 * 695 * @var string 696 */ 697 public $label = false; 698 699 /** 700 * 701 * @var array 702 */ 703 public $label_count = false; 704 705 /** 706 * 707 * @var labels 708 */ 709 public $labels = null; 710 711 /** 712 * 713 * @var bool 714 */ 715 public $exclude_from_search = null; 716 717 /** 718 * 719 * @var bool 720 */ 721 public $_builtin = false; 722 723 /** 724 * 725 * @var bool 726 */ 727 public $public = null; 728 729 /** 730 * 731 * @var bool 732 */ 733 public $internal = null; 734 735 /** 736 * 737 * @var bool 738 */ 739 public $protected = null; 740 741 /** 742 * 743 * @var bool 744 */ 745 public $moderation = null; 746 747 /** 748 * 749 * @var bool 750 */ 751 public $private = null; 752 753 /** 754 * 755 * @var array 756 */ 757 public $post_type = null; 758 759 /** 760 * 761 * @var bool 762 */ 763 public $publicly_queryable = null; 764 765 /** 766 * 767 * @var bool 768 */ 769 public $show_in_admin_status_list = null; 770 771 /** 772 * 773 * @var bool 774 */ 775 public $show_in_admin_all_list = null; 776 777 /** 778 * 779 * @var bool 780 */ 781 public $show_in_admin_status_dropdown = false; 782 783 public function __construct( $post_status, $args = array() ) { 784 785 $args = (object) $args; 786 foreach ( get_object_vars( $args ) as $key => $value ) 787 $this->$key = $value; 788 789 $this->name = sanitize_key( $post_status ); 790 791 if ( null === $this->public && null === $this->internal && null === $this->protected && null === $this->private && null === $this->moderation ) 792 $this->internal = true; 793 794 if ( null === $this->public ) 795 $this->public = false; 796 797 if ( null === $this->private ) 798 $this->private = false; 799 800 if ( null === $this->protected ) 801 $this->protected = false; 802 803 if ( null === $this->moderation ) 804 $this->moderation = false; 805 806 if ( null === $this->internal ) 807 $this->internal = false; 808 809 if ( null === $this->publicly_queryable ) 810 $this->publicly_queryable = $this->public; 811 812 if ( null === $this->exclude_from_search ) 813 $this->exclude_from_search = $this->internal; 814 815 if ( null === $this->show_in_admin_all_list ) 816 $this->show_in_admin_all_list = !$this->internal; 817 818 if ( null === $this->show_in_admin_status_list ) 819 $this->show_in_admin_status_list = !$this->internal; 820 821 if ( null === $this->show_in_admin_status_dropdown ) 822 $this->show_in_admin_status_dropdown = $this->moderation; 823 824 if ( false === $this->label ) 825 $this->label = $post_status; 826 827 if ( false === $this->label_count ) 828 $this->label_count = array( $this->label, $this->label ); 829 830 if ( is_string( $this->post_type ) ) 831 $this->post_type = array( $this->post_type ); 832 } 833 } 834 835 /** 676 836 * Retrieve ancestors of a post. 677 837 * 678 838 * @since 2.5.0 … … 920 1080 * @param array|string $args See above description. 921 1081 */ 922 1082 function register_post_status($post_status, $args = array()) { 923 global $wp_post_statuses ;1083 global $wp_post_statuses, $wp_post_types; 924 1084 925 1085 if (!is_array($wp_post_statuses)) 926 1086 $wp_post_statuses = array(); 927 1087 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; 1088 $args = new WP_Post_Status( $post_status, $args ); 1089 $wp_post_statuses[ $post_status ] = $args; 944 1090 945 $post_status = sanitize_key($post_status); 946 $args->name = $post_status; 1091 // Add status to already registered post types 1092 if ( ! empty( $wp_post_types ) ) 1093 foreach ( $wp_post_types as $key => $post_type ) { 1094 if ( ! empty( $args->post_type ) && ! in_array( $key, $args->post_type ) ) 1095 continue; 947 1096 948 if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) 949 $args->internal = true; 1097 if ( ! array_key_exists( $post_status, $post_type->statuses ) ) 1098 $wp_post_types[ $key ]->statuses[ $post_status ] = $args; 1099 } 950 1100 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 1101 return $args; 984 1102 } 985 1103 … … 996 1114 * @param string $post_status The name of a registered post status 997 1115 * @return object A post status object 998 1116 */ 999 function get_post_status_object( $post_status ) {1117 function get_post_status_object( $post_status, $object_type = null ) { 1000 1118 global $wp_post_statuses; 1001 1119 1002 if ( empty($wp_post_statuses[$post_status]) ) 1003 return null; 1120 $status_object = null; 1004 1121 1005 return $wp_post_statuses[$post_status]; 1122 if ( $object_type ) { 1123 $post_type = get_post_type_object( $object_type ); 1124 if ( $post_type && ! empty( $post_type->statuses[ $post_status ] ) ) 1125 $status_object = $post_type->statuses[ $post_status ]; 1126 } 1127 1128 if ( ! empty( $wp_post_statuses[ $post_status ] ) ) 1129 $status = $wp_post_statuses[ $post_status ]; 1130 1131 // Search across all post types 1132 foreach ( get_post_types( array(), 'objects' ) as $post_type ) { 1133 if ( ! empty( $post_type->statuses[ $post_status ] ) ) { 1134 $status_object = $post_type->statuses[ $post_status ]; 1135 break; 1136 } 1137 } 1138 1139 return $status_object; 1006 1140 } 1007 1141 1008 1142 /** … … 1026 1160 1027 1161 $field = ('names' == $output) ? 'name' : false; 1028 1162 1029 return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); 1163 $statuses = $wp_post_statuses; 1164 1165 if ( ! empty( $args['post_type'] ) ) { 1166 $post_type = get_post_type_object( $args['post_type'] ); 1167 if ( $post_type && ! empty( $post_type->statuses ) ) 1168 $statuses = $post_type->statuses; 1169 1170 unset( $args['post_type'] ); 1171 } 1172 1173 return wp_filter_object_list( $statuses, $args, $operator, $field ); 1030 1174 } 1031 1175 1032 1176 /** … … 1211 1355 * @return object|WP_Error the registered post type object, or an error object 1212 1356 */ 1213 1357 function register_post_type( $post_type, $args = array() ) { 1214 global $wp_post_types, $wp_rewrite, $wp ;1358 global $wp_post_types, $wp_rewrite, $wp, $wp_post_statuses; 1215 1359 1216 1360 if ( !is_array($wp_post_types) ) 1217 1361 $wp_post_types = array(); … … 1227 1371 'can_export' => true, 1228 1372 'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 1229 1373 'delete_with_user' => null, 1374 'statuses' => null, 1230 1375 ); 1231 1376 $args = wp_parse_args($args, $defaults); 1232 1377 $args = (object) $args; … … 1336 1481 if ( $args->register_meta_box_cb ) 1337 1482 add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); 1338 1483 1484 if ( null === $args->statuses ) 1485 $args->statuses = array(); 1486 1487 foreach ( $args->statuses as $post_status => $post_status_args ) 1488 $args->statuses[ $post_status ] = new WP_Post_Status( $post_status, $post_status_args ); 1489 1490 // Legacy post statuses 1491 if ( ! empty( $wp_post_statuses ) ) 1492 foreach ( $wp_post_statuses as $key => $post_status ) 1493 if ( empty( $args->statuses[ $key ] ) ) 1494 $args->statuses[ $key ] = $post_status; 1495 1339 1496 $args->labels = get_post_type_labels( $args ); 1340 1497 $args->label = $args->labels->name; 1341 1498 … … 2142 2299 $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2143 2300 2144 2301 $stats = array(); 2145 foreach ( get_post_stati( ) as $state )2302 foreach ( get_post_stati( array( 'post_type' => $type ) ) as $state ) 2146 2303 $stats[$state] = 0; 2147 2304 2148 2305 foreach ( (array) $count as $row ) … … 2736 2893 if ( empty($post_type) ) 2737 2894 $post_type = 'post'; 2738 2895 2739 if ( empty($post_status) ) 2740 $post_status = 'draft'; 2896 if ( empty($post_status) ) { 2897 $post_status = array_shift( get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ); 2898 } 2741 2899 2742 2900 if ( !empty($post_category) ) 2743 2901 $post_category = array_filter($post_category); // Filter out empty terms … … 2767 2925 if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) 2768 2926 $post_name = ''; 2769 2927 2770 // Create a valid post name. Drafts and pending posts are allowed to have an empty 2771 // post name. 2928 // Create a valid post name. Posts in moderation are allowed to have an empty post_name 2772 2929 if ( empty($post_name) ) { 2773 if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 2930 if ( 'auto-draft' != $post_status 2931 && ! in_array( $post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) 2774 2932 $post_name = sanitize_title($post_title); 2775 2933 else 2776 2934 $post_name = ''; … … 2800 2958 } 2801 2959 2802 2960 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' ) ) ) 2961 if ( 'auto-draft' != $post_status 2962 && ! in_array( $post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) 2804 2963 $post_date_gmt = get_gmt_from_date($post_date); 2805 2964 else 2806 2965 $post_date_gmt = '0000-00-00 00:00:00'; … … 2895 3054 $where = array( 'ID' => $post_ID ); 2896 3055 } 2897 3056 2898 if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 3057 if ( empty($data['post_name']) 3058 && 'auto-draft' != $data['post_status'] 3059 && ! in_array( $data['post_status'], get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) { 2899 3060 $data['post_name'] = sanitize_title($data['post_title'], $post_ID); 2900 3061 $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); 2901 3062 } … … 2985 3146 else 2986 3147 $post_cats = $post['post_category']; 2987 3148 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']) ) 3149 // Moderation posts shouldn't be assigned a date unless explicitly done so by the user 3150 if ( isset( $post['post_status'] ) 3151 && ( 'auto-draft' == $post['post_status'] || in_array( $post['post_status'], get_post_stati( array( 'moderation' => true, 'post_type' => $post['post_type'] ) ) ) ) 3152 && empty($postarr['edit_date']) 3153 && ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) 2991 3154 $clear_date = true; 2992 3155 else 2993 3156 $clear_date = false; … … 3084 3247 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 3085 3248 */ 3086 3249 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') ) )3250 if ( 'auto-draft' == $post_status || in_array( $post_status, get_post_stati( array( 'moderation' => true, 'post_type' => $post_type ) ) ) ) 3088 3251 return $slug; 3089 3252 3090 3253 global $wpdb, $wp_rewrite; … … 3646 3809 // Make sure we have a valid post status 3647 3810 if ( !is_array( $post_status ) ) 3648 3811 $post_status = explode( ',', $post_status ); 3649 if ( array_diff( $post_status, get_post_stati( ) ) )3812 if ( array_diff( $post_status, get_post_stati( array( 'post_type' => $post_type ) ) ) ) 3650 3813 return $pages; 3651 3814 3652 3815 // $args can be whatever, only use the args defined in defaults to compute the key -
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 ) ) ) ) 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' ); … … 554 554 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>"; 555 555 } 556 556 if ( $post_type_object->public ) { 557 if ( in_array( $post->post_status, array( 'pending', 'draft', 'future') ) ) {557 if ( in_array( $post->post_status, get_post_stati( array( 'protected' => true ) ) ) ) { 558 558 if ( $can_edit_post ) 559 559 $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>'; 560 560 } elseif ( 'trash' != $post->post_status ) { … … 592 592 else 593 593 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>'; 594 594 echo '<br />'; 595 if ( 'publish' == $post->post_status) {595 if ( in_array( $post->post_status, get_post_stati( array( 'public' => true ), $post->post_type ) ) ) { 596 596 _e( 'Published' ); 597 597 } elseif ( 'future' == $post->post_status ) { 598 598 if ( $time_diff > 0 ) … … 954 954 <label class="inline-edit-status alignleft"> 955 955 <span class="title"><?php _e( 'Status' ); ?></span> 956 956 <select name="_status"> 957 <?php if ( $bulk ) : ?> 958 <option value="-1"><?php _e( '— No Change —' ); ?></option> 959 <?php endif; // $bulk ?> 960 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?> 961 <option value="publish"><?php _e( 'Published' ); ?></option> 962 <option value="future"><?php _e( 'Scheduled' ); ?></option> 963 <?php if ( $bulk ) : ?> 964 <option value="private"><?php _e( 'Private' ) ?></option> 965 <?php endif; // $bulk ?> 966 <?php endif; ?> 967 <option value="pending"><?php _e( 'Pending Review' ); ?></option> 968 <option value="draft"><?php _e( 'Draft' ); ?></option> 957 <?php 958 $statuses = array(); 959 if ( $bulk ) 960 $statuses['-1'] = _e( '— No Change —' ); 961 if ( $can_publish ) { 962 $public_stati = get_post_stati( array( 'public' => true, 'post_type' => $screen->post_type ), 'objects' ); 963 foreach( $public_stati as $status ) { 964 $statuses[$status->name] = $status->label; 965 } 966 if ( $bulk ) { 967 $private_stati = get_post_stati( array( 'private' => true, 'post_type' => $screen->post_type ), 'objects' ); 968 foreach( $private_stati as $status ) { 969 $statuses[$status->name] = $status->label; 970 } 971 } 972 } 973 $moderation_stati = get_post_stati( array( 'moderation' => true, 'post_type' => $screen->post_type ), 'objects' ); 974 foreach( $moderation_stati as $status ) { 975 $statuses[$status->name] = $status->label; 976 } 977 foreach( $statuses as $status_key => $status_label ) : ?> 978 <option value="<?php echo esc_attr( $status_key ); ?>"><?php echo esc_html( $status_label ); ?></option> 979 <?php endforeach; ?> 969 980 </select> 970 981 </label> 971 982