Skip to:
Content

BuddyPress.org

Changeset 3742 for trunk/bp-core.php


Ignore:
Timestamp:
01/19/2011 08:31:10 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Adjust internal action load orders to stop 'doing it wrong' by moving appropriate actions off plugins_loaded and into init. Fixes #2609 but will need testing; it may have adverse effects on external plugins. Adds missing function_exists checks to bp-default functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r3736 r3742  
    253253}
    254254
    255 
    256255function bp_core_get_page_names() {
    257     global $wpdb;
    258 
    259     $page_ids = bp_core_get_page_meta();
    260 
     256    global $wpdb, $bp;
     257
     258    // Set pages as standard class
    261259    $pages = new stdClass;
    262260
    263     // When upgrading to BP 1.3+ from a version of BP that does not use WP pages, $bp->pages
    264     // must be populated with dummy info to avoid crashing the site while the db is upgraded
    265     if ( empty( $page_ids ) ) {
    266         $dummy_components = array(
    267             'members',
    268             'groups',
    269             'activity',
    270             'forums',
    271             'activate',
    272             'register',
    273             'blogs'
    274         );
    275        
    276         foreach ( $dummy_components as $dc ) {
    277             $pages->{$dc}->name     = $dc;
    278             $pages->{$dc}->slug     = $dc;
    279             $pages->{$dc}->id   = $dc;
     261    // When upgrading to BP 1.3+ from a version of BP that does not use WP
     262    // pages, $bp->pages must be populated with dummy info to avoid crashing the
     263    // site while the db is upgraded.
     264    if ( !$page_ids = bp_core_get_page_meta() ) {       
     265        foreach ( $bp->active_components as $component ) {
     266            $pages->{$component->id}->name = $component->id;
     267            $pages->{$component->id}->slug = $component->id;
     268            $pages->{$component->id}->id   = $component->id;
    280269        }
    281270       
     
    284273
    285274    $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
    286 
    287     $page_ids_sql = implode( ',', (array)$page_ids );
    288 
    289     $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) " ) );
     275    $page_ids_sql     = implode( ',', (array)$page_ids );
     276    $page_names       = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) " ) );
    290277
    291278    foreach ( (array)$page_ids as $key => $page_id ) {
     
    293280            if ( $page_name->ID == $page_id ) {
    294281                $pages->{$key}->name = $page_name->post_name;
    295                 $pages->{$key}->id = $page_name->ID;
    296 
    297                 $slug[] = $page_name->post_name;
    298 
    299                 /* Get the slug */
     282                $pages->{$key}->id   = $page_name->ID;
     283                $slug[]              = $page_name->post_name;
     284
     285                // Get the slug
    300286                while ( $page_name->post_parent != 0 ) {
    301                     $parent = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) );
    302                     $slug[] = $parent[0]->post_name;
     287                    $parent                 = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) );
     288                    $slug[]                 = $parent[0]->post_name;
    303289                    $page_name->post_parent = $parent[0]->post_parent;
    304290                }
     
    377363    // Add the administration tab under the "Site Admin" tab for site administrators
    378364    $hook = bp_core_add_admin_menu_page( array(
    379         'menu_title'   => __( 'BuddyPress', 'buddypress' ),
    380         'page_title'   => __( 'BuddyPress', 'buddypress' ),
    381         'capability'   => 'manage_options',
    382         'file'         => 'bp-general-settings',
    383         'function'     => 'bp_core_admin_dashboard',
    384         'position'     => 2
     365        'menu_title' => __( 'BuddyPress', 'buddypress' ),
     366        'page_title' => __( 'BuddyPress', 'buddypress' ),
     367        'capability' => 'manage_options',
     368        'file'       => 'bp-general-settings',
     369        'function'   => 'bp_core_admin_dashboard',
     370        'position'   => 2
    385371    ) );
    386372
     
    411397     */
    412398    if ( !bp_is_active( 'xprofile' ) ) {
    413         /* Fallback values if xprofile is disabled */
     399        // Fallback values if xprofile is disabled
    414400        $bp->core->profile->slug = 'profile';
    415401        $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
    416402
    417         /* Add 'Profile' to the main navigation */
     403        // Add 'Profile' to the main navigation
    418404        bp_core_new_nav_item( array(
    419405            'name' => __('Profile', 'buddypress'),
     
    426412        $profile_link = $bp->loggedin_user->domain . '/profile/';
    427413
    428         /* Add the subnav items to the profile */
     414        // Add the subnav items to the profile
    429415        bp_core_new_subnav_item( array(
    430416            'name' => __( 'Public', 'buddypress' ),
     
    14441430
    14451431        if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
    1446             /* Add to output var */
     1432            // Add to output var
    14471433            $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
    14481434        }
     
    16971683    bp_core_redirect( apply_filters( 'bp_core_search_site', site_url( $slug . $query_string . urlencode( $search_terms ) ), $search_terms ) );
    16981684}
    1699 add_action( 'init', 'bp_core_action_search_site', 5 );
     1685add_action( 'bp_init', 'bp_core_action_search_site', 7 );
    17001686
    17011687/**
     
    18651851        return false;
    18661852}
    1867 add_action ( 'bp_loaded', 'bp_core_load_buddypress_textdomain', 2 );
     1853add_action ( 'bp_init', 'bp_core_load_buddypress_textdomain', 2 );
    18681854
    18691855function bp_core_add_ajax_hook() {
     
    18721858        do_action( 'wp_ajax_' . $_REQUEST['action'] );
    18731859}
    1874 add_action( 'init', 'bp_core_add_ajax_hook' );
     1860add_action( 'bp_init', 'bp_core_add_ajax_hook' );
    18751861
    18761862/**
     
    19571943}
    19581944
    1959 /********************************************************************************
    1960  * Custom Actions
    1961  *
    1962  * Functions to set up custom BuddyPress actions that all other components can
    1963  * hook in to.
    1964  */
    1965 
    1966 /**
    1967  * Allow plugins to include their files ahead of core filters
    1968  */
    1969 function bp_include() {
    1970     do_action( 'bp_include' );
    1971 }
    1972 add_action( 'bp_loaded', 'bp_include', 2 );
    1973 
    1974 /**
    1975  * Allow core components and dependent plugins to set root components
    1976  */
    1977 function bp_setup_root_components() {
    1978     do_action( 'bp_setup_root_components' );
    1979 }
    1980 add_action( 'bp_loaded', 'bp_setup_root_components', 2 );
    1981 
    1982 /**
    1983  * Allow core components and dependent plugins to set globals
    1984  */
    1985 function bp_setup_globals() {
    1986     do_action( 'bp_setup_globals' );
    1987 }
    1988 add_action( 'bp_loaded', 'bp_setup_globals', 6 );
    1989 
    1990 /**
    1991  * Allow core components and dependent plugins to set their nav
    1992  */
    1993 function bp_setup_nav() {
    1994     do_action( 'bp_setup_nav' );
    1995 }
    1996 add_action( 'bp_loaded', 'bp_setup_nav', 8 );
    1997 
    1998 /**
    1999  * Allow core components and dependent plugins to register widgets
    2000  */
    2001 function bp_setup_widgets() {
    2002     do_action( 'bp_register_widgets' );
    2003 }
    2004 add_action( 'bp_loaded', 'bp_setup_widgets', 8 );
    2005 
    2006 /**
    2007  * Allow components to initialize themselves cleanly
    2008  */
    2009 function bp_init() {
    2010     do_action( 'bp_init' );
    2011 }
    2012 add_action( 'bp_loaded', 'bp_init' );
    2013 
     1945/**
     1946 * BuddyPress uses site options to store configuration settings. Many of these settings are needed
     1947 * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
     1948 * them all in one go.
     1949 *
     1950 * @package BuddyPress Core
     1951 */
     1952function bp_core_get_site_options() {
     1953    global $bp, $wpdb;
     1954
     1955    // These options come from the options table in WP single, and sitemeta in MS
     1956    $site_options = apply_filters( 'bp_core_site_options', array(
     1957        'bp-deactivated-components',
     1958        'bp-blogs-first-install',
     1959        'bp-disable-blog-forum-comments',
     1960        'bp-xprofile-base-group-name',
     1961        'bp-xprofile-fullname-field-name',
     1962        'bp-disable-profile-sync',
     1963        'bp-disable-avatar-uploads',
     1964        'bp-disable-account-deletion',
     1965        'bp-disable-forum-directory',
     1966        'bp-disable-blogforum-comments',
     1967        'bb-config-location',
     1968        'hide-loggedout-adminbar',
     1969
     1970        // Useful WordPress settings used often
     1971        'tags_blog_id',
     1972        'registration',
     1973        'fileupload_maxk'
     1974    ) );
     1975
     1976    // These options always come from the options table of BP_ROOT_BLOG
     1977    $root_blog_options = apply_filters( 'bp_core_root_blog_options', array(
     1978        'avatar_default'
     1979    ) );
     1980
     1981    $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";
     1982
     1983    if ( is_multisite() )
     1984        $site_meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );
     1985    else
     1986        $site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
     1987
     1988    $root_blog_meta_keys  = "'" . implode( "','", (array)$root_blog_options ) ."'";
     1989    $root_blog_meta_table = $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'options';
     1990    $root_blog_meta       = $wpdb->get_results( $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$root_blog_meta_table} WHERE option_name IN ({$root_blog_meta_keys})" ) );
     1991
     1992    $site_options = array();
     1993    foreach( array( $site_meta, $root_blog_meta ) as $meta ) {
     1994        if ( !empty( $meta ) ) {
     1995            foreach( (array)$meta as $meta_item )
     1996                $site_options[$meta_item->name] = $meta_item->value;
     1997        }
     1998    }
     1999    return apply_filters( 'bp_core_get_site_options', $site_options );
     2000}
    20142001
    20152002/********************************************************************************
     
    20312018        wp_cache_add_global_groups( array( 'bp' ) );
    20322019}
    2033 add_action( 'init', 'bp_core_add_global_group' );
     2020add_action( 'bp_loaded', 'bp_core_add_global_group' );
    20342021
    20352022/**
Note: See TracChangeset for help on using the changeset viewer.