Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/19/2017 03:25:37 AM (7 years ago)
Author:
johnjamesjacoby
Message:

in_array(): be strict whenever possible.

Use wp_parse_id_list() on certain array values to ensure proper results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/extend/buddypress/functions.php

    r6370 r6415  
    341341    }
    342342
    343     // Make sure result is an array
    344     if ( ! is_array( $forum_ids ) ) {
    345         $forum_ids = (array) $forum_ids;
    346     }
    347 
    348     // Trim out any empty array items
    349     $forum_ids = array_filter( $forum_ids );
    350 
     343    // Make sure result is an array of ints
     344    $forum_ids = array_filter( wp_parse_id_list( $forum_ids ) );
     345
     346    // Filter & return
    351347    return (array) apply_filters( 'bbp_get_group_forum_ids', $forum_ids, $group_id );
    352348}
     
    373369    }
    374370
    375     // Make sure result is an array
    376     if ( ! is_array( $group_ids ) ) {
    377         $group_ids = (array) $group_ids;
    378     }
    379 
    380     // Trim out any empty array items
    381     $group_ids = array_filter( $group_ids );
    382 
     371    // Make sure result is an array of ints
     372    $group_ids = array_filter( wp_parse_id_list( $group_ids ) );
     373
     374    // Filter & return
    383375    return (array) apply_filters( 'bbp_get_forum_group_ids', $group_ids, $forum_id );
    384376}
     
    398390
    399391    // Trim out any empties
    400     $forum_ids = array_filter( $forum_ids );
     392    $forum_ids = array_filter( wp_parse_id_list( $forum_ids ) );
    401393
    402394    // Get the forums
     
    414406
    415407    // Trim out any empties
    416     $group_ids = array_filter( $group_ids );
     408    $group_ids = array_filter( wp_parse_id_list( $group_ids ) );
    417409
    418410    // Get the forums
     
    440432
    441433    // Maybe update the groups forums
    442     if ( ! in_array( $group_id, $group_ids ) ) {
     434    if ( ! in_array( $group_id, $group_ids, true ) ) {
    443435        $group_ids[] = $group_id;
    444436        return bbp_update_forum_group_ids( $forum_id, $group_ids );
     
    466458
    467459    // Maybe update the groups forums
    468     if ( ! in_array( $forum_id, $forum_ids ) ) {
     460    if ( ! in_array( $forum_id, $forum_ids, true ) ) {
    469461        $forum_ids[] = $forum_id;
    470462        return bbp_update_group_forum_ids( $group_id, $forum_ids );
     
    492484
    493485    // Maybe update the groups forums
    494     if ( in_array( $group_id, $group_ids ) ) {
     486    if ( in_array( $group_id, $group_ids, true ) ) {
    495487        $group_ids = array_diff( array_values( $group_ids ), (array) $group_id );
    496488        return bbp_update_forum_group_ids( $forum_id, $group_ids );
     
    518510
    519511    // Maybe update the groups forums
    520     if ( in_array( $forum_id, $forum_ids ) ) {
     512    if ( in_array( $forum_id, $forum_ids, true ) ) {
    521513        $forum_ids = array_diff( array_values( $forum_ids ), (array) $forum_id );
    522514        return bbp_update_group_forum_ids( $group_id, $forum_ids );
     
    541533
    542534    // Loop through forums and remove this group from each one
    543     foreach ( (array) $forum_ids as $forum_id ) {
     535    foreach ( $forum_ids as $forum_id ) {
    544536        bbp_remove_group_id_from_forum( $group_id, $forum_id );
    545537    }
     
    559551
    560552    // Loop through groups and remove this forum from each one
    561     foreach ( (array) $group_ids as $group_id ) {
     553    foreach ( $group_ids as $group_id ) {
    562554        bbp_remove_forum_id_from_group( $forum_id, $group_id );
    563555    }
Note: See TracChangeset for help on using the changeset viewer.