Make WordPress Core

Ticket #35603: 35603.diff

File 35603.diff, 1.0 KB (added by flixos90, 11 years ago)

patch to fix wp_count_posts() on multisite after switching

  • src/wp-includes/post.php

     
    22042204function wp_count_posts( $type = 'post', $perm = '' ) {
    22052205        global $wpdb;
    22062206
    2207         if ( ! post_type_exists( $type ) )
     2207        if ( ! post_type_exists( $type ) && ( ! is_multisite() || empty( $GLOBALS['_wp_switched_stack'] ) ) )
    22082208                return new stdClass;
    22092209
    22102210        $cache_key = _count_posts_cache_key( $type, $perm );
    … …  
    22182218        $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    22192219        if ( 'readable' == $perm && is_user_logged_in() ) {
    22202220                $post_type_object = get_post_type_object($type);
    2221                 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
     2221                if ( ! $post_type_object || ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
    22222222                        $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
    22232223                                get_current_user_id()
    22242224                        );