Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/04/2012 12:16:42 PM (13 years ago)
Author:
johnjamesjacoby
Message:

See #4671:

  • Round one changes...
  • Remove the cumbersome update wizard and associated CSS and images.
  • Copy "About" and "Credits" pages from bbPress.
  • First pass at default components array.
  • Deprecate some functions, consolidate others.
  • Introduce bp-core/admin/bp-core-actions.php to handle admin sub-actions.
  • More to do here (update script, testing, css/images, etc...)
File:
1 edited

Legend:

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

    r6499 r6558  
    3737function bp_core_admin_backpat_menu() {
    3838    global $_parent_pages, $_registered_pages, $submenu;
    39 
    40     // Don't do anything if a BP upgrade is in progress, or if the bp-wizard is in progress.
    41     if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE || empty( $submenu['bp-general-settings'] ) )
    42         return;
    4339
    4440    /**
     
    4743     * 'bp-general-settings' menu, it will only contain one item. Kill it.
    4844     */
    49     if ( 1 == count( $submenu['bp-general-settings'] ) ) {
    50 
    51         // This removes the top-level menu
    52         remove_submenu_page( 'bp-general-settings', 'bp-general-settings' );
    53         remove_menu_page( 'bp-general-settings' );
    54 
    55         // These stop people accessing the URL directly
    56         unset( $_parent_pages['bp-general-settings'] );
    57         unset( $_registered_pages['toplevel_page_bp-general-settings'] );
    58     }
     45    if ( 1 != count( $submenu['bp-general-settings'] ) )
     46        remove;
     47
     48    // This removes the top-level menu
     49    remove_submenu_page( 'bp-general-settings', 'bp-general-settings' );
     50    remove_menu_page( 'bp-general-settings' );
     51
     52    // These stop people accessing the URL directly
     53    unset( $_parent_pages['bp-general-settings'] );
     54    unset( $_registered_pages['toplevel_page_bp-general-settings'] );
    5955}
    6056add_action( bp_core_admin_hook(), 'bp_core_admin_backpat_menu', 999 );
    61 
    62 /**
    63  * Tweak the Settings subnav menu to show only one BuddyPress menu item (Settings > BuddyPress).
    64  *
    65  * @since BuddyPress (1.6)
    66  */
    67 function bp_core_modify_admin_menu() {
    68     $page  = bp_core_do_network_admin()  ? 'settings.php' : 'options-general.php';
    69 
    70     remove_submenu_page( $page, 'bb-forums-setup' );
    71     remove_submenu_page( $page, 'bp-page-settings' );
    72     remove_submenu_page( $page, 'bp-settings'     );
    73 }
    74 add_action( 'admin_head', 'bp_core_modify_admin_menu', 999 );
    7557
    7658/**
     
    180162
    181163/**
    182  * Verify that some BP prerequisites are set up properly, and notify the admin if not
    183  *
    184  * On every Dashboard page, this function checks the following:
    185  *   - that pretty permalinks are enabled
    186  *   - that a BP-compatible theme is activated
    187  *   - that every BP component that needs a WP page for a directory has one
    188  *   - that no WP page has multiple BP components associated with it
    189  * The administrator will be shown a notice for each check that fails.
    190  *
    191  * @package BuddyPress Core
    192  */
    193 function bp_core_activation_notice() {
    194     global $wp_rewrite, $wpdb;
    195 
    196     $bp = buddypress();
    197 
    198     // Only the super admin gets warnings
    199     if ( !bp_current_user_can( 'bp_moderate' ) )
    200         return;
    201 
    202     // On multisite installs, don't load on a non-root blog, unless do_network_admin is
    203     // overridden
    204     if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
    205         return;
    206 
    207     // Don't show these messages during setup or upgrade
    208     if ( !empty( $bp->maintenance_mode ) )
    209         return;
    210 
    211     /**
    212      * Check to make sure that the blog setup routine has run. This can't happen during the
    213      * wizard because of the order which the components are loaded. We check for multisite here
    214      * on the off chance that someone has activated the blogs component and then disabled MS
    215      */
    216     if ( bp_is_active( 'blogs' ) ) {
    217         $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" );
    218 
    219         if ( empty( $count ) ) {
    220             bp_blogs_record_existing_blogs();
    221         }
    222     }
    223 
    224     /**
    225      * Are pretty permalinks enabled?
    226      */
    227     if ( isset( $_POST['permalink_structure'] ) )
    228         return false;
    229 
    230     if ( empty( $wp_rewrite->permalink_structure ) ) {
    231         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' ) ) );
    232     }
    233 
    234     /**
    235      * Check for orphaned BP components (BP component is enabled, no WP page exists)
    236      */
    237     $orphaned_components = array();
    238     $wp_page_components  = array();
    239 
    240     // Only components with 'has_directory' require a WP page to function
    241     foreach( array_keys( $bp->loaded_components ) as $component_id ) {
    242         if ( !empty( $bp->{$component_id}->has_directory ) ) {
    243             $wp_page_components[] = array(
    244                 'id'   => $component_id,
    245                 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id )
    246             );
    247         }
    248     }
    249 
    250     // Activate and Register are special cases. They are not components but they need WP pages.
    251     // If user registration is disabled, we can skip this step.
    252     if ( bp_get_signup_allowed() ) {
    253         $wp_page_components[] = array(
    254             'id'   => 'activate',
    255             'name' => __( 'Activate', 'buddypress' )
    256         );
    257 
    258         $wp_page_components[] = array(
    259             'id'   => 'register',
    260             'name' => __( 'Register', 'buddypress' )
    261         );
    262     }
    263 
    264     foreach( $wp_page_components as $component ) {
    265         if ( !isset( $bp->pages->{$component['id']} ) ) {
    266             $orphaned_components[] = $component['name'];
    267         }
    268     }
    269 
    270     // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is
    271     // not correctly set up, don't show a nag. (In these cases, it's probably the case that the
    272     // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292
    273     if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) {
    274         $forum_key = array_search( $bp->forums->name, $orphaned_components );
    275         unset( $orphaned_components[$forum_key] );
    276         $orphaned_components = array_values( $orphaned_components );
    277     }
    278 
    279     if ( !empty( $orphaned_components ) ) {
    280         $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
    281         $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>' );
    282 
    283         bp_core_add_admin_notice( $notice );
    284     }
    285 
    286     /**
    287      * BP components cannot share a single WP page. Check for duplicate assignments, and post
    288      * a message if found.
    289      */
    290     $dupe_names = array();
    291     $page_ids   = (array)bp_core_get_directory_page_ids();
    292     $dupes      = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
    293 
    294     if ( !empty( $dupes ) ) {
    295         foreach( array_keys( $dupes ) as $dupe_component ) {
    296             $dupe_names[] = $bp->pages->{$dupe_component}->title;
    297         }
    298 
    299         // Make sure that there are no duplicate duplicates :)
    300         $dupe_names = array_unique( $dupe_names );
    301     }
    302 
    303     // If there are duplicates, post a message about them
    304     if ( !empty( $dupe_names ) ) {
    305         $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
    306         $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>' );
    307 
    308         bp_core_add_admin_notice( $notice );
    309     }
    310 }
    311 add_action( 'admin_init', 'bp_core_activation_notice' );
    312 
    313 /**
    314  * Add an extra update message to the update plugin notification.
    315  *
    316  * @package BuddyPress Core
    317  */
    318 function bp_core_update_message() {
    319     echo '<p style="color: red; margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">' . __( 'IMPORTANT: <a href="http://codex.buddypress.org/buddypress-site-administration/upgrading-buddypress/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>';
    320 }
    321 add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
     164 * Redirect user to bbPress's What's New page on activation
     165 *
     166 * @since bbPress (r4389)
     167 *
     168 * @internal Used internally to redirect bbPress to the about page on activation
     169 *
     170 * @uses get_transient() To see if transient to redirect exists
     171 * @uses delete_transient() To delete the transient if it exists
     172 * @uses is_network_admin() To bail if being network activated
     173 * @uses wp_safe_redirect() To redirect
     174 * @uses add_query_arg() To help build the URL to redirect to
     175 * @uses admin_url() To get the admin URL to index.php
     176 *
     177 * @return If no transient, or in network admin, or is bulk activation
     178 */
     179function bp_do_activation_redirect() {
     180
     181    // Bail if no activation redirect
     182    if ( ! get_transient( '_bp_activation_redirect' ) )
     183        return;
     184
     185    // Delete the redirect transient
     186    delete_transient( '_bp_activation_redirect' );
     187
     188    // Bail if activating from network, or bulk
     189    if ( is_network_admin() || isset( $_GET['activate-multi'] ) )
     190        return;
     191
     192    // Redirect to bbPress about page
     193    wp_safe_redirect( add_query_arg( array( 'page' => 'bp-about' ), admin_url( 'index.php' ) ) );
     194}
    322195
    323196/** UI/Styling ****************************************************************/
     
    373246    do_action( 'bp_admin_tabs' );
    374247}
    375 
    376 /**
    377  * Add the confirmation inline javascript in the WP admin dashboard.
    378  *
    379  * Only add it if we're not in BP maintenance mode.
    380  *
    381  * @since BuddyPress (1.7)
    382  * @uses bp_get_maintenance_mode() To see if we're in BP maintenance mode.
    383  * @uses bp_core_confirmation_js() To output our inline JS.
    384  */
    385 function bp_core_admin_add_confirm_js() {
    386     if ( ! bp_get_maintenance_mode() )
    387         bp_core_confirmation_js();
    388 }
    389 add_action( 'admin_head', 'bp_core_admin_add_confirm_js' );
Note: See TracChangeset for help on using the changeset viewer.