Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/10/2015 03:24:04 PM (10 years ago)
Author:
boonebgorges
Message:

bp_core_get_directory_page_ids() should skip bp_is_active() check in save context.

In [9177], a bp_is_active() check was added to bp_core_get_directory_page_ids()
such that the function would not return page mappings for inactive components.
This change caused problems for custom components, as the bp_is_active()
check didn't always pass for components that didn't manually set themselves in
the active_components array. [9553] and [9555] addressed this problem by only
filtering out packaged components. See #6244. But this fix was not truly
general, as it still resulted in the deletion of bp-pages entries related to
third-party deactivated components when saving the page mapping settings.

This changeset introduces a more general fix, by distinguishing between two
different use "contexts" of bp_core_get_directory_page_ids():

  • Read-only - When pulling up page IDs for display or for URI parsing, deactivated components should be ignored.
  • Save - When modifying the bp-pages array stored in the database, we should be working with raw page data, including deactivated components.

The new $status parameter for bp_core_get_directory_page_ids() addresses
this distinction (possible values 'all' and 'active'). We then pass 'all' as
required in BP - namely, when modifying the bp-pages setting. This change
supercedes the fixes from #6244.

Props dtc7240, boonebgorges.
Fixes #6280.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/src/bp-core/bp-core-functions.php

    r9505 r9609  
    419419 * @since BuddyPress (1.5.0)
    420420 *
     421 * @param string $status 'active' to return only pages associated with active components, 'all' to return all saved
     422 *                       pages. When running save routines, use 'all' to avoid removing data related to inactive
     423 *                       components. Default: 'active'.
    421424 * @return array|string An array of page IDs, keyed by component names, or an
    422  *         empty string if the list is not found.
    423  */
    424 function bp_core_get_directory_page_ids() {
     425 *                      empty string if the list is not found.
     426 */
     427function bp_core_get_directory_page_ids( $status = 'active' ) {
    425428    $page_ids = bp_get_option( 'bp-pages' );
    426429
     
    437440            }
    438441
    439             if ( ! bp_is_active( $component_name ) || 'trash' == get_post_status( $page_id ) ) {
     442            // Trashed pages should not appear in results.
     443            if ( 'trash' == get_post_status( $page_id ) ) {
     444                unset( $page_ids[ $component_name ] );
     445
     446            }
     447
     448            // Remove inactive component pages, if required.
     449            if ( 'active' === $status && ! bp_is_active( $component_name ) ) {
    440450                unset( $page_ids[ $component_name ] );
    441451            }
     
    549559    }
    550560
    551     $pages = bp_core_get_directory_page_ids();
     561    $pages = bp_core_get_directory_page_ids( 'all' );
    552562
    553563    // Delete any existing pages
     
    640650    }
    641651
    642     $page_ids       = bp_core_get_directory_page_ids();
     652    $page_ids       = bp_core_get_directory_page_ids( 'all' );
    643653    $component_name = array_search( $post_id, $page_ids );
    644654
     
    746756    }
    747757
    748     $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids() );
     758    $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids( 'all' ) );
    749759    bp_core_update_directory_page_ids( $page_ids );
    750760}
Note: See TracChangeset for help on using the changeset viewer.