Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/25/2014 03:33:45 PM (10 years ago)
Author:
boonebgorges
Message:

Improve matching between active component status and directory page status.

  • When a directory page is deleted, delete the corresponding entry from bp_pages. This ensures that the admin will see the admin_notice that a page mapping is missing.
  • When pulling up page mappings with bp_core_get_directory_page_ids(), remove entries corresponding to deleted pages and deactivated components.

Props Mamaduka.
Fixes #5681.

File:
1 edited

Legend:

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

    r9012 r9177  
    382382        foreach( (array) $page_ids as $component_name => $page_id ) {
    383383            if ( empty( $component_name ) || empty( $page_id ) ) {
    384                 unset( $page_ids[$component_name] );
     384                unset( $page_ids[ $component_name ] );
     385            }
     386
     387            if ( ! bp_is_active( $component_name ) || 'trash' == get_post_status( $page_id ) ) {
     388                unset( $page_ids[ $component_name ] );
    385389            }
    386390        }
     
    566570    }
    567571}
     572
     573/**
     574 * Remove the entry from bp_pages when the corresponding WP page is deleted.
     575 *
     576 * @since BuddyPress (2.2.0)
     577 *
     578 * @param int $post_id Post ID.
     579 */
     580function bp_core_on_directory_page_delete( $post_id ) {
     581    $page_ids = bp_core_get_directory_page_ids();
     582    $component_name = array_search( $post_id, $page_ids );
     583
     584    if ( ! empty( $component_name ) ) {
     585        unset( $page_ids[ $component_name ] );
     586    }
     587
     588    bp_core_update_directory_page_ids( $page_ids );
     589}
     590add_action( 'delete_post', 'bp_core_on_directory_page_delete' );
    568591
    569592/**
Note: See TracChangeset for help on using the changeset viewer.