Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/13/2011 09:54:52 PM (15 years ago)
Author:
boonebgorges
Message:

Introduces bp_do_404() for easy 404ing. Corrects invalid path handling throughout, using bp_do_404(). Fixes #3280. Props DJPaul

File:
1 edited

Legend:

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

    r4482 r4506  
    2424function bp_core_get_page_meta() {
    2525    $page_ids = get_site_option( 'bp-pages' );
    26    
     26
    2727    $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
    2828
     
    3030
    3131    // Upgrading from an earlier version of BP pre-1.3
    32     if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {       
    33         if ( empty( $page_ids ) ) {     
     32    if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {
     33        if ( empty( $page_ids ) ) {
    3434            // We're probably coming from an old multisite install
    3535            $old_page_ids = get_blog_option( $page_blog_id, 'bp-pages' );
     
    3838            $old_page_ids = $page_ids;
    3939        }
    40        
     40
    4141        /**
    4242         * If $page_ids is found in a blog_option, and it's formatted in the new way (keyed
     
    4646        if ( !isset( $old_page_ids['members'] ) )
    4747            return false;
    48            
     48
    4949        // Finally, move the page ids over to site options
    5050        $new_page_ids = array(
     
    5454        update_site_option( 'bp-pages', $new_page_ids );
    5555    }
    56    
     56
    5757    $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
    58    
     58
    5959    return apply_filters( 'bp_core_get_page_meta', $blog_page_ids );
    6060}
     
    6666 * blog_id. This allows you to change your BP_ROOT_BLOG and go through the setup process again.
    6767 *
    68  * @package BuddyPress Core 
     68 * @package BuddyPress Core
    6969 * @since 1.3
    7070 *
     
    7777    // Generally, we key by the BP_ROOT_BLOG. Exception: when BP_ENABLE_MULTIBLOG is turned on
    7878    $key = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    79    
     79
    8080    $page_ids[$key] = $blog_page_ids;
    8181
     
    162162function bp_core_do_network_admin() {
    163163    $do_network_admin = false;
    164    
     164
    165165    if ( is_multisite() && ( !defined( 'BP_ENABLE_MULTIBLOG' ) || !BP_ENABLE_MULTIBLOG ) )
    166166        $do_network_admin = true;
    167    
     167
    168168    return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
    169169}
     
    171171function bp_core_admin_hook() {
    172172    $hook = bp_core_do_network_admin() ? 'network_admin_menu' : 'admin_menu';
    173    
     173
    174174    return apply_filters( 'bp_core_admin_hook', $hook );
    175175}
     
    184184    if ( !is_super_admin() )
    185185        return false;
    186    
     186
    187187    add_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 );
    188188
     
    236236function bp_core_print_admin_notices() {
    237237    global $bp;
    238    
     238
    239239    // Only the super admin should see messages
    240240    if ( !is_super_admin() )
    241241        return;
    242    
     242
    243243    // On multisite installs, don't show on the Site Admin of a non-root blog, unless
    244244    // do_network_admin is overridden
    245245    if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
    246246        return;
    247        
     247
    248248    // Show the messages
    249249    if ( !empty( $bp->admin->notices ) ) {
     
    253253                <p><?php echo $notice ?></p>
    254254            <?php endforeach ?>
    255         </div>     
     255        </div>
    256256    <?php
    257257    }
     
    275275function bp_core_add_admin_notice( $notice ) {
    276276    global $bp;
    277    
     277
    278278    if ( empty( $bp->admin->notices ) ) {
    279279        $bp->admin->notices = array();
    280280    }
    281    
     281
    282282    $bp->admin->notices[] = $notice;
    283283}
     
    301301    if ( !is_super_admin() )
    302302        return;
    303        
     303
    304304    // On multisite installs, don't load on a non-root blog, unless do_network_admin is
    305305    // overridden
    306306    if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
    307307        return;
    308        
     308
    309309    // Don't show these messages during setup or upgrade
    310310    if ( isset( $bp->maintenence_mode ) )
     
    317317    if ( bp_is_active( 'blogs' ) ) {
    318318        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" ) );
    319        
     319
    320320        if ( !$count )
    321321            bp_blogs_record_existing_blogs();
     
    328328        return false;
    329329
    330     if ( empty( $wp_rewrite->permalink_structure ) ) { 
     330    if ( empty( $wp_rewrite->permalink_structure ) ) {
    331331        bp_core_add_admin_notice( sprintf( __( '<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress' ), admin_url( 'options-permalink.php' ) ) );
    332332    }
    333    
     333
    334334    /**
    335335     * Are you using a BP-compatible theme?
    336336     */
    337    
     337
    338338    // Get current theme info
    339339    $ct = current_theme_info();
     
    341341    // The best way to remove this notice is to add a "buddypress" tag to
    342342    // your active theme's CSS header.
    343     if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { 
     343    if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) {
    344344        bp_core_add_admin_notice( sprintf( __( "You'll need to <a href='%s'>activate a <strong>BuddyPress-compatible theme</strong></a> to take advantage of all of BuddyPress's features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>update your existing WordPress theme</a>.", 'buddypress' ), admin_url( 'themes.php' ), network_admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), network_admin_url( 'plugin-install.php?type=term&tab=search&s=%22bp-template-pack%22' ) ) );
    345345    }
    346        
     346
    347347    /**
    348348     * Check for orphaned directory pages (BP component is disabled, WP page exists)
    349349     */
    350      
     350
    351351    $orphaned_pages = array();
    352352    foreach( $bp->pages as $component_id => $page ) {
    353        
     353
    354354        // Some members of $bp->pages will not have corresponding $bp->{component}, so we
    355355        // skip them. Plugins can add themselves here if necessary.
     
    357357        if ( in_array( $component_id, $exceptions ) )
    358358            continue;
    359        
     359
    360360        if ( !isset( $bp->{$component_id} ) ) {
    361361            // We'll need to get some more information about the page for the notice
     
    367367            );
    368368        }
    369        
    370     }
    371    
     369
     370    }
     371
    372372    // If orphaned pages are found, post a notice about them.
    373373    if ( !empty( $orphaned_pages ) ) {
    374        
     374
    375375        // Create the string of links to the Edit Page screen for the pages
    376376        $edit_pages_links = array();
     
    378378            $edit_pages_links[] = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'post.php?action=edit&post=' . $op['id'] ), $op['title'] );
    379379        }
    380        
     380
    381381        $admin_url = bp_core_do_network_admin() ? network_admin_url( 'admin.php?page=bp-general-settings' ) : admin_url( 'admin.php?page=bp-general-settings' );
    382        
     382
    383383        $notice = sprintf( __( 'Some of your WordPress pages are linked to BuddyPress components that have been disabled. These pages may continue to show up in your site navigation. Consider <a href="%1$s">reactivating the components</a>, or unpublishing the pages: <strong>%2$s</strong>', 'buddypress' ), $admin_url, implode( ', ', $edit_pages_links ) );
    384        
     384
    385385        bp_core_add_admin_notice( $notice );
    386386    }
    387    
     387
    388388    /**
    389389     * Check for orphaned BP components (BP component is enabled, no WP page exists)
    390390     */
    391    
     391
    392392    $orphaned_components = array();
    393393    $wp_page_components  = array();
    394    
     394
    395395    // Only some BP components require a WP page to function - those with a non-empty root_slug
    396396    foreach( $bp->active_components as $component_id => $is_active ) {
     
    402402        }
    403403    }
    404    
     404
    405405    // Activate and Register are special cases. They are not components but they need WP pages.
    406406    // If user registration is disabled, we can skip this step.
     
    410410            'name'  => __( 'Activate', 'buddypress' )
    411411        );
    412        
     412
    413413        $wp_page_components[] = array(
    414414            'id'    => 'register',
    415415            'name'  => __( 'Register', 'buddypress' )
    416416        );
    417     }   
    418    
    419     foreach( $wp_page_components as $component ) {     
     417    }
     418
     419    foreach( $wp_page_components as $component ) {
    420420        if ( !isset( $bp->pages->{$component['id']} ) ) {
    421421            $orphaned_components[] = $component['name'];
    422422        }
    423423    }
    424    
     424
    425425    if ( !empty( $orphaned_components ) ) {
    426426        $admin_url = bp_core_do_network_admin() ? network_admin_url( 'admin.php?page=bp-general-settings' ) : admin_url( 'admin.php?page=bp-general-settings' );
    427        
     427
    428428        $notice = sprintf( __( 'Some BuddyPress components must be associated with WordPress pages for your site to work properly. The following components are missing their required WP pages: <strong>%1$s</strong>. Visit the <a href="%2$s">BuddyPress Components</a> panel, where you can either deactivate unused components or complete the page setup.', 'buddypress' ), implode( ', ', $orphaned_components ), $admin_url );
    429        
     429
    430430        bp_core_add_admin_notice( $notice );
    431431    }
     
    966966function bp_core_add_root_component( $slug ) {
    967967    global $bp;
    968    
     968
    969969    if ( empty( $bp->pages ) )
    970970        $bp->pages = bp_core_get_page_names();
     
    10081008function bp_is_root_blog( $blog_id = false ) {
    10091009    $is_root_blog = true;
    1010    
     1010
    10111011    if ( !$blog_id )
    10121012        $blog_id = get_current_blog_id();
     
    10291029 *    $last_active = get_user_meta( $user_id, bp_get_user_meta_key( 'last_activity' ), true );
    10301030 * Do not hardcode these keys.
    1031  * 
     1031 *
    10321032 * If your plugin introduces custom user metadata that might change between multiple BP instances
    10331033 * on a single WP installation, you are strongly recommended to use this function when storing and
     
    10951095}
    10961096
     1097/**
     1098 * Trigger a 404
     1099 *
     1100 * @global object $bp Global BuddyPress settings object
     1101 * @global WP_Query $wp_query WordPress query object
     1102 * @param string $redirect If 'remove_canonical_direct', remove WordPress' "helpful" redirect_canonical action.
     1103 * @since 1.3
     1104 */
     1105function bp_do_404( $redirect = 'remove_canonical_direct' ) {
     1106    global $bp, $wp_query;
     1107
     1108    do_action( 'bp_do_404', $redirect );
     1109
     1110    $wp_query->set_404();
     1111    status_header( 404 );
     1112    nocache_headers();
     1113
     1114    if ( 'remove_canonical_direct' == $redirect )
     1115        remove_action( 'template_redirect', 'redirect_canonical' );
     1116}
    10971117?>
Note: See TracChangeset for help on using the changeset viewer.