Skip to:
Content

bbPress.org

Changeset 5730


Ignore:
Timestamp:
05/12/2015 10:00:47 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Common: Additional type-casting in query functions.

Ensures direct query results return a consistent, testable value.

Props thebrandonallen, netweb. See #2801.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/functions.php

    r5718 r5730  
    15291529        $post_status = "'" . implode( "', '", $post_status ) . "'";
    15301530
    1531         $child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) );
     1531        $child_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) );
    15321532        wp_cache_set( $cache_id, $child_id, 'bbpress_posts' );
    15331533    }
    15341534
    15351535    // Filter and return
    1536     return apply_filters( 'bbp_get_public_child_last_id', (int) $child_id, $parent_id, $post_type );
     1536    return (int) apply_filters( 'bbp_get_public_child_last_id', $child_id, $parent_id, $post_type );
    15371537}
    15381538
     
    15771577        $post_status = "'" . implode( "', '", $post_status ) . "'";
    15781578
    1579         $child_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) );
     1579        $child_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) );
    15801580        wp_cache_set( $cache_id, $child_count, 'bbpress_posts' );
    15811581    }
    15821582
    15831583    // Filter and return
    1584     return apply_filters( 'bbp_get_public_child_count', (int) $child_count, $parent_id, $post_type );
     1584    return (int) apply_filters( 'bbp_get_public_child_count', $child_count, $parent_id, $post_type );
    15851585}
    15861586
     
    16251625        $post_status = "'" . implode( "', '", $post_status ) . "'";
    16261626
    1627         $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
     1627        $child_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
    16281628        wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' );
    16291629    }
    16301630
    16311631    // Filter and return
    1632     return apply_filters( 'bbp_get_public_child_ids', $child_ids, $parent_id, $post_type );
     1632    return (array) apply_filters( 'bbp_get_public_child_ids', $child_ids, $parent_id, $post_type );
    16331633}
    16341634
     
    16891689        $post_status = "'" . implode( "', '", $post_status ) . "'";
    16901690
    1691         $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
     1691        $child_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
    16921692        wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' );
    16931693    }
    16941694
    16951695    // Filter and return
    1696     return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type );
     1696    return (array) apply_filters( 'bbp_get_all_child_ids', $child_ids, $parent_id, $post_type );
    16971697}
    16981698
Note: See TracChangeset for help on using the changeset viewer.