Changeset 27081 for trunk/src/wp-includes/post.php
- Timestamp:
- 02/03/2014 07:41:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r26911 r27081 2078 2078 2079 2079 /** 2080 * Return the cache key for wp_count_posts() based on the passed arguments 2081 * 2082 * @since 3.9.0 2083 * 2084 * @param string $type Optional. Post type to retrieve count 2085 * @param string $perm Optional. 'readable' or empty. 2086 * @return string The cache key. 2087 */ 2088 function _count_posts_cache_key( $type = 'post', $perm = '' ) { 2089 $cache_key = 'posts-' . $type; 2090 if ( 'readable' == $perm && is_user_logged_in() ) { 2091 $post_type_object = get_post_type_object( $type ); 2092 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { 2093 $cache_key .= '_' . $perm . '_' . get_current_user_id(); 2094 } 2095 } 2096 return $cache_key; 2097 } 2098 2099 /** 2080 2100 * Count number of posts of a post type and if user has permissions to view. 2081 2101 * … … 2102 2122 return new stdClass; 2103 2123 2104 $user = wp_get_current_user(); 2105 2106 $cache_key = 'posts-' . $type; 2124 $cache_key = _count_posts_cache_key( $type, $perm ); 2107 2125 2108 2126 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2109 2127 if ( 'readable' == $perm && is_user_logged_in() ) { 2110 2128 $post_type_object = get_post_type_object($type); 2111 if ( !current_user_can( $post_type_object->cap->read_private_posts ) ) { 2112 $cache_key .= '_' . $perm . '_' . $user->ID; 2113 $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))"; 2129 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { 2130 $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", 2131 get_current_user_id() 2132 ); 2114 2133 } 2115 2134 } … … 4886 4905 } 4887 4906 4907 if ( $new_status !== $old_status ) { 4908 wp_cache_delete( _count_posts_cache_key( $post->post_type ), 'counts' ); 4909 wp_cache_delete( _count_posts_cache_key( $post->post_type, 'readable' ), 'counts' ); 4910 } 4911 4888 4912 // Always clears the hook in case the post status bounced from future to draft. 4889 4913 wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) );
Note: See TracChangeset
for help on using the changeset viewer.