Make WordPress Core

Ticket #24803: 24803.2.diff

File 24803.2.diff, 1.4 KB (added by johnpbloch, 11 years ago)
  • wp-includes/post.php

     
    20322032 * The $perm parameter checks for 'readable' value and if the user can read
    20332033 * private posts, it will display that for the user that is signed in.
    20342034 *
     2035 * This function will return a WP_Error object if the post type is invalid
     2036 *
    20352037 * @since 2.5.0
    20362038 * @link http://codex.wordpress.org/Template_Tags/wp_count_posts
    20372039 *
    20382040 * @param string $type Optional. Post type to retrieve count
    20392041 * @param string $perm Optional. 'readable' or empty.
    2040  * @return object Number of posts for each status
     2042 * @return object|WP_Error Number of posts for each status, WP_Error if $type is invalid
    20412043 */
    20422044function wp_count_posts( $type = 'post', $perm = '' ) {
    20432045        global $wpdb;
    20442046
     2047        if ( ! post_type_exists( $type ) ) {
     2048                return new WP_Error( 'invalid_post_type', __( 'Invalid post type' ) );
     2049        }
     2050
    20452051        $user = wp_get_current_user();
    20462052
    20472053        $cache_key = $type;
    20482054
    2049         $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
     2055        $query = "xSELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    20502056        if ( 'readable' == $perm && is_user_logged_in() ) {
    20512057                $post_type_object = get_post_type_object($type);
    20522058                if ( !current_user_can( $post_type_object->cap->read_private_posts ) ) {