Changeset 13172
- Timestamp:
- 02/16/2010 09:13:44 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/edit.php
r13100 r13172 233 233 $status_links[] = "<li><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>'; 234 234 235 foreach ( get_post_stati(array('show_in_admin_ edit' => true), 'objects') as $status ) {235 foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) { 236 236 $class = ''; 237 237 -
trunk/wp-includes/post.php
r13101 r13172 71 71 72 72 register_post_status( 'future', array( 'label' => _x('Scheduled', 'post'), 73 'p ublic' => true,73 'protected' => true, 74 74 '_builtin' => true, 75 75 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>') … … 77 77 78 78 register_post_status( 'draft', array( 'label' => _x('Draft', 'post'), 79 'p ublic' => true,79 'protected' => true, 80 80 '_builtin' => true, 81 81 'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>') 82 82 ) ); 83 83 84 register_post_status( 'pending', array( 'label' => _x('Pending', 'post'), 85 'protected' => true, 86 '_builtin' => true, 87 'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>') 88 ) ); 89 84 90 register_post_status( 'private', array( 'label' => _x('Private', 'post'), 85 'p ublic' => true,91 'private' => true, 86 92 '_builtin' => true, 87 93 'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>') … … 89 95 90 96 register_post_status( 'trash', array( 'label' => _x('Trash', 'post'), 91 ' public' => true,92 ' exclude_from_search' => true,97 'internal' => true, 98 'show_in_admin_status_list' => true, 93 99 '_builtin' => true, 94 100 'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>') … … 96 102 97 103 register_post_status( 'auto-draft', array( 'label' => _x('Auto-Draft', 'post'), 98 'public' => false, 99 'exclude_from_search' => true, 104 'internal' => true, 100 105 '_builtin' => true, 101 106 'label_count' => _n_noop('Auto-Draft <span class="count">(%s)</span>', 'Auto-Drafts <span class="count">(%s)</span>') … … 527 532 528 533 // Args prefixed with an underscore are reserved for internal use. 529 $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' => false, 'publicly_queryable' => null, 'show_in_admin_edit' => null);534 $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); 530 535 $args = wp_parse_args($args, $defaults); 531 536 $args = (object) $args; … … 534 539 $args->name = $post_status; 535 540 536 // If not set, default to the setting for public. 541 if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) 542 $args->internal = true; 543 544 if ( null === $args->public ) 545 $args->public = false; 546 547 if ( null === $args->private ) 548 $args->private = false; 549 550 if ( null === $args->protected ) 551 $args->protected = false; 552 553 if ( null === $args->internal ) 554 $args->internal = false; 555 537 556 if ( null === $args->publicly_queryable ) 538 557 $args->publicly_queryable = $args->public; 539 558 540 // If not set, default to true if not public, false if public.541 559 if ( null === $args->exclude_from_search ) 542 $args->exclude_from_search = !$args->public; 543 544 // If not set, default to the setting for public. 545 if ( null === $args->show_in_admin_edit ) 546 $args->show_in_admin_edit = $args->public; 560 $args->exclude_from_search = $args->internal; 561 562 if ( null === $args->show_in_admin_all_list ) 563 $args->show_in_admin_all_list = !$args->internal; 564 565 if ( null === $args->show_in_admin_status_list ) 566 $args->show_in_admin_status_list = !$args->internal; 567 568 if ( null === $args->single_view_cap ) 569 $args->single_view_cap = $args->public ? '' : 'edit'; 547 570 548 571 if ( false === $args->label ) … … 592 615 * Only post statuses having attributes that match all arguments are returned. 593 616 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default. 617 * @param string $operator Whether the elements in $args should be logicallly 'or'ed or 'and'ed together. 'or' means only one element from the array needs to match. 'and' means all elements must match. The default is 'or'. 594 618 * @return array A list of post type names or objects 595 619 */ 596 function get_post_stati( $args = array(), $output = 'names' ) {620 function get_post_stati( $args = array(), $output = 'names', $operator = 'or' ) { 597 621 global $wp_post_statuses; 598 622 … … 600 624 if ( 'names' == $output ) 601 625 $do_names = true; 626 627 if ( 'and' == $operator ) 628 $arg_count = count($args); 629 else 630 $arg_count = 0; 602 631 603 632 $post_statuses = array(); … … 608 637 else 609 638 $post_statuses[] = $post_status; 610 } elseif ( array_intersect_assoc((array) $post_status, $args) ) { 639 } elseif ( $intersect = array_intersect_assoc((array) $post_status, $args) ) { 640 if ( $arg_count && ( $arg_count != count($intersect) ) ) 641 continue; 611 642 if ( $do_names ) 612 643 $post_statuses[] = $post_status->name; … … 788 819 if ( empty($args->read_cap) ) 789 820 $args->read_cap = 'read_' . $args->capability_type; 821 if ( empty($args->read_private_cap) ) 822 $args->read_private_cap = 'read_private_' . $args->capability_type . 's'; 790 823 if ( empty($args->delete_cap) ) 791 824 $args->delete_cap = 'delete_' . $args->capability_type; -
trunk/wp-includes/query.php
r13118 r13172 2062 2062 } 2063 2063 2064 if ( is_array($post_type) ) 2064 if ( is_array($post_type) ) { 2065 2065 $post_type_cap = 'multiple_post_type'; 2066 else {2066 } else { 2067 2067 $post_type_object = get_post_type_object ( $post_type ); 2068 2068 if ( !empty($post_type_object) ) … … 2082 2082 } elseif ( ! empty( $post_type ) ) { 2083 2083 $where .= " AND $wpdb->posts.post_type = '$post_type'"; 2084 $post_type_object = get_post_type_object ( $post_type ); 2084 2085 } elseif ( $this->is_attachment ) { 2085 2086 $where .= " AND $wpdb->posts.post_type = 'attachment'"; 2086 $post_type_ cap = 'post';2087 $post_type_object = get_post_type_object ( 'attachment' ); 2087 2088 } elseif ($this->is_page) { 2088 2089 $where .= " AND $wpdb->posts.post_type = 'page'"; 2089 $post_type_ cap = 'page';2090 $post_type_object = get_post_type_object ( 'page' ); 2090 2091 } else { 2091 2092 $where .= " AND $wpdb->posts.post_type = 'post'"; 2092 $post_type_cap = 'post'; 2093 $post_type_object = get_post_type_object ( 'post' ); 2094 } 2095 2096 if ( !empty($post_type_object) ) { 2097 $post_type_cap = $post_type_object->capability_type; 2098 $edit_cap = $post_type_object->edit_cap; 2099 $read_cap = $post_type_object->read_cap; 2100 $edit_others_cap = $post_type_object->edit_others_cap; 2101 $read_private_cap = $post_type_object->read_private_cap; 2102 } else { 2103 $edit_cap = 'edit_' . $post_type_cap; 2104 $read_cap = 'read_' . $post_type_cap; 2105 $edit_others_cap = 'edit_others_' . $post_type_cap . 's'; 2106 $read_private_cap = 'read_private_' . $post_type_cap . 's'; 2093 2107 } 2094 2108 … … 2122 2136 } 2123 2137 if ( !empty($r_status) ) { 2124 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can( "edit_others_{$post_type_cap}s") )2138 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) 2125 2139 $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))"; 2126 2140 else … … 2128 2142 } 2129 2143 if ( !empty($p_status) ) { 2130 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can( "read_private_{$post_type_cap}s") )2144 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) 2131 2145 $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))"; 2132 2146 else … … 2143 2157 $where .= " AND ($wpdb->posts.post_status = 'publish'"; 2144 2158 2145 if ( is_admin() ) 2146 $where .= " OR $wpdb->posts.post_status = 'future' OR $wpdb->posts.post_status = 'draft' OR $wpdb->posts.post_status = 'pending'"; 2159 // Add public states. 2160 $public_states = get_post_stati( array('public' => true) ); 2161 foreach ( (array) $public_states as $state ) { 2162 if ( 'publish' == $state ) // Publish is hard-coded above. 2163 continue; 2164 $where .= " OR $wpdb->posts.post_status = '$state'"; 2165 } 2166 2167 if ( is_admin() ) { 2168 // Add protected states that should show in the admin all list. 2169 $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true), 'names', 'and' ); 2170 foreach ( (array) $admin_all_states as $state ) 2171 $where .= " OR $wpdb->posts.post_status = '$state'"; 2172 } 2147 2173 2148 2174 if ( is_user_logged_in() ) { 2149 $where .= current_user_can( "read_private_{$post_type_cap}s" ) ? " OR $wpdb->posts.post_status = 'private'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = 'private'"; 2175 // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. 2176 $private_states = get_post_stati( array('private' => true) ); 2177 foreach ( (array) $private_states as $state ) 2178 $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = '$state'"; 2150 2179 } 2151 2180 … … 2297 2326 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { 2298 2327 $status = get_post_status($this->posts[0]); 2328 $post_status_obj = get_post_status_object($status); 2299 2329 //$type = get_post_type($this->posts[0]); 2300 if ( ('publish' != $status)) {2330 if ( !$post_status_obj->public ) { 2301 2331 if ( ! is_user_logged_in() ) { 2302 2332 // User must be logged in to view unpublished posts. 2303 2333 $this->posts = array(); 2304 2334 } else { 2305 if ( in_array($status, array('draft', 'pending', 'trash'))) {2335 if ( $post_status_obj->protected ) { 2306 2336 // User must have edit permissions on the draft to preview. 2307 if (! current_user_can( "edit_$post_type_cap", $this->posts[0]->ID)) {2337 if (! current_user_can($edit_cap, $this->posts[0]->ID)) { 2308 2338 $this->posts = array(); 2309 2339 } else { 2310 2340 $this->is_preview = true; 2311 $this->posts[0]->post_date = current_time('mysql'); 2341 if ('future' != $status) 2342 $this->posts[0]->post_date = current_time('mysql'); 2312 2343 } 2313 } else if ('future' == $status) { 2314 $this->is_preview = true; 2315 if (!current_user_can("edit_$post_type_cap", $this->posts[0]->ID)) { 2316 $this->posts = array ( ); 2317 } 2344 } elseif ( $post_status_obj->private ) { 2345 if ( ! current_user_can($read_cap, $this->posts[0]->ID) ) 2346 $this->posts = array(); 2318 2347 } else { 2319 if (! current_user_can("read_$post_type_cap", $this->posts[0]->ID)) 2320 $this->posts = array(); 2348 $this->posts = array(); 2321 2349 } 2322 2350 } 2323 2351 } 2324 2352 2325 if ( $this->is_preview && current_user_can( "edit_{$post_type_cap}", $this->posts[0]->ID ) )2353 if ( $this->is_preview && current_user_can( $edit_cap, $this->posts[0]->ID ) ) 2326 2354 $this->posts[0] = apply_filters('the_preview', $this->posts[0]); 2327 2355 }
Note: See TracChangeset
for help on using the changeset viewer.