Skip to:
Content

BuddyPress.org

Changeset 11513


Ignore:
Timestamp:
03/16/2017 03:49:08 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Core: Make sure trashed activate and register pages are unset in bp_core_get_directory_page_ids().

This flips the order of 2 conditions, which incorrectly included trashed pages for the activate & register components.

In addition, normalize the return value & type-casting of bp_core_get_directory_page_ids() to ensure it is always an array, even if an empty one.

Fixes #7469.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/bp-core-admin-functions.php

    r11390 r11513  
    315315    // BP components cannot share a single WP page. Check for duplicate assignments, and post a message if found.
    316316    $dupe_names = array();
    317     $page_ids   = (array)bp_core_get_directory_page_ids();
     317    $page_ids   = bp_core_get_directory_page_ids();
    318318    $dupes      = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
    319319
  • trunk/src/bp-core/bp-core-cache.php

    r11447 r11513  
    7474 * @param int $post_id ID of the page that was saved.
    7575 */
    76 function bp_core_clear_directory_pages_cache_page_edit( $post_id ) {
    77     if ( ! bp_is_root_blog() ) {
    78         return;
    79     }
     76function bp_core_clear_directory_pages_cache_page_edit( $post_id = 0 ) {
    8077
    8178    // Bail if BP is not defined here.
     
    8481    }
    8582
     83    // Bail if not on the root blog
     84    if ( ! bp_is_root_blog() ) {
     85        return;
     86    }
     87
    8688    $page_ids = bp_core_get_directory_page_ids( 'all' );
    8789
    88     if ( ! in_array( $post_id, (array) $page_ids ) ) {
     90    // Bail if post ID is not a directory page
     91    if ( ! in_array( $post_id, $page_ids ) ) {
    8992        return;
    9093    }
  • trunk/src/bp-core/bp-core-functions.php

    r11447 r11513  
    489489 */
    490490function bp_core_get_directory_page_ids( $status = 'active' ) {
    491     $page_ids = bp_get_option( 'bp-pages' );
    492 
    493     // Ensure that empty indexes are unset. Should only matter in edge cases.
    494     if ( !empty( $page_ids ) && is_array( $page_ids ) ) {
    495         foreach( (array) $page_ids as $component_name => $page_id ) {
    496             if ( empty( $component_name ) || empty( $page_id ) ) {
    497                 unset( $page_ids[ $component_name ] );
    498             }
    499 
    500             // 'register' and 'activate' do not have components, but should be whitelisted.
    501             if ( 'register' === $component_name || 'activate' === $component_name ) {
    502                 continue;
    503             }
    504 
    505             // Trashed pages should not appear in results.
    506             if ( 'trash' == get_post_status( $page_id ) ) {
    507                 unset( $page_ids[ $component_name ] );
    508 
    509             }
    510 
    511             // Remove inactive component pages, if required.
    512             if ( 'active' === $status && ! bp_is_active( $component_name ) ) {
    513                 unset( $page_ids[ $component_name ] );
    514             }
     491    $page_ids = bp_get_option( 'bp-pages', array() );
     492
     493    // Loop through pages
     494    foreach ( $page_ids as $component_name => $page_id ) {
     495
     496        // Ensure that empty indexes are unset. Should only matter in edge cases.
     497        if ( empty( $component_name ) || empty( $page_id ) ) {
     498            unset( $page_ids[ $component_name ] );
    515499        }
     500
     501        // Trashed pages should never appear in results.
     502        if ( 'trash' == get_post_status( $page_id ) ) {
     503            unset( $page_ids[ $component_name ] );
     504        }
     505
     506        // 'register' and 'activate' do not have components, but should be whitelisted.
     507        if ( in_array( $component_name, array( 'register', 'activate' ), true ) ) {
     508            continue;
     509        }
     510
     511        // Remove inactive component pages.
     512        if ( ( 'active' === $status ) && ! bp_is_active( $component_name ) ) {
     513            unset( $page_ids[ $component_name ] );
     514        }
    516515    }
    517516
     
    520519     *
    521520     * @since 1.5.0
    522      *
    523      * @param array $page_ids Array of directory pages.
    524      */
    525     return apply_filters( 'bp_core_get_directory_page_ids', $page_ids );
     521     * @since 2.9.0 Add $status parameter
     522     *
     523     * @param array  $page_ids Array of directory pages.
     524     * @param string $status   Page status to limit results to
     525     */
     526    return (array) apply_filters( 'bp_core_get_directory_page_ids', $page_ids, $status );
    526527}
    527528
     
    663664    // Delete any existing pages.
    664665    if ( 'delete' === $existing ) {
    665         foreach ( (array) $pages as $page_id ) {
     666        foreach ( $pages as $page_id ) {
    666667            wp_delete_post( $page_id, true );
    667668        }
     
    889890    }
    890891
    891     $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids( 'all' ) );
     892    $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) );
    892893    bp_core_update_directory_page_ids( $page_ids );
    893894}
  • trunk/tests/phpunit/testcases/admin/functions.php

    r10972 r11513  
    145145        ) ) );
    146146
    147         $page_ids = array_merge( $new_page_ids, (array) bp_core_get_directory_page_ids( 'all' ) );
     147        $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) );
    148148        bp_core_update_directory_page_ids( $page_ids );
    149149
Note: See TracChangeset for help on using the changeset viewer.