Skip to:
Content

BuddyPress.org

Changeset 6695


Ignore:
Timestamp:
12/30/2012 04:27:02 PM (12 years ago)
Author:
djpaul
Message:

Bring back bp_core_activation_notice() from the bench; it provides a notice for admins if pretty permalinks aren't enabled and/or the BP component/page mapping is incomplete. See #4671.

These notices are helpful for debugging people's sites on the support forums, and for telling people they need to set permalinks. Most (all?) of this will be taken back out in a future version of BuddyPress when we switch to using rewrite rules.

This commit also accidentally fixes a regression in trunk where, if the Blogs component is active on multisite, we weren't recording existing blogs' information for use in the Sites Directory.

Location:
trunk/bp-core
Files:
3 edited

Legend:

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

    r6676 r6695  
    5050
    5151// Hook on to admin_init
    52 add_action( 'bp_admin_init', 'bp_setup_updater',          999 );
    53 add_action( 'bp_admin_init', 'bp_register_importers'          );
    54 add_action( 'bp_admin_init', 'bp_register_admin_style'        );
    55 add_action( 'bp_admin_init', 'bp_register_admin_settings'     );
    56 add_action( 'bp_admin_init', 'bp_do_activation_redirect', 1   );
     52add_action( 'bp_admin_init', 'bp_setup_updater',          1000 );
     53add_action( 'bp_admin_init', 'bp_core_activation_notice', 1010 );
     54add_action( 'bp_admin_init', 'bp_register_importers'           );
     55add_action( 'bp_admin_init', 'bp_register_admin_style'         );
     56add_action( 'bp_admin_init', 'bp_register_admin_settings'      );
     57add_action( 'bp_admin_init', 'bp_do_activation_redirect', 1    );
    5758
    5859// Add a new separator
  • trunk/bp-core/admin/bp-core-functions.php

    r6689 r6695  
    160160
    161161    $bp->admin->notices[] = $notice;
     162}
     163
     164/**
     165 * Verify that some BP prerequisites are set up properly, and notify the admin if not
     166 *
     167 * On every Dashboard page, this function checks the following:
     168 *   - that pretty permalinks are enabled
     169 *   - that every BP component that needs a WP page for a directory has one
     170 *   - that no WP page has multiple BP components associated with it
     171 * The administrator will be shown a notice for each check that fails.
     172 *
     173 * @global WPDB $wpdb WordPress DB object
     174 * @global WP_Rewrite $wp_rewrite
     175 * @since BuddyPress (1.2)
     176 */
     177function bp_core_activation_notice() {
     178    global $wpdb, $wp_rewrite;
     179
     180    $bp = buddypress();
     181
     182    // Only the super admin gets warnings
     183    if ( !bp_current_user_can( 'bp_moderate' ) )
     184        return;
     185
     186    // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden
     187    if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
     188        return;
     189
     190    /**
     191     * Check to make sure that the blog setup routine has run. This can't happen during the
     192     * wizard because of the order which the components are loaded. We check for multisite here
     193     * on the off chance that someone has activated the blogs component and then disabled MS
     194     */
     195    if ( bp_is_active( 'blogs' ) ) {
     196        $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" );
     197
     198        if ( empty( $count ) ) {
     199            bp_blogs_record_existing_blogs();
     200        }
     201    }
     202
     203    /**
     204     * Are pretty permalinks enabled?
     205     */
     206    if ( isset( $_POST['permalink_structure'] ) )
     207        return;
     208
     209    if ( empty( $wp_rewrite->permalink_structure ) ) {
     210        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' ) ) );
     211    }
     212
     213    /**
     214     * Check for orphaned BP components (BP component is enabled, no WP page exists)
     215     */
     216    $orphaned_components = array();
     217    $wp_page_components  = array();
     218
     219    // Only components with 'has_directory' require a WP page to function
     220    foreach( array_keys( $bp->loaded_components ) as $component_id ) {
     221        if ( !empty( $bp->{$component_id}->has_directory ) ) {
     222            $wp_page_components[] = array(
     223                'id'   => $component_id,
     224                'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id )
     225            );
     226        }
     227    }
     228
     229    // Activate and Register are special cases. They are not components but they need WP pages.
     230    // If user registration is disabled, we can skip this step.
     231    if ( bp_get_signup_allowed() ) {
     232        $wp_page_components[] = array(
     233            'id'   => 'activate',
     234            'name' => __( 'Activate', 'buddypress' )
     235        );
     236
     237        $wp_page_components[] = array(
     238            'id'   => 'register',
     239            'name' => __( 'Register', 'buddypress' )
     240        );
     241    }
     242
     243    // On the first admin screen after a new installation, this isn't set, so grab it to supress a misleading error message.
     244    if ( empty( $bp->pages->members ) )
     245        $bp->pages = bp_core_get_directory_pages();
     246
     247    foreach( $wp_page_components as $component ) {
     248        if ( !isset( $bp->pages->{$component['id']} ) ) {
     249            $orphaned_components[] = $component['name'];
     250        }
     251    }
     252
     253    // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is
     254    // not correctly set up, don't show a nag. (In these cases, it's probably the case that the
     255    // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292
     256    if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) {
     257        $forum_key = array_search( $bp->forums->name, $orphaned_components );
     258        unset( $orphaned_components[$forum_key] );
     259        $orphaned_components = array_values( $orphaned_components );
     260    }
     261
     262    if ( !empty( $orphaned_components ) ) {
     263        $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
     264        $notice    = sprintf( __( 'The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $orphaned_components ) . '</strong>' );
     265
     266        bp_core_add_admin_notice( $notice );
     267    }
     268
     269    // BP components cannot share a single WP page. Check for duplicate assignments, and post a message if found.
     270    $dupe_names = array();
     271    $page_ids   = (array)bp_core_get_directory_page_ids();
     272    $dupes      = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
     273
     274    if ( !empty( $dupes ) ) {
     275        foreach( array_keys( $dupes ) as $dupe_component ) {
     276            $dupe_names[] = $bp->pages->{$dupe_component}->title;
     277        }
     278
     279        // Make sure that there are no duplicate duplicates :)
     280        $dupe_names = array_unique( $dupe_names );
     281    }
     282
     283    // If there are duplicates, post a message about them
     284    if ( !empty( $dupe_names ) ) {
     285        $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
     286        $notice    = sprintf( __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $dupe_names ) . '</strong>' );
     287
     288        bp_core_add_admin_notice( $notice );
     289    }
    162290}
    163291
  • trunk/bp-core/deprecated/1.7.php

    r6612 r6695  
    117117
    118118/**
    119  * Verify that some BP prerequisites are set up properly, and notify the admin if not
    120  *
    121  * On every Dashboard page, this function checks the following:
    122  *   - that pretty permalinks are enabled
    123  *   - that a BP-compatible theme is activated
    124  *   - that every BP component that needs a WP page for a directory has one
    125  *   - that no WP page has multiple BP components associated with it
    126  * The administrator will be shown a notice for each check that fails.
    127  *
    128  * @deprecated BuddyPress (1.7)
    129  * @package BuddyPress Core
    130  */
    131 function bp_core_activation_notice() {
    132     global $wp_rewrite, $wpdb;
    133 
    134     $bp = buddypress();
    135 
    136     // Only the super admin gets warnings
    137     if ( !bp_current_user_can( 'bp_moderate' ) )
    138         return;
    139 
    140     // On multisite installs, don't load on a non-root blog, unless do_network_admin is
    141     // overridden
    142     if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
    143         return;
    144 
    145     // Don't show these messages during setup or upgrade
    146     if ( !empty( $bp->maintenance_mode ) )
    147         return;
    148 
    149     /**
    150      * Check to make sure that the blog setup routine has run. This can't happen during the
    151      * wizard because of the order which the components are loaded. We check for multisite here
    152      * on the off chance that someone has activated the blogs component and then disabled MS
    153      */
    154     if ( bp_is_active( 'blogs' ) ) {
    155         $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" );
    156 
    157         if ( empty( $count ) ) {
    158             bp_blogs_record_existing_blogs();
    159         }
    160     }
    161 
    162     /**
    163      * Are pretty permalinks enabled?
    164      */
    165     if ( isset( $_POST['permalink_structure'] ) )
    166         return false;
    167 
    168     if ( empty( $wp_rewrite->permalink_structure ) ) {
    169         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' ) ) );
    170     }
    171 
    172     /**
    173      * Check for orphaned BP components (BP component is enabled, no WP page exists)
    174      */
    175     $orphaned_components = array();
    176     $wp_page_components  = array();
    177 
    178     // Only components with 'has_directory' require a WP page to function
    179     foreach( array_keys( $bp->loaded_components ) as $component_id ) {
    180         if ( !empty( $bp->{$component_id}->has_directory ) ) {
    181             $wp_page_components[] = array(
    182                 'id'   => $component_id,
    183                 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id )
    184             );
    185         }
    186     }
    187 
    188     // Activate and Register are special cases. They are not components but they need WP pages.
    189     // If user registration is disabled, we can skip this step.
    190     if ( bp_get_signup_allowed() ) {
    191         $wp_page_components[] = array(
    192             'id'   => 'activate',
    193             'name' => __( 'Activate', 'buddypress' )
    194         );
    195 
    196         $wp_page_components[] = array(
    197             'id'   => 'register',
    198             'name' => __( 'Register', 'buddypress' )
    199         );
    200     }
    201 
    202     foreach( $wp_page_components as $component ) {
    203         if ( !isset( $bp->pages->{$component['id']} ) ) {
    204             $orphaned_components[] = $component['name'];
    205         }
    206     }
    207 
    208     // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is
    209     // not correctly set up, don't show a nag. (In these cases, it's probably the case that the
    210     // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292
    211     if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) {
    212         $forum_key = array_search( $bp->forums->name, $orphaned_components );
    213         unset( $orphaned_components[$forum_key] );
    214         $orphaned_components = array_values( $orphaned_components );
    215     }
    216 
    217     if ( !empty( $orphaned_components ) ) {
    218         $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
    219         $notice    = sprintf( __( 'The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $orphaned_components ) . '</strong>' );
    220 
    221         bp_core_add_admin_notice( $notice );
    222     }
    223 
    224     /**
    225      * BP components cannot share a single WP page. Check for duplicate assignments, and post
    226      * a message if found.
    227      */
    228     $dupe_names = array();
    229     $page_ids   = (array)bp_core_get_directory_page_ids();
    230     $dupes      = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
    231 
    232     if ( !empty( $dupes ) ) {
    233         foreach( array_keys( $dupes ) as $dupe_component ) {
    234             $dupe_names[] = $bp->pages->{$dupe_component}->title;
    235         }
    236 
    237         // Make sure that there are no duplicate duplicates :)
    238         $dupe_names = array_unique( $dupe_names );
    239     }
    240 
    241     // If there are duplicates, post a message about them
    242     if ( !empty( $dupe_names ) ) {
    243         $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
    244         $notice    = sprintf( __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $dupe_names ) . '</strong>' );
    245 
    246         bp_core_add_admin_notice( $notice );
    247     }
    248 }
    249 
    250 /**
    251119 * This function was originally used to update pre-1.1 schemas, but that was
    252120 * before we had a legitimate update process.
Note: See TracChangeset for help on using the changeset viewer.