Skip to:
Content

BuddyPress.org

Changeset 3742


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.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r3728 r3742  
    12671267    do_action( 'bp_register_activity_actions' );
    12681268}
    1269 add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
     1269add_action( 'bp_init', 'bp_register_activity_actions', 8 );
    12701270
    12711271
  • 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/**
  • trunk/bp-core/bp-core-adminbar.php

    r3722 r3742  
    309309    }
    310310}
    311 add_action( 'bp_loaded', 'bp_core_load_admin_bar' );
     311add_action( 'bp_init', 'bp_core_load_admin_bar' );
    312312
    313313?>
  • trunk/bp-core/bp-core-avatars.php

    r3703 r3742  
    4545        define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
    4646}
    47 add_action( 'bp_loaded', 'bp_core_set_avatar_constants', 8 );
     47add_action( 'bp_init', 'bp_core_set_avatar_constants', 8 );
    4848
    4949/**
  • trunk/bp-core/bp-core-catchuri.php

    r3592 r3742  
    213213    $action_variables = array_merge( array(), $action_variables );
    214214}
    215 add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 );
     215add_action( 'bp_init', 'bp_core_set_uri_globals', 4 );
    216216
    217217/**
  • trunk/bp-core/bp-core-cssjs.php

    r3706 r3742  
    2424    }
    2525}
    26 add_action( 'init', 'bp_core_add_admin_bar_css' );
     26add_action( 'bp_init', 'bp_core_add_admin_bar_css' );
    2727
    2828/**
  • trunk/bp-core/bp-core-deprecated.php

    r3728 r3742  
    3939    if ( empty( $match ) ) {
    4040        $bp->add_root[] = $slug;
    41         add_action( 'init', 'bp_core_create_root_component_page' );
     41        add_action( 'bp_init', 'bp_core_create_root_component_page' );
    4242    }
    4343}
  • trunk/bp-core/bp-core-signup.php

    r3734 r3742  
    623623    add_action( 'wp', 'bp_core_wpsignup_redirect' );
    624624else
    625     add_action( 'init', 'bp_core_wpsignup_redirect' );
     625    add_action( 'bp_init', 'bp_core_wpsignup_redirect' );
    626626
    627627?>
  • trunk/bp-friends.php

    r3728 r3742  
    201201    return false;
    202202}
    203 add_action( 'init', 'friends_action_add_friend' );
     203add_action( 'bp_init', 'friends_action_add_friend' );
    204204
    205205function friends_action_remove_friend() {
     
    240240    return false;
    241241}
    242 add_action( 'init', 'friends_action_remove_friend' );
     242add_action( 'bp_init', 'friends_action_remove_friend' );
    243243
    244244
  • trunk/bp-loader.php

    r3736 r3742  
    7272        require_once( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-update.php' );
    7373    }
    74 
    75     add_action( 'plugins_loaded', 'bp_loaded', 20 );
    7674}
    7775
     76/********************************************************************************
     77 * Custom Actions
     78 *
     79 * Functions to set up custom BuddyPress actions that all other components can
     80 * hook in to.
     81 */
     82
    7883/**
    79  * Allow dependent plugins and core actions to attach themselves in a safe way.
    80  *
    81  * See bp-core.php for the following core actions:
    82  *      - bp_init|bp_setup_globals|bp_setup_root_components|bp_setup_nav|bp_register_widgets
     84 * Allow plugins to include their files ahead of core filters
     85 */
     86function bp_include() {
     87    do_action( 'bp_include' );
     88}
     89add_action( 'bp_loaded', 'bp_include', 2 );
     90
     91/**
     92 * Allow core components and dependent plugins to set root components
     93 */
     94function bp_setup_root_components() {
     95    do_action( 'bp_setup_root_components' );
     96}
     97add_action( 'bp_init', 'bp_setup_root_components', 2 );
     98
     99/**
     100 * Allow core components and dependent plugins to set globals
     101 */
     102function bp_setup_globals() {
     103    do_action( 'bp_setup_globals' );
     104}
     105add_action( 'bp_init', 'bp_setup_globals', 6 );
     106
     107/**
     108 * Allow core components and dependent plugins to set their nav
     109 */
     110function bp_setup_nav() {
     111    do_action( 'bp_setup_nav' );
     112}
     113add_action( 'bp_init', 'bp_setup_nav', 8 );
     114
     115/**
     116 * Allow core components and dependent plugins to register widgets
     117 */
     118function bp_setup_widgets() {
     119    do_action( 'bp_register_widgets' );
     120}
     121add_action( 'bp_init', 'bp_setup_widgets', 8 );
     122
     123/**
     124 * Allow components to initialize themselves cleanly
     125 */
     126function bp_init() {
     127    do_action( 'bp_init' );
     128}
     129add_action( 'init', 'bp_init' );
     130
     131/**
     132 * Attached to plugins_loaded
    83133 */
    84134function bp_loaded() {
    85135    do_action( 'bp_loaded' );
    86136}
    87 
    88 /**
    89  * BuddyPress uses site options to store configuration settings. Many of these settings are needed
    90  * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
    91  * them all in one go.
    92  *
    93  * @package BuddyPress Core
    94  */
    95 function bp_core_get_site_options() {
    96     global $bp, $wpdb;
    97 
    98     // These options come from the options table in WP single, and sitemeta in MS
    99     $site_options = apply_filters( 'bp_core_site_options', array(
    100         'bp-deactivated-components',
    101         'bp-blogs-first-install',
    102         'bp-disable-blog-forum-comments',
    103         'bp-xprofile-base-group-name',
    104         'bp-xprofile-fullname-field-name',
    105         'bp-disable-profile-sync',
    106         'bp-disable-avatar-uploads',
    107         'bp-disable-account-deletion',
    108         'bp-disable-forum-directory',
    109         'bp-disable-blogforum-comments',
    110         'bb-config-location',
    111         'hide-loggedout-adminbar',
    112 
    113         // Useful WordPress settings used often
    114         'tags_blog_id',
    115         'registration',
    116         'fileupload_maxk'
    117     ) );
    118 
    119     // These options always come from the options table of BP_ROOT_BLOG
    120     $root_blog_options = apply_filters( 'bp_core_root_blog_options', array(
    121         'avatar_default'
    122     ) );
    123 
    124     $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";
    125 
    126     if ( is_multisite() )
    127         $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}" );
    128     else
    129         $site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
    130 
    131     $root_blog_meta_keys  = "'" . implode( "','", (array)$root_blog_options ) ."'";
    132     $root_blog_meta_table = $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'options';
    133     $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})" ) );
    134 
    135     $site_options = array();
    136     foreach( array( $site_meta, $root_blog_meta ) as $meta ) {
    137         if ( !empty( $meta ) ) {
    138             foreach( (array)$meta as $meta_item )
    139                 $site_options[$meta_item->name] = $meta_item->value;
    140         }
    141     }
    142     return apply_filters( 'bp_core_get_site_options', $site_options );
    143 }
     137add_action( 'plugins_loaded', 'bp_loaded', 10 );
    144138
    145139/**
  • trunk/bp-themes/bp-default/functions.php

    r3736 r3742  
    117117endif;
    118118
    119 /**
    120  * Enqueue theme javascript safely after the 'init' action, per WordPress Codex.
     119if ( !function_exists( 'bp_dtheme_enqueue_scripts' ) ) :
     120/**
     121 * Enqueue theme javascript safely
    121122 *
    122123 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    146147}
    147148add_action( 'wp_enqueue_scripts', 'bp_dtheme_enqueue_scripts' );
     149endif;
    148150
    149151if ( !function_exists( 'bp_dtheme_admin_header_style' ) ) :
     
    289291endif;
    290292
     293if ( !function_exists( 'bp_dtheme_widgets_init' ) ) :
    291294/**
    292295 * Register widgetised areas, including one sidebar and four widget-ready columns in the footer.
     
    355358}
    356359add_action( 'widgets_init', 'bp_dtheme_widgets_init' );
     360endif;
    357361
    358362if ( !function_exists( 'bp_dtheme_blog_comments' ) ) :
     
    425429endif;
    426430
     431if ( !function_exists( 'bp_dtheme_page_on_front' ) ) :
    427432/**
    428433 * Return the ID of a page set as the home page.
     
    437442    return apply_filters( 'bp_dtheme_page_on_front', get_option( 'page_on_front' ) );
    438443}
    439 
     444endif;
     445
     446if ( !function_exists( 'bp_dtheme_activity_secondary_avatars' ) ) :
    440447/**
    441448 * Add secondary avatar image to this activity stream's record, if supported.
     
    463470}
    464471add_filter( 'bp_get_activity_action_pre_meta', 'bp_dtheme_activity_secondary_avatars', 10, 2 );
    465 
     472endif;
     473
     474if ( !function_exists( 'bp_dtheme_show_notice' ) ) :
    466475/**
    467476 * Show a notice when the theme is activated - workaround by Ozh (http://old.nabble.com/Activation-hook-exist-for-themes--td25211004.html)
     
    479488if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
    480489    add_action( 'admin_notices', 'bp_dtheme_show_notice' );
     490endif;
    481491
    482492if ( !function_exists( 'bp_dtheme_main_nav' ) ) :
     
    516526endif;
    517527
     528if ( !function_exists( 'bp_dtheme_page_menu_args' ) ) :
    518529/**
    519530 * Get our wp_nav_menu() fallback, bp_dtheme_main_nav(), to show a home link.
     
    528539}
    529540add_filter( 'wp_page_menu_args', 'bp_dtheme_page_menu_args' );
    530 
     541endif;
     542
     543if ( !function_exists( 'bp_dtheme_comment_form' ) ) :
    531544/**
    532545 * Applies BuddyPress customisations to the post comment form.
     
    564577}
    565578add_filter( 'comment_form_defaults', 'bp_dtheme_comment_form', 10 );
    566 
     579endif;
     580
     581if ( !function_exists( 'bp_dtheme_before_comment_form' ) ) :
    567582/**
    568583 * Adds the user's avatar before the comment form box.
     
    592607}
    593608add_action( 'comment_form_top', 'bp_dtheme_before_comment_form' );
    594 
     609endif;
     610
     611if ( !function_exists( 'bp_dtheme_after_comment_form' ) ) :
    595612/**
    596613 * Closes tags opened in bp_dtheme_before_comment_form().
     
    602619function bp_dtheme_after_comment_form() {
    603620?>
     621
    604622    </div><!-- .comment-content standard-form -->
     623
    605624<?php
    606625}
    607626add_action( 'comment_form', 'bp_dtheme_after_comment_form' );
    608 
     627endif;
    609628
    610629// Everything beyond this point is deprecated as of BuddyPress 1.3. This will be removed in a future version.
     630
     631if ( BP_VERSION < 1.3 ) :
    611632
    612633/**
     
    701722        wp_enqueue_script( 'comment-reply' );
    702723}
     724endif;
     725
    703726?>
Note: See TracChangeset for help on using the changeset viewer.