Skip to:
Content

BuddyPress.org

Changeset 3728 for trunk/bp-core.php


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r3720 r3728  
    99define( 'BP_PLUGIN_URL', plugins_url( $path = '/buddypress' ) );
    1010
    11 /* Load the WP abstraction file so BuddyPress can run on all WordPress setups. */
     11// Load the WP abstraction file so BuddyPress can run on all WordPress setups.
    1212require ( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
    1313
    14 /* Place your custom code (actions/filters) in a file called /plugins/bp-custom.php and it will be loaded before anything else. */
     14// Place your custom code (actions/filters) in a file called /plugins/bp-custom.php and it will be loaded before anything else.
    1515if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
    1616        require( WP_PLUGIN_DIR . '/bp-custom.php' );
    1717
    18 /* Define the user and usermeta table names, useful if you are using custom or shared tables. */
     18// Define the user and usermeta table names, useful if you are using custom or shared tables.
    1919if ( !defined( 'CUSTOM_USER_TABLE' ) )
    2020        define( 'CUSTOM_USER_TABLE', $wpdb->base_prefix . 'users' );
     
    2525// The search slug has to be defined nice and early because of the way search requests are loaded
    2626if ( !defined( 'BP_SEARCH_SLUG' ) )
    27         define( 'BP_SEARCH_SLUG', 'search' );
    28 
    29 /* Load the files containing functions that we globally will need. */
    30 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
    31 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
    32 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
    33 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
    34 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
    35 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
    36 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-settings.php' );
    37 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
     27        define( 'BP_SEARCH_SLUG', 'search' );
     28
     29// Load the files containing functions that we globally will need.
     30require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php'      );
     31require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php'       );
     32require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php'       );
     33require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php'         );
     34require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php'       );
     35require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php'  );
     36require ( BP_PLUGIN_DIR . '/bp-core/bp-core-settings.php'      );
     37require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php'       );
    3838require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
    39 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
    40 
    41 /* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
     39require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php'        );
     40require ( BP_PLUGIN_DIR . '/bp-core/bp-core-deprecated.php'    );
     41
     42// If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar.
    4243if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
    4344        require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
    4445
    45 /* Register BuddyPress themes contained within the bp-theme folder */
     46// Register BuddyPress themes contained within the bp-theme folder
    4647register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
    4748
    48 
    49 /* "And now for something completely different" .... */
    50 
    51 
    52 /**
    53  * bp_core_setup_globals()
    54  *
     49/** "And now for something completely different" ******************************/
     50
     51/**
    5552 * Sets up default global BuddyPress configuration settings and stores
    5653 * them in a $bp variable.
     
    7673
    7774        // The domain for the root of the site where the main blog resides
    78         $bp->root_domain = bp_core_get_root_domain();
     75        $bp->root_domain  = bp_core_get_root_domain();
    7976
    8077        // The names of the core WordPress pages used to display BuddyPress content
    81         $bp->pages = $bp_pages;
     78        $bp->pages        = $bp_pages;
     79
     80        /** Members Component *****************************************************/
    8281
    8382        // Set up the members id and active components entry
    84         $bp->members->id = 'members';
    85 
     83        $bp->members->id  = 'members';
     84
     85        // Members Slugs
    8686        $bp->members->slug = $bp->pages->members->slug;
    8787        $bp->active_components[$bp->members->slug] = $bp->members->id;
     
    8989        // The user ID of the user who is currently logged in.
    9090        $bp->loggedin_user->id = $current_user->ID;
     91
     92        /** Logged in user ********************************************************/
    9193
    9294        // The domain for the user currently logged in. eg: http://domain.com/members/andy
     
    100102        $bp->loggedin_user->is_site_admin  = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6
    101103
     104        /** Displayed user ********************************************************/
     105
    102106        // The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php
    103107        $bp->displayed_user->id = $displayed_user_id;
     
    109113        $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
    110114
     115        /** Component and Action **************************************************/
     116
    111117        // The component being used eg: http://domain.com/members/andy/ [profile]
    112118        $bp->current_component = $current_component; // type: string
     
    121127        $bp->current_item = ''; // type: string
    122128
    123         // Used for overriding the 2nd level navigation menu so it can be used to display custom navigation for an item (for example a group)
     129        // Used for overriding the 2nd level navigation menu so it can be used to
     130        // display custom navigation for an item (for example a group)
    124131        $bp->is_single_item = false;
    125132
     
    134141        }
    135142
    136         // Fetches all of the core database based BuddyPress settings in one foul swoop
     143        // Fetches all of the core BuddyPress settings in one fell swoop
    137144        $bp->site_options = bp_core_get_site_options();
    138145
    139         // Sets up the array container for the component navigation rendered by bp_get_nav()
     146        // Sets up the array container for the component navigation rendered
     147        // by bp_get_nav()
    140148        $bp->bp_nav = array();
    141149
    142         // Sets up the array container for the component options navigation rendered by bp_get_options_nav()
     150        // Sets up the array container for the component options navigation
     151        // rendered by bp_get_options_nav()
    143152        $bp->bp_options_nav = array();
    144153
    145         // Contains an array of all the active components. The key is the slug, value the internal ID of the component
     154        // Contains an array of all the active components. The key is the slug,
     155        // value the internal ID of the component.
    146156        $bp->active_components = array();
     157
     158        /** Avatars ***************************************************************/
    147159
    148160        // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
     
    155167        $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );
    156168
    157         /* Used to determine if user has admin rights on current content. If the logged in user is viewing
    158            their own profile and wants to delete something, is_item_admin is used. This is a
    159            generic variable so it can be used by other components. It can also be modified, so when viewing a group
    160            'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
     169        /**
     170         * Used to determine if user has admin rights on current content. If the logged in user is viewing
     171         * their own profile and wants to delete something, is_item_admin is used. This is a
     172         * generic variable so it can be used by other components. It can also be modified, so when viewing a group
     173         * 'is_item_admin' would be 1 if they are a group admin, 0 if they are not.
     174         */
    161175        $bp->is_item_admin = bp_user_has_access();
    162176
     
    164178        $bp->is_item_mod = false;
    165179
     180        // Notifications Table
    166181        $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
    167182
     183        // Default Component
    168184        if ( !$bp->current_component && $bp->displayed_user->id )
    169185                $bp->current_component = $bp->default_component;
    170186
    171187        // The default text for the members directory search box
    172         $bp->default_search_strings[$bp->members->slug] = __( 'Search Members...', 'buddypress' );
     188        $bp->default_search_strings[$bp->members->slug] = __( 'Search Members...', 'buddypress' );
    173189
    174190        do_action( 'bp_core_setup_globals' );
     
    177193
    178194/**
    179  * bp_core_get_table_prefix()
    180  *
    181195 * Allow filtering of database prefix. Intended for use in multinetwork installations.
    182196 *
     
    191205
    192206/**
    193  * bp_core_define_slugs()
    194  *
    195207 * Define the slugs used for BuddyPress pages, based on the slugs of the WP pages used.
    196208 * These can be overridden manually by defining these slugs in wp-config.php.
     
    215227
    216228/**
    217  * bp_core_get_page_meta()
    218  *
    219229 * Fetches BP pages from the meta table, depending on setup
    220230 *
     
    231241
    232242/**
    233  * bp_core_update_page_meta()
    234  *
    235243 * Stores BP pages in the meta table, depending on setup
    236244 *
     
    285293}
    286294
    287 /**
    288  * bp_core_admin_menu_init()
    289  *
     295/**
     296 * Creates a default component slug from a WP page root_slug
     297 *
     298 * Since 1.3, BP components get their root_slug (the slug used immediately
     299 * following the root domain) from the slug of a corresponding WP page.
     300 *
     301 * E.g. if your BP installation at example.com has its members page at
     302 * example.com/community/people, $bp->members->root_slug will be 'community/people'.
     303 *
     304 * By default, this function creates a shorter version of the root_slug for
     305 * use elsewhere in the URL, by returning the content after the final '/'
     306 * in the root_slug ('people' in the example above).
     307 *
     308 * Filter on 'bp_core_component_slug_from_root_slug' to override this method
     309 * in general, or define a specific component slug constant (e.g. BP_MEMBERS_SLUG)
     310 * to override specific component slugs.
     311 * 
     312 * @package BuddyPress Core
     313 * @since 1.3
     314 *
     315 * @param str $root_slug The root slug, which comes from $bp->pages->[component]->slug
     316 * @return str $slug The short slug for use in the middle of URLs
     317 */
     318function bp_core_component_slug_from_root_slug( $root_slug ) {
     319        $slug_chunks = explode( '/', $root_slug );
     320        $slug        = array_pop( $slug_chunks );
     321       
     322        return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );
     323}
     324
     325/**
    290326 * Initializes the wp-admin area "BuddyPress" menus and sub menus.
    291327 *
     
    302338
    303339/**
    304  * bp_core_add_admin_menu()
    305  *
    306340 * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
    307341 *
     
    334368
    335369/**
    336  * bp_core_is_root_component()
    337  *
    338  * Checks to see if a component's URL should be in the root, not under a member page:
    339  * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
    340  *
    341  * @package BuddyPress Core
    342  * @return true if root component, else false.
    343  */
    344 function bp_core_is_root_component( $component_name ) {
    345         global $bp;
    346 
    347         foreach ( (array) $bp->pages as $key => $page ) {
    348                 if ( $key == $component_name || $page->slug == $component_name )
    349                         return true;
    350         }
    351 
    352         return false;
    353 }
    354 
    355 /**
    356  * bp_core_setup_nav()
    357  *
    358370 * Sets up the profile navigation item if the Xprofile component is not installed.
    359371 *
     
    419431
    420432/**
    421  * bp_core_action_directory_members()
    422  *
    423433 * Listens to the $bp component and action variables to determine if the user is viewing the members
    424434 * directory page. If they are, it will set up the directory and load the members directory template.
     
    442452
    443453/**
    444  * bp_core_action_set_spammer_status()
    445  *
    446454 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
    447455 * this action will fire and mark or unmark the user and their blogs as spam.
     
    458466
    459467        if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
    460                 /* Check the nonce */
     468                // Check the nonce
    461469                check_admin_referer( 'mark-unmark-spammer' );
    462470
    463                 /* Get the functions file */
     471                // Get the functions file
    464472                if ( is_multisite() )
    465473                        require_once( ABSPATH . 'wp-admin/includes/ms.php' );
     
    470478                        $is_spam = 0;
    471479
    472                 /* Get the blogs for the user */
     480                // Get the blogs for the user
    473481                $blogs = get_blogs_of_user( $bp->displayed_user->id, true );
    474482
    475483                foreach ( (array) $blogs as $key => $details ) {
    476                         /* Do not mark the main or current root blog as spam */
     484                        // Do not mark the main or current root blog as spam
    477485                        if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
    478486                                continue;
    479487
    480                         /* Update the blog status */
     488                        // Update the blog status
    481489                        update_blog_status( $details->userblog_id, 'spam', $is_spam );
    482490
    483                         /* Fire the standard WPMU hook */
     491                        // Fire the standard multisite hook
    484492                        do_action( 'make_spam_blog', $details->userblog_id );
    485493                }
    486494
    487                 /* Finally, mark this user as a spammer */
     495                // Finally, mark this user as a spammer
    488496                if ( is_multisite() )
    489497                        $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
     
    496504                        bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );
    497505
    498                 /* Hide this user's activity */
     506                // Hide this user's activity
    499507                if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )
    500508                        bp_activity_hide_user_activity( $bp->displayed_user->id );
    501509
    502                 // We need a special hook for is_spam so that components can delete data at spam time
     510                // We need a special hook for is_spam so that components can
     511                // delete data at spam time
    503512                if ( $is_spam )
    504                         do_action( 'bp_make_spam_user', $bp->displayed_user->id );
     513                        do_action( 'bp_make_spam_user', $bp->displayed_user->id );
    505514
    506515                do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );
     
    512521
    513522/**
    514  * bp_core_action_delete_user()
    515  *
    516523 * Allows a site admin to delete a user from the adminbar menu.
    517524 *
     
    526533
    527534        if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {
    528                 /* Check the nonce */
     535                // Check the nonce
    529536                check_admin_referer( 'delete-user' );
    530537
     
    559566
    560567/**
    561  * bp_core_get_users()
    562  *
    563568 * Return an array of users IDs based on the parameters passed.
    564569 *
     
    587592
    588593/**
    589  * bp_core_get_user_domain()
    590  *
    591  * Returns the domain for the passed user:
    592  * e.g. http://domain.com/members/andy/
     594 * Returns the domain for the passed user: e.g. http://domain.com/members/andy/
    593595 *
    594596 * @package BuddyPress Core
     
    605607                $username = bp_core_get_username( $user_id, $user_nicename, $user_login );
    606608
    607                 /* If we are using a members slug, include it. */
     609                // If we are using a members slug, include it.
    608610                if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
    609611                        $domain = $bp->root_domain . '/' . $bp->members->slug . '/' . $username . '/';
     
    611613                        $domain = $bp->root_domain . '/' . $username . '/';
    612614
    613                 /* Cache the link */
     615                // Cache the link
    614616                if ( !empty( $domain ) )
    615617                        wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
     
    620622
    621623/**
    622  * bp_core_get_core_userdata()
    623  *
    624624 * Fetch everything in the wp_users table for a user, without any usermeta.
    625625 *
     
    640640
    641641/**
    642  * bp_core_get_root_domain()
    643  *
    644642 * Returns the domain for the root blog.
    645643 * eg: http://domain.com/ OR https://domain.com
     
    661659
    662660/**
    663  * bp_core_get_displayed_userid()
    664  *
    665661 * Returns the user id for the user that is currently being displayed.
    666662 * eg: http://andy.domain.com/ or http://domain.com/andy/
     
    675671
    676672/**
    677  * bp_core_new_nav_item()
    678  *
    679673 * Adds a navigation item to the main navigation array used in BuddyPress themes.
    680674 *
     
    686680
    687681        $defaults = array(
    688                 'name' => false, // Display name for the nav item
    689                 'slug' => false, // URL slug for the nav item
    690                 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
    691                 'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
    692                 'site_admin_only' => false, // Can only site admins see this nav item?
    693                 'position' => 99, // Index of where this nav item should be positioned
    694                 'screen_function' => false, // The name of the function to run when clicked
    695                 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
     682                'name'                    => false, // Display name for the nav item
     683                'slug'                    => false, // URL slug for the nav item
     684                'item_css_id'             => false, // The CSS ID to apply to the HTML of the nav item
     685                'show_for_displayed_user' => true,  // When viewing another user does this nav item show up?
     686                'site_admin_only'         => false, // Can only site admins see this nav item?
     687                'position'                => 99,    // Index of where this nav item should be positioned
     688                'screen_function'         => false, // The name of the function to run when clicked
     689                'default_subnav_slug'     => false // The slug of the default subnav item to select when clicked
    696690        );
    697691
     
    699693        extract( $r, EXTR_SKIP );
    700694
    701         /* If we don't have the required info we need, don't create this subnav item */
     695        // If we don't have the required info we need, don't create this subnav item
    702696        if ( empty($name) || empty($slug) )
    703697                return false;
    704698
    705         /* If this is for site admins only and the user is not one, don't create the subnav item */
     699        // If this is for site admins only and the user is not one, don't create the subnav item
    706700        if ( $site_admin_only && !is_super_admin() )
    707701                return false;
     
    711705
    712706        $bp->bp_nav[$slug] = array(
    713                 'name' => $name,
    714                 'slug' => $slug,
    715                 'link' => $bp->loggedin_user->domain . $slug . '/',
    716                 'css_id' => $item_css_id,
     707                'name'                    => $name,
     708                'slug'                    => $slug,
     709                'link'                    => $bp->loggedin_user->domain . $slug . '/',
     710                'css_id'                  => $item_css_id,
    717711                'show_for_displayed_user' => $show_for_displayed_user,
    718                 'position' => $position,
    719                 'screen_function' => &$screen_function
     712                'position'                => $position,
     713                'screen_function'         => &$screen_function
    720714        );
    721715
     
    732726         * default subnav function so we can display a directory or something else.
    733727         */
    734         if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
     728        if ( bp_is_root_component( $slug ) && !$bp->displayed_user->id )
    735729                return;
    736730
     
    747741
    748742/**
    749  * bp_core_new_nav_default()
    750  *
    751743 * Modify the default subnav item to load when a top level nav item is clicked.
    752744 *
     
    758750
    759751        $defaults = array(
    760                 'parent_slug' => false, // Slug of the parent
     752                'parent_slug'     => false, // Slug of the parent
    761753                'screen_function' => false, // The name of the function to run when clicked
    762                 'subnav_slug' => false // The slug of the subnav item to select when clicked
     754                'subnav_slug'     => false // The slug of the subnav item to select when clicked
    763755        );
    764756
     
    787779
    788780/**
    789  * bp_core_sort_nav_items()
    790  *
    791781 * We can only sort nav items by their position integer at a later point in time, once all
    792782 * plugins have registered their navigation items.
     
    817807        $bp->bp_nav = &$temp;
    818808}
    819 add_action( 'wp_head', 'bp_core_sort_nav_items' );
     809add_action( 'wp_head',    'bp_core_sort_nav_items' );
    820810add_action( 'admin_head', 'bp_core_sort_nav_items' );
    821811
    822812/**
    823  * bp_core_new_subnav_item()
    824  *
    825813 * Adds a navigation item to the sub navigation array used in BuddyPress themes.
    826814 *
     
    832820
    833821        $defaults = array(
    834                 'name' => false, // Display name for the nav item
    835                 'slug' => false, // URL slug for the nav item
    836                 'parent_slug' => false, // URL slug of the parent nav item
    837                 'parent_url' => false, // URL of the parent item
    838                 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
    839                 'user_has_access' => true, // Can the logged in user see this nav item?
     822                'name'            => false, // Display name for the nav item
     823                'slug'            => false, // URL slug for the nav item
     824                'parent_slug'     => false, // URL slug of the parent nav item
     825                'parent_url'      => false, // URL of the parent item
     826                'item_css_id'     => false, // The CSS ID to apply to the HTML of the nav item
     827                'user_has_access' => true,  // Can the logged in user see this nav item?
    840828                'site_admin_only' => false, // Can only site admins see this nav item?
    841                 'position' => 90, // Index of where this nav item should be positioned
    842                 'screen_function' => false // The name of the function to run when clicked
     829                'position'        => 90,    // Index of where this nav item should be positioned
     830                'screen_function' => false  // The name of the function to run when clicked
    843831        );
    844832
     
    846834        extract( $r, EXTR_SKIP );
    847835
    848         /* If we don't have the required info we need, don't create this subnav item */
    849         if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
    850                 return false;
    851 
    852         /* If this is for site admins only and the user is not one, don't create the subnav item */
     836        // If we don't have the required info we need, don't create this subnav item
     837        if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )
     838                return false;
     839
     840        // If this is for site admins only and the user is not one, don't create the subnav item
    853841        if ( $site_admin_only && !is_super_admin() )
    854842                return false;
     
    858846
    859847        $bp->bp_options_nav[$parent_slug][$slug] = array(
    860                 'name' => $name,
    861                 'link' => $parent_url . $slug . '/',
    862                 'slug' => $slug,
    863                 'css_id' => $item_css_id,
    864                 'position' => $position,
     848                'name'            => $name,
     849                'link'            => $parent_url . $slug . '/',
     850                'slug'            => $slug,
     851                'css_id'          => $item_css_id,
     852                'position'        => $position,
    865853                'user_has_access' => $user_has_access,
    866854                'screen_function' => &$screen_function
    867855        );
    868 
     856       
    869857        if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
    870858                if ( !is_object( $screen_function[0] ) )
     
    899887                ksort( $temp );
    900888                $bp->bp_options_nav[$parent_slug] = &$temp;
    901                 unset($temp);
    902         }
    903 }
    904 add_action( 'wp_head', 'bp_core_sort_subnav_items' );
     889                unset( $temp );
     890        }
     891}
     892add_action( 'wp_head',    'bp_core_sort_subnav_items' );
    905893add_action( 'admin_head', 'bp_core_sort_subnav_items' );
    906894
    907895/**
    908  * bp_core_remove_nav_item()
    909  *
    910896 * Removes a navigation item from the sub navigation array used in BuddyPress themes.
    911897 *
     
    917903        global $bp;
    918904
    919         /* Unset subnav items for this nav item */
     905        // Unset subnav items for this nav item
    920906        if ( is_array( $bp->bp_options_nav[$parent_id] ) ) {
    921907                foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {
     
    935921
    936922/**
    937  * bp_core_remove_subnav_item()
    938  *
    939923 * Removes a navigation item from the sub navigation array used in BuddyPress themes.
    940924 *
     
    962946
    963947/**
    964  * bp_core_reset_subnav_items()
    965  *
    966948 * Clear the subnav items for a specific nav item.
    967949 *
     
    970952 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    971953 */
    972 function bp_core_reset_subnav_items($parent_slug) {
    973         global $bp;
    974 
    975         unset($bp->bp_options_nav[$parent_slug]);
    976 }
    977 
    978 /**
    979  * bp_core_get_random_member()
    980  *
     954function bp_core_reset_subnav_items( $parent_slug ) {
     955        global $bp;
     956
     957        unset( $bp->bp_options_nav[$parent_slug] );
     958}
     959
     960/**
    981961 * Returns the user_id for a user based on their username.
    982962 *
     
    997977
    998978/**
    999  * bp_core_get_userid()
    1000  *
    1001979 * Returns the user_id for a user based on their username.
    1002980 *
     
    1017995
    1018996/**
    1019  * bp_core_get_userid_from_nicename()
    1020  *
    1021997 * Returns the user_id for a user based on their user_nicename.
    1022998 *
     
    10371013
    10381014/**
    1039  * bp_core_get_username()
    1040  *
    10411015 * Returns the username for a user based on their user id.
    10421016 *
     
    10761050        }
    10771051
    1078         /* Add this to cache */
     1052        // Add this to cache
    10791053        if ( !empty( $username ) )
    10801054                wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
     
    10841058
    10851059/**
    1086  * bp_core_get_user_email()
    1087  *
    10881060 * Returns the email address for the user based on user ID
    10891061 *
     
    11051077
    11061078/**
    1107  * bp_core_get_userlink()
    1108  *
    11091079 * Returns a HTML formatted link for a user with the user's full name as the link text.
    11101080 * eg: <a href="http://andy.domain.com/">Andy Peatling</a>
     
    11461116
    11471117/**
    1148  * bp_core_get_user_displayname()
    1149  *
    11501118 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
    11511119 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
     
    12031171}
    12041172add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
    1205 add_filter( 'bp_core_get_user_displayname', 'trim' );
    1206 add_filter( 'bp_core_get_user_displayname', 'stripslashes' );
    1207 
    1208 
    1209 /**
    1210  * bp_core_get_userlink_by_email()
    1211  *
     1173add_filter( 'bp_core_get_user_displayname', 'trim'          );
     1174add_filter( 'bp_core_get_user_displayname', 'stripslashes'  );
     1175
     1176
     1177/**
    12121178 * Returns the user link for the user based on user email address
    12131179 *
     
    12241190
    12251191/**
    1226  * bp_core_get_userlink_by_username()
    1227  *
    12281192 * Returns the user link for the user based on user's username
    12291193 *
     
    12411205
    12421206/**
    1243  * bp_core_get_total_member_count()
    1244  *
    12451207 * Returns the total number of members for the installation.
    12461208 *
     
    12611223
    12621224/**
    1263  * bp_core_is_user_spammer()
    1264  *
    12651225 * Checks if the user has been marked as a spammer.
    12661226 *
     
    12811241
    12821242/**
    1283  * bp_core_is_user_deleted()
    1284  *
    12851243 * Checks if the user has been marked as deleted.
    12861244 *
     
    12961254
    12971255/**
    1298  * bp_core_current_time()
    1299  *
    13001256 * Get the current GMT time to save into the DB
    13011257 *
     
    13111267
    13121268/**
    1313  * bp_core_add_message()
    1314  *
    13151269 * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.
    13161270 *
     
    13231277                $type = 'success';
    13241278
    1325         /* Send the values to the cookie for page reload display */
     1279        // Send the values to the cookie for page reload display
    13261280        @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
    13271281        @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
     
    13311285         * without a page reload
    13321286         */
    1333         $bp->template_message = $message;
     1287        $bp->template_message      = $message;
    13341288        $bp->template_message_type = $type;
    13351289}
    13361290
    13371291/**
    1338  * bp_core_setup_message()
    1339  *
    1340  * Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
    1341  * so that the message can be parsed into the template and displayed to the user.
    1342  *
    1343  * After the message is displayed, it removes the message vars from the cookie so that the message
    1344  * is not shown to the user multiple times.
     1292 * Checks if there is a feedback message in the WP cookie, if so, adds a
     1293 * "template_notices" action so that the message can be parsed into the template
     1294 * and displayed to the user.
     1295 *
     1296 * After the message is displayed, it removes the message vars from the cookie
     1297 * so that the message is not shown to the user multiple times.
    13451298 *
    13461299 * @package BuddyPress Core
     
    13661319
    13671320/**
    1368  * bp_core_render_message()
    1369  *
    13701321 * Renders a feedback message (either error or success message) to the theme template.
    13711322 * The hook action 'template_notices' is used to call this function, it is not called directly.
     
    13781329
    13791330        if ( isset( $bp->template_message ) && $bp->template_message ) {
    1380                 $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
    1381         ?>
     1331                $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error'; ?>
     1332
    13821333                <div id="message" class="<?php echo $type; ?>">
    13831334                        <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p>
    13841335                </div>
     1336
    13851337        <?php
     1338
    13861339                do_action( 'bp_core_render_message' );
    13871340        }
     
    13891342
    13901343/**
    1391  * bp_core_time_since()
    1392  *
    13931344 * Based on function created by Dunstan Orchard - http://1976design.com
    13941345 *
     
    14241375        }
    14251376
    1426         /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
    1427         /* $newer_date will have a value if we want to work out time elapsed between two known dates */
     1377        /**
     1378         * $newer_date will equal false if we want to know the time elapsed between
     1379         * a date and the current time. $newer_date will have a value if we want to
     1380         * work out time elapsed between two known dates.
     1381         */
    14281382        $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
    14291383
    1430         /* Difference in seconds */
     1384        // Difference in seconds
    14311385        $since = $newer_date - $older_date;
    14321386
    1433         /* Something went wrong with date calculation and we ended up with a negative date. */
     1387        // Something went wrong with date calculation and we ended up with a negative date.
    14341388        if ( 0 > $since )
    14351389                return __( 'sometime', 'buddypress' );
     
    14421396         */
    14431397
    1444         /* Step one: the first chunk */
     1398        // Step one: the first chunk
    14451399        for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
    14461400                $seconds = $chunks[$i][0];
    14471401
    1448                 /* Finding the biggest chunk (if the chunk fits, break) */
     1402                // Finding the biggest chunk (if the chunk fits, break)
    14491403                if ( ( $count = floor($since / $seconds) ) != 0 )
    14501404                        break;
    14511405        }
    14521406
    1453         // If $i iterates all the way to $j, then the event happened 0 seconds ago
    1454         if ( !isset( $chunks[$i] ) )
     1407        // If $i iterates all the way to $j, then the event happened 0 seconds ago
     1408        if ( !isset( $chunks[$i] ) )
    14551409                return '0 ' . __( 'seconds', 'buddypress' );
    14561410
    1457         /* Set output var */
     1411        // Set output var
    14581412        $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
    14591413
    1460         /* Step two: the second chunk */
     1414        // Step two: the second chunk
    14611415        if ( $i + 2 < $j ) {
    14621416                $seconds2 = $chunks[$i + 1][0];
     
    14691423        }
    14701424
    1471         if ( !(int)trim($output) )
     1425        if ( !(int)trim( $output ) )
    14721426                $output = '0 ' . __( 'seconds', 'buddypress' );
    14731427
     
    14771431
    14781432/**
    1479  * bp_core_record_activity()
    1480  *
    14811433 * Record user activity to the database. Many functions use a "last active" feature to
    14821434 * show the length of time since the user was last active.
     
    15011453        $current_time = bp_core_current_time();
    15021454
    1503         if ( '' == $activity || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
     1455        if ( empty( $activity ) || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
    15041456                update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time );
    15051457}
     
    15081460
    15091461/**
    1510  * bp_core_get_last_activity()
    1511  *
    15121462 * Formats last activity based on time since date given.
    15131463 *
     
    15191469 */
    15201470function bp_core_get_last_activity( $last_activity_date, $string ) {
    1521         if ( !$last_activity_date || empty( $last_activity_date ) ) {
     1471        if ( !$last_activity_date || empty( $last_activity_date ) )
    15221472                $last_active = __( 'not recently active', 'buddypress' );
    1523         } else {
     1473        else
    15241474                $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
    1525         }
    15261475
    15271476        return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );
     
    15291478
    15301479function bp_core_number_format( $number, $decimals = false ) {
    1531         /* Check we actually have a number first. */
     1480        // Check we actually have a number first.
    15321481        if ( empty( $number ) )
    15331482                return $number;
     
    15371486
    15381487/**
    1539  * bp_core_get_all_posts_for_user()
    1540  *
    15411488 * Fetch every post that is authored by the given user for the current blog.
    15421489 *
     
    15461493 * @return array of post ids.
    15471494 */
    1548 function bp_core_get_all_posts_for_user( $user_id = null ) {
     1495function bp_core_get_all_posts_for_user( $user_id = 0 ) {
    15491496        global $bp, $wpdb;
    15501497
    1551         if ( !$user_id )
     1498        if ( empty( $user_id ) )
    15521499                $user_id = $bp->displayed_user->id;
    15531500
     
    15561503
    15571504/**
    1558  * bp_core_get_site_path()
    1559  *
    15601505 * Get the path of of the current site.
    15611506 *
     
    15771522                        $site_path = '/';
    15781523                else {
    1579                         /* Unset the first three segments (http(s)://domain.com part) */
     1524                        // Unset the first three segments (http(s)://domain.com part)
    15801525                        unset( $site_path[0] );
    15811526                        unset( $site_path[1] );
     
    15931538
    15941539/**
    1595  * bp_core_redirect()
    1596  *
    15971540 * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
    15981541 *
     
    16141557
    16151558/**
    1616  * bp_core_referrer()
    1617  *
    16181559 * Returns the referrer URL without the http(s)://
    16191560 *
     
    16281569
    16291570/**
    1630  * bp_core_add_illegal_names()
    1631  *
    16321571 * Adds illegal names to WP so that root components will not conflict with
    16331572 * blog names on a subdirectory installation.
     
    16401579
    16411580/**
    1642  * bp_core_delete_account()
    1643  *
    16441581 * Allows a user to completely remove their account from the system
    16451582 *
     
    16571594                $user_id = $bp->loggedin_user->id;
    16581595
    1659         /* Make sure account deletion is not disabled */
     1596        // Make sure account deletion is not disabled
    16601597        if ( !empty( $bp->site_options['bp-disable-account-deletion'] ) && !$bp->loggedin_user->is_super_admin )
    16611598                return false;
    16621599
    1663         /* Site admins cannot be deleted */
     1600        // Site admins cannot be deleted
    16641601        if ( is_super_admin( bp_core_get_username( $user_id ) ) )
    16651602                return false;
    16661603
    1667         /* Specifically handle multi-site environment */
     1604        // Specifically handle multi-site environment
    16681605        if ( is_multisite() ) {
    16691606                if ( $wp_version >= '3.0' )
     
    16761613                return wpmu_delete_user( $user_id );
    16771614
    1678         /* Single site user deletion */
     1615        // Single site user deletion
    16791616        } else {
    16801617                require_once( ABSPATH . '/wp-admin/includes/user.php' );
     
    16841621
    16851622/**
    1686  * bp_core_search_site()
    1687  *
    16881623 * A javascript free implementation of the search functions in BuddyPress
    16891624 *
     
    17121647                                $slug = bp_is_active( 'blogs' )  ? $bp->blogs->slug  : '';
    17131648                                break;
     1649
    17141650                        case 'forums':
    17151651                                $slug = bp_is_active( 'forums' ) ? $bp->forums->slug : '';
    17161652                                $query_string = '/?fs=';
    17171653                                break;
     1654
    17181655                        case 'groups':
    17191656                                $slug = bp_is_active( 'groups' ) ? $bp->groups->slug : '';
    17201657                                break;
     1658
    17211659                        case 'members':
    17221660                        default:
     
    17351673add_action( 'init', 'bp_core_action_search_site', 5 );
    17361674
    1737 
    1738 /**
    1739  * bp_core_ucfirst()
    1740  *
     1675/**
    17411676 * Localization safe ucfirst() support.
    17421677 *
     
    17521687}
    17531688
    1754 
    1755 /**
    1756  * bp_core_strip_username_spaces()
    1757  *
     1689/**
    17581690 * Strips spaces from usernames that are created using add_user() and wp_insert_user()
    17591691 *
     
    17611693 */
    17621694function bp_core_strip_username_spaces( $username ) {
    1763         // Don't alter the user_login of existing users, as it causes user_nicename problems.
    1764         // See http://trac.buddypress.org/ticket/2642
    1765         if ( username_exists( $username ) && ( !defined( 'BP_ENABLE_USER_COMPATIBILITY_MODE' ) || !BP_ENABLE_USER_COMPATIBILITY_MODE ) )
    1766                 return $username;
     1695        // Don't alter the user_login of existing users, as it causes user_nicename problems.
     1696        // See http://trac.buddypress.org/ticket/2642
     1697        if ( username_exists( $username ) && ( !defined( 'BP_ENABLE_USER_COMPATIBILITY_MODE' ) || !BP_ENABLE_USER_COMPATIBILITY_MODE ) )
     1698                return $username;
    17671699
    17681700        return str_replace( ' ', '-', $username );
     
    17701702add_action( 'pre_user_login', 'bp_core_strip_username_spaces' );
    17711703
    1772 
    1773 /**
    1774  * bp_core_clear_cache()
     1704/**
    17751705 * REQUIRES WP-SUPER-CACHE
    17761706 *
     
    17911721
    17921722/**
    1793  * bp_core_print_generation_time()
    1794  *
    17951723 * Prints the generation time in the footer of the site.
    17961724 *
     
    18071735
    18081736/**
    1809  * bp_core_add_admin_menu_page()
    1810  *
    18111737 * A better version of add_admin_menu_page() that allows positioning of menus.
    18121738 *
     
    18541780
    18551781/**
    1856  * bp_core_boot_spammer()
    1857  *
    18581782 * When a user logs in, check if they have been marked as a spammer. If yes then simply
    18591783 * redirect them to the home page and stop them from logging in.
     
    18701794
    18711795        if ( !$user = get_userdatabylogin( $username ) )
    1872                 return false;
     1796                return false;
    18731797
    18741798        if ( ( is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
     
    18801804
    18811805/**
    1882  * bp_core_remove_data()
    1883  *
    18841806 * Deletes usermeta for the user when the user is deleted.
    18851807 *
     
    18891811 */
    18901812function bp_core_remove_data( $user_id ) {
    1891         /* Remove usermeta */
     1813        // Remove usermeta
    18921814        delete_user_meta( $user_id, 'last_activity' );
    18931815
    1894         /* Flush the cache to remove the user from all cached objects */
     1816        // Flush the cache to remove the user from all cached objects
    18951817        wp_cache_flush();
    18961818}
    1897 add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
    1898 add_action( 'delete_user', 'bp_core_remove_data' );
     1819add_action( 'wpmu_delete_user',  'bp_core_remove_data' );
     1820add_action( 'delete_user',       'bp_core_remove_data' );
    18991821add_action( 'bp_make_spam_user', 'bp_core_remove_data' );
    19001822
    19011823/**
    1902  * bp_load_buddypress_textdomain()
    1903  *
    19041824 * Load the buddypress translation file for current language
    19051825 *
     
    19221842
    19231843function bp_core_add_ajax_hook() {
    1924         /* Theme only, we already have the wp_ajax_ hook firing in wp-admin */
     1844        // Theme only, we already have the wp_ajax_ hook firing in wp-admin
    19251845        if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) )
    19261846                do_action( 'wp_ajax_' . $_REQUEST['action'] );
     
    19291849
    19301850/**
    1931  * bp_core_update_message()
    1932  *
    19331851 * Add an extra update message to the update plugin notification.
    19341852 *
     
    19411859
    19421860/**
    1943  * bp_core_activation_notice()
    1944  *
    19451861 * When BuddyPress is activated we must make sure that mod_rewrite is enabled.
    19461862 * We must also make sure a BuddyPress compatible theme is enabled. This function
     
    19641880
    19651881        if ( empty( $wp_rewrite->permalink_structure ) ) { ?>
     1882
    19661883                <div id="message" class="updated fade">
    19671884                        <p><?php printf( __( '<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' ) ) ?></p>
    19681885                </div><?php
     1886
    19691887        } else {
    1970                 /* Get current theme info */
     1888                // Get current theme info
    19711889                $ct = current_theme_info();
    19721890
    1973                 /* The best way to remove this notice is to add a "buddypress" tag to your active theme's CSS header. */
     1891                // The best way to remove this notice is to add a "buddypress" tag to
     1892                // your active theme's CSS header.
    19741893                if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?>
     1894
    19751895                        <div id="message" class="updated fade">
    19761896                                <p style="line-height: 150%"><?php printf( __( "<strong>BuddyPress is ready</strong>. You'll need to <a href='%s'>activate a BuddyPress compatible theme</a> to take advantage of all of the 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' ), admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), admin_url( 'plugin-install.php?type=term&tab=search&s=%22bp-template-pack%22' ) ) ?></p>
    1977                         </div><?php
     1897                        </div>
     1898
     1899                <?php
    19781900                }
    19791901        }
     
    19821904
    19831905/**
    1984  * bp_core_activate_site_options()
    1985  *
    19861906 * When switching from single to multisite we need to copy blog options to
    19871907 * site options.
     
    20191939
    20201940/**
    2021  * bp_include()
    2022  *
    20231941 * Allow plugins to include their files ahead of core filters
    20241942 */
     
    20291947
    20301948/**
    2031  * bp_setup_root_components()
    2032  *
    20331949 * Allow core components and dependent plugins to set root components
    20341950 */
     
    20391955
    20401956/**
    2041  * bp_setup_globals()
    2042  *
    20431957 * Allow core components and dependent plugins to set globals
    20441958 */
     
    20491963
    20501964/**
    2051  * bp_setup_nav()
    2052  *
    20531965 * Allow core components and dependent plugins to set their nav
    20541966 */
     
    20591971
    20601972/**
    2061  * bp_setup_widgets()
    2062  *
    20631973 * Allow core components and dependent plugins to register widgets
    20641974 */
     
    20691979
    20701980/**
    2071  * bp_init()
    2072  *
    20731981 * Allow components to initialize themselves cleanly
    20741982 */
     
    20871995
    20881996/**
    2089  * bp_core_add_global_group()
    2090  *
    20911997 * Add's 'bp' to global group of network wide cachable objects
    20921998 *
     
    21022008
    21032009/**
    2104  * bp_core_clear_user_object_cache()
    2105  *
    21062010 * Clears all cached objects for a user, or a user is part of.
    21072011 *
     
    21132017
    21142018// List actions to clear super cached pages on, if super cache is installed
    2115 add_action( 'wp_login', 'bp_core_clear_cache' );
     2019add_action( 'wp_login',              'bp_core_clear_cache' );
    21162020add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );
    21172021
    2118 
    2119 /* DEPRECATED FUNCTIONS ****/
    2120 
    2121 /**
    2122  * bp_core_add_root_component()
    2123  *
    2124  * This function originally let plugins add support for pages in the root of the install.
    2125  * These pages are now handled by actual WordPress pages so this function is deprecated.
    2126  * It now simply facilitates backwards compatibility by adding a WP page if the plugin has not been
    2127  * updated to do so.
    2128  *
    2129  * @deprecated 1.3
    2130  * @deprecated Use wp_insert_post() to create a page
    2131  * @package BuddyPress Core
    2132  * @param $slug str The slug of the component
    2133  * @global $bp BuddyPress global settings
    2134  */
    2135 function bp_core_add_root_component( $slug ) {
    2136         global $bp, $bp_pages;
    2137 
    2138         _deprecated_function( __FUNCTION__, '1.3', 'wp_insert_post()' );
    2139         if ( empty( $bp_pages ) )
    2140                 $bp_pages = bp_core_get_page_names();
    2141 
    2142         $match = false;
    2143 
    2144         /* Check if the slug is registered in the $bp->pages global */
    2145         foreach ( (array)$bp_pages as $key => $page ) {
    2146                 if ( $key == $slug || $page->slug == $slug )
    2147                         $match = true;
    2148         }
    2149 
    2150         /* If there was no match, add a page for this root component */
    2151         if ( empty( $match ) ) {
    2152                 $bp->add_root[] = $slug;
    2153                 add_action( 'init', 'bp_core_create_root_component_page' );
    2154         }
    2155 }
    2156 
    2157 function bp_core_create_root_component_page() {
    2158         global $bp;
    2159 
    2160         $new_page_ids = array();
    2161 
    2162         foreach ( (array)$bp->add_root as $slug )
    2163                 $new_page_ids[$slug] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $slug ), 'post_status' => 'publish', 'post_type' => 'page' ) );
    2164 
    2165         $page_ids = bp_core_get_page_meta();
    2166 
    2167         $page_ids = (array) $page_ids;
    2168         $page_ids = array_merge( (array) $new_page_ids, (array) $page_ids );
    2169 
    2170         bp_core_update_page_meta( $page_ids );
    2171 }
    21722022?>
Note: See TracChangeset for help on using the changeset viewer.