Changeset 3728 for trunk/bp-core.php
- Timestamp:
- 01/18/2011 12:53:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core.php
r3720 r3728 9 9 define( 'BP_PLUGIN_URL', plugins_url( $path = '/buddypress' ) ); 10 10 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. 12 12 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' ); 13 13 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. 15 15 if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) ) 16 16 require( WP_PLUGIN_DIR . '/bp-custom.php' ); 17 17 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. 19 19 if ( !defined( 'CUSTOM_USER_TABLE' ) ) 20 20 define( 'CUSTOM_USER_TABLE', $wpdb->base_prefix . 'users' ); … … 25 25 // The search slug has to be defined nice and early because of the way search requests are loaded 26 26 if ( !defined( 'BP_SEARCH_SLUG' ) ) 27 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. 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' ); 38 38 require ( 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. */ 39 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' ); 40 require ( 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. 42 43 if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) ) 43 44 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' ); 44 45 45 / * Register BuddyPress themes contained within the bp-theme folder */46 // Register BuddyPress themes contained within the bp-theme folder 46 47 register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' ); 47 48 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 /** 55 52 * Sets up default global BuddyPress configuration settings and stores 56 53 * them in a $bp variable. … … 76 73 77 74 // 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(); 79 76 80 77 // 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 *****************************************************/ 82 81 83 82 // Set up the members id and active components entry 84 $bp->members->id = 'members'; 85 83 $bp->members->id = 'members'; 84 85 // Members Slugs 86 86 $bp->members->slug = $bp->pages->members->slug; 87 87 $bp->active_components[$bp->members->slug] = $bp->members->id; … … 89 89 // The user ID of the user who is currently logged in. 90 90 $bp->loggedin_user->id = $current_user->ID; 91 92 /** Logged in user ********************************************************/ 91 93 92 94 // The domain for the user currently logged in. eg: http://domain.com/members/andy … … 100 102 $bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6 101 103 104 /** Displayed user ********************************************************/ 105 102 106 // The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php 103 107 $bp->displayed_user->id = $displayed_user_id; … … 109 113 $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id ); 110 114 115 /** Component and Action **************************************************/ 116 111 117 // The component being used eg: http://domain.com/members/andy/ [profile] 112 118 $bp->current_component = $current_component; // type: string … … 121 127 $bp->current_item = ''; // type: string 122 128 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) 124 131 $bp->is_single_item = false; 125 132 … … 134 141 } 135 142 136 // Fetches all of the core database based BuddyPress settings in one foul swoop143 // Fetches all of the core BuddyPress settings in one fell swoop 137 144 $bp->site_options = bp_core_get_site_options(); 138 145 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() 140 148 $bp->bp_nav = array(); 141 149 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() 143 152 $bp->bp_options_nav = array(); 144 153 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. 146 156 $bp->active_components = array(); 157 158 /** Avatars ***************************************************************/ 147 159 148 160 // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar … … 155 167 $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id ); 156 168 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 */ 161 175 $bp->is_item_admin = bp_user_has_access(); 162 176 … … 164 178 $bp->is_item_mod = false; 165 179 180 // Notifications Table 166 181 $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; 167 182 183 // Default Component 168 184 if ( !$bp->current_component && $bp->displayed_user->id ) 169 185 $bp->current_component = $bp->default_component; 170 186 171 187 // The default text for the members directory search box 172 188 $bp->default_search_strings[$bp->members->slug] = __( 'Search Members...', 'buddypress' ); 173 189 174 190 do_action( 'bp_core_setup_globals' ); … … 177 193 178 194 /** 179 * bp_core_get_table_prefix()180 *181 195 * Allow filtering of database prefix. Intended for use in multinetwork installations. 182 196 * … … 191 205 192 206 /** 193 * bp_core_define_slugs()194 *195 207 * Define the slugs used for BuddyPress pages, based on the slugs of the WP pages used. 196 208 * These can be overridden manually by defining these slugs in wp-config.php. … … 215 227 216 228 /** 217 * bp_core_get_page_meta()218 *219 229 * Fetches BP pages from the meta table, depending on setup 220 230 * … … 231 241 232 242 /** 233 * bp_core_update_page_meta()234 *235 243 * Stores BP pages in the meta table, depending on setup 236 244 * … … 285 293 } 286 294 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 */ 318 function 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 /** 290 326 * Initializes the wp-admin area "BuddyPress" menus and sub menus. 291 327 * … … 302 338 303 339 /** 304 * bp_core_add_admin_menu()305 *306 340 * Adds the "BuddyPress" admin submenu item to the Site Admin tab. 307 341 * … … 334 368 335 369 /** 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-group340 *341 * @package BuddyPress Core342 * @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 *358 370 * Sets up the profile navigation item if the Xprofile component is not installed. 359 371 * … … 419 431 420 432 /** 421 * bp_core_action_directory_members()422 *423 433 * Listens to the $bp component and action variables to determine if the user is viewing the members 424 434 * directory page. If they are, it will set up the directory and load the members directory template. … … 442 452 443 453 /** 444 * bp_core_action_set_spammer_status()445 *446 454 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu 447 455 * this action will fire and mark or unmark the user and their blogs as spam. … … 458 466 459 467 if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) { 460 / * Check the nonce */468 // Check the nonce 461 469 check_admin_referer( 'mark-unmark-spammer' ); 462 470 463 / * Get the functions file */471 // Get the functions file 464 472 if ( is_multisite() ) 465 473 require_once( ABSPATH . 'wp-admin/includes/ms.php' ); … … 470 478 $is_spam = 0; 471 479 472 / * Get the blogs for the user */480 // Get the blogs for the user 473 481 $blogs = get_blogs_of_user( $bp->displayed_user->id, true ); 474 482 475 483 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 477 485 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 478 486 continue; 479 487 480 / * Update the blog status */488 // Update the blog status 481 489 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 482 490 483 / * Fire the standard WPMU hook */491 // Fire the standard multisite hook 484 492 do_action( 'make_spam_blog', $details->userblog_id ); 485 493 } 486 494 487 / * Finally, mark this user as a spammer */495 // Finally, mark this user as a spammer 488 496 if ( is_multisite() ) 489 497 $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) ); … … 496 504 bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) ); 497 505 498 / * Hide this user's activity */506 // Hide this user's activity 499 507 if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) ) 500 508 bp_activity_hide_user_activity( $bp->displayed_user->id ); 501 509 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 503 512 if ( $is_spam ) 504 513 do_action( 'bp_make_spam_user', $bp->displayed_user->id ); 505 514 506 515 do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam ); … … 512 521 513 522 /** 514 * bp_core_action_delete_user()515 *516 523 * Allows a site admin to delete a user from the adminbar menu. 517 524 * … … 526 533 527 534 if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) { 528 / * Check the nonce */535 // Check the nonce 529 536 check_admin_referer( 'delete-user' ); 530 537 … … 559 566 560 567 /** 561 * bp_core_get_users()562 *563 568 * Return an array of users IDs based on the parameters passed. 564 569 * … … 587 592 588 593 /** 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/ 593 595 * 594 596 * @package BuddyPress Core … … 605 607 $username = bp_core_get_username( $user_id, $user_nicename, $user_login ); 606 608 607 / * If we are using a members slug, include it. */609 // If we are using a members slug, include it. 608 610 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) 609 611 $domain = $bp->root_domain . '/' . $bp->members->slug . '/' . $username . '/'; … … 611 613 $domain = $bp->root_domain . '/' . $username . '/'; 612 614 613 / * Cache the link */615 // Cache the link 614 616 if ( !empty( $domain ) ) 615 617 wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' ); … … 620 622 621 623 /** 622 * bp_core_get_core_userdata()623 *624 624 * Fetch everything in the wp_users table for a user, without any usermeta. 625 625 * … … 640 640 641 641 /** 642 * bp_core_get_root_domain()643 *644 642 * Returns the domain for the root blog. 645 643 * eg: http://domain.com/ OR https://domain.com … … 661 659 662 660 /** 663 * bp_core_get_displayed_userid()664 *665 661 * Returns the user id for the user that is currently being displayed. 666 662 * eg: http://andy.domain.com/ or http://domain.com/andy/ … … 675 671 676 672 /** 677 * bp_core_new_nav_item()678 *679 673 * Adds a navigation item to the main navigation array used in BuddyPress themes. 680 674 * … … 686 680 687 681 $defaults = array( 688 'name' => false, // Display name for the nav item689 'slug' => false, // URL slug for the nav item690 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item691 '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 positioned694 'screen_function' => false, // The name of the function to run when clicked695 'default_subnav_slug' => false// The slug of the default subnav item to select when clicked682 '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 696 690 ); 697 691 … … 699 693 extract( $r, EXTR_SKIP ); 700 694 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 702 696 if ( empty($name) || empty($slug) ) 703 697 return false; 704 698 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 706 700 if ( $site_admin_only && !is_super_admin() ) 707 701 return false; … … 711 705 712 706 $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, 717 711 'show_for_displayed_user' => $show_for_displayed_user, 718 'position' => $position,719 'screen_function' => &$screen_function712 'position' => $position, 713 'screen_function' => &$screen_function 720 714 ); 721 715 … … 732 726 * default subnav function so we can display a directory or something else. 733 727 */ 734 if ( bp_ core_is_root_component( $slug ) && !$bp->displayed_user->id )728 if ( bp_is_root_component( $slug ) && !$bp->displayed_user->id ) 735 729 return; 736 730 … … 747 741 748 742 /** 749 * bp_core_new_nav_default()750 *751 743 * Modify the default subnav item to load when a top level nav item is clicked. 752 744 * … … 758 750 759 751 $defaults = array( 760 'parent_slug' => false, // Slug of the parent752 'parent_slug' => false, // Slug of the parent 761 753 '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 clicked754 'subnav_slug' => false // The slug of the subnav item to select when clicked 763 755 ); 764 756 … … 787 779 788 780 /** 789 * bp_core_sort_nav_items()790 *791 781 * We can only sort nav items by their position integer at a later point in time, once all 792 782 * plugins have registered their navigation items. … … 817 807 $bp->bp_nav = &$temp; 818 808 } 819 add_action( 'wp_head', 'bp_core_sort_nav_items' );809 add_action( 'wp_head', 'bp_core_sort_nav_items' ); 820 810 add_action( 'admin_head', 'bp_core_sort_nav_items' ); 821 811 822 812 /** 823 * bp_core_new_subnav_item()824 *825 813 * Adds a navigation item to the sub navigation array used in BuddyPress themes. 826 814 * … … 832 820 833 821 $defaults = array( 834 'name' => false, // Display name for the nav item835 'slug' => false, // URL slug for the nav item836 'parent_slug' => false, // URL slug of the parent nav item837 'parent_url' => false, // URL of the parent item838 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item839 '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? 840 828 'site_admin_only' => false, // Can only site admins see this nav item? 841 'position' => 90,// Index of where this nav item should be positioned842 'screen_function' => false // The name of the function to run when clicked829 'position' => 90, // Index of where this nav item should be positioned 830 'screen_function' => false // The name of the function to run when clicked 843 831 ); 844 832 … … 846 834 extract( $r, EXTR_SKIP ); 847 835 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 853 841 if ( $site_admin_only && !is_super_admin() ) 854 842 return false; … … 858 846 859 847 $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, 865 853 'user_has_access' => $user_has_access, 866 854 'screen_function' => &$screen_function 867 855 ); 868 856 869 857 if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) { 870 858 if ( !is_object( $screen_function[0] ) ) … … 899 887 ksort( $temp ); 900 888 $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 } 892 add_action( 'wp_head', 'bp_core_sort_subnav_items' ); 905 893 add_action( 'admin_head', 'bp_core_sort_subnav_items' ); 906 894 907 895 /** 908 * bp_core_remove_nav_item()909 *910 896 * Removes a navigation item from the sub navigation array used in BuddyPress themes. 911 897 * … … 917 903 global $bp; 918 904 919 / * Unset subnav items for this nav item */905 // Unset subnav items for this nav item 920 906 if ( is_array( $bp->bp_options_nav[$parent_id] ) ) { 921 907 foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) { … … 935 921 936 922 /** 937 * bp_core_remove_subnav_item()938 *939 923 * Removes a navigation item from the sub navigation array used in BuddyPress themes. 940 924 * … … 962 946 963 947 /** 964 * bp_core_reset_subnav_items()965 *966 948 * Clear the subnav items for a specific nav item. 967 949 * … … 970 952 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 971 953 */ 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 * 954 function bp_core_reset_subnav_items( $parent_slug ) { 955 global $bp; 956 957 unset( $bp->bp_options_nav[$parent_slug] ); 958 } 959 960 /** 981 961 * Returns the user_id for a user based on their username. 982 962 * … … 997 977 998 978 /** 999 * bp_core_get_userid()1000 *1001 979 * Returns the user_id for a user based on their username. 1002 980 * … … 1017 995 1018 996 /** 1019 * bp_core_get_userid_from_nicename()1020 *1021 997 * Returns the user_id for a user based on their user_nicename. 1022 998 * … … 1037 1013 1038 1014 /** 1039 * bp_core_get_username()1040 *1041 1015 * Returns the username for a user based on their user id. 1042 1016 * … … 1076 1050 } 1077 1051 1078 / * Add this to cache */1052 // Add this to cache 1079 1053 if ( !empty( $username ) ) 1080 1054 wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' ); … … 1084 1058 1085 1059 /** 1086 * bp_core_get_user_email()1087 *1088 1060 * Returns the email address for the user based on user ID 1089 1061 * … … 1105 1077 1106 1078 /** 1107 * bp_core_get_userlink()1108 *1109 1079 * Returns a HTML formatted link for a user with the user's full name as the link text. 1110 1080 * eg: <a href="http://andy.domain.com/">Andy Peatling</a> … … 1146 1116 1147 1117 /** 1148 * bp_core_get_user_displayname()1149 *1150 1118 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed. 1151 1119 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set. … … 1203 1171 } 1204 1172 add_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 * 1173 add_filter( 'bp_core_get_user_displayname', 'trim' ); 1174 add_filter( 'bp_core_get_user_displayname', 'stripslashes' ); 1175 1176 1177 /** 1212 1178 * Returns the user link for the user based on user email address 1213 1179 * … … 1224 1190 1225 1191 /** 1226 * bp_core_get_userlink_by_username()1227 *1228 1192 * Returns the user link for the user based on user's username 1229 1193 * … … 1241 1205 1242 1206 /** 1243 * bp_core_get_total_member_count()1244 *1245 1207 * Returns the total number of members for the installation. 1246 1208 * … … 1261 1223 1262 1224 /** 1263 * bp_core_is_user_spammer()1264 *1265 1225 * Checks if the user has been marked as a spammer. 1266 1226 * … … 1281 1241 1282 1242 /** 1283 * bp_core_is_user_deleted()1284 *1285 1243 * Checks if the user has been marked as deleted. 1286 1244 * … … 1296 1254 1297 1255 /** 1298 * bp_core_current_time()1299 *1300 1256 * Get the current GMT time to save into the DB 1301 1257 * … … 1311 1267 1312 1268 /** 1313 * bp_core_add_message()1314 *1315 1269 * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads. 1316 1270 * … … 1323 1277 $type = 'success'; 1324 1278 1325 / * Send the values to the cookie for page reload display */1279 // Send the values to the cookie for page reload display 1326 1280 @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH ); 1327 1281 @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH ); … … 1331 1285 * without a page reload 1332 1286 */ 1333 $bp->template_message = $message;1287 $bp->template_message = $message; 1334 1288 $bp->template_message_type = $type; 1335 1289 } 1336 1290 1337 1291 /** 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. 1345 1298 * 1346 1299 * @package BuddyPress Core … … 1366 1319 1367 1320 /** 1368 * bp_core_render_message()1369 *1370 1321 * Renders a feedback message (either error or success message) to the theme template. 1371 1322 * The hook action 'template_notices' is used to call this function, it is not called directly. … … 1378 1329 1379 1330 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 1382 1333 <div id="message" class="<?php echo $type; ?>"> 1383 1334 <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p> 1384 1335 </div> 1336 1385 1337 <?php 1338 1386 1339 do_action( 'bp_core_render_message' ); 1387 1340 } … … 1389 1342 1390 1343 /** 1391 * bp_core_time_since()1392 *1393 1344 * Based on function created by Dunstan Orchard - http://1976design.com 1394 1345 * … … 1424 1375 } 1425 1376 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 */ 1428 1382 $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date; 1429 1383 1430 / * Difference in seconds */1384 // Difference in seconds 1431 1385 $since = $newer_date - $older_date; 1432 1386 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. 1434 1388 if ( 0 > $since ) 1435 1389 return __( 'sometime', 'buddypress' ); … … 1442 1396 */ 1443 1397 1444 / * Step one: the first chunk */1398 // Step one: the first chunk 1445 1399 for ( $i = 0, $j = count($chunks); $i < $j; $i++) { 1446 1400 $seconds = $chunks[$i][0]; 1447 1401 1448 / * Finding the biggest chunk (if the chunk fits, break) */1402 // Finding the biggest chunk (if the chunk fits, break) 1449 1403 if ( ( $count = floor($since / $seconds) ) != 0 ) 1450 1404 break; 1451 1405 } 1452 1406 1453 1454 1407 // If $i iterates all the way to $j, then the event happened 0 seconds ago 1408 if ( !isset( $chunks[$i] ) ) 1455 1409 return '0 ' . __( 'seconds', 'buddypress' ); 1456 1410 1457 / * Set output var */1411 // Set output var 1458 1412 $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2]; 1459 1413 1460 / * Step two: the second chunk */1414 // Step two: the second chunk 1461 1415 if ( $i + 2 < $j ) { 1462 1416 $seconds2 = $chunks[$i + 1][0]; … … 1469 1423 } 1470 1424 1471 if ( !(int)trim( $output) )1425 if ( !(int)trim( $output ) ) 1472 1426 $output = '0 ' . __( 'seconds', 'buddypress' ); 1473 1427 … … 1477 1431 1478 1432 /** 1479 * bp_core_record_activity()1480 *1481 1433 * Record user activity to the database. Many functions use a "last active" feature to 1482 1434 * show the length of time since the user was last active. … … 1501 1453 $current_time = bp_core_current_time(); 1502 1454 1503 if ( '' == $activity|| strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )1455 if ( empty( $activity ) || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) ) 1504 1456 update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time ); 1505 1457 } … … 1508 1460 1509 1461 /** 1510 * bp_core_get_last_activity()1511 *1512 1462 * Formats last activity based on time since date given. 1513 1463 * … … 1519 1469 */ 1520 1470 function 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 ) ) 1522 1472 $last_active = __( 'not recently active', 'buddypress' ); 1523 } else {1473 else 1524 1474 $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) ); 1525 }1526 1475 1527 1476 return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string ); … … 1529 1478 1530 1479 function bp_core_number_format( $number, $decimals = false ) { 1531 / * Check we actually have a number first. */1480 // Check we actually have a number first. 1532 1481 if ( empty( $number ) ) 1533 1482 return $number; … … 1537 1486 1538 1487 /** 1539 * bp_core_get_all_posts_for_user()1540 *1541 1488 * Fetch every post that is authored by the given user for the current blog. 1542 1489 * … … 1546 1493 * @return array of post ids. 1547 1494 */ 1548 function bp_core_get_all_posts_for_user( $user_id = null) {1495 function bp_core_get_all_posts_for_user( $user_id = 0 ) { 1549 1496 global $bp, $wpdb; 1550 1497 1551 if ( !$user_id)1498 if ( empty( $user_id ) ) 1552 1499 $user_id = $bp->displayed_user->id; 1553 1500 … … 1556 1503 1557 1504 /** 1558 * bp_core_get_site_path()1559 *1560 1505 * Get the path of of the current site. 1561 1506 * … … 1577 1522 $site_path = '/'; 1578 1523 else { 1579 / * Unset the first three segments (http(s)://domain.com part) */1524 // Unset the first three segments (http(s)://domain.com part) 1580 1525 unset( $site_path[0] ); 1581 1526 unset( $site_path[1] ); … … 1593 1538 1594 1539 /** 1595 * bp_core_redirect()1596 *1597 1540 * Performs a status safe wp_redirect() that is compatible with bp_catch_uri() 1598 1541 * … … 1614 1557 1615 1558 /** 1616 * bp_core_referrer()1617 *1618 1559 * Returns the referrer URL without the http(s):// 1619 1560 * … … 1628 1569 1629 1570 /** 1630 * bp_core_add_illegal_names()1631 *1632 1571 * Adds illegal names to WP so that root components will not conflict with 1633 1572 * blog names on a subdirectory installation. … … 1640 1579 1641 1580 /** 1642 * bp_core_delete_account()1643 *1644 1581 * Allows a user to completely remove their account from the system 1645 1582 * … … 1657 1594 $user_id = $bp->loggedin_user->id; 1658 1595 1659 / * Make sure account deletion is not disabled */1596 // Make sure account deletion is not disabled 1660 1597 if ( !empty( $bp->site_options['bp-disable-account-deletion'] ) && !$bp->loggedin_user->is_super_admin ) 1661 1598 return false; 1662 1599 1663 / * Site admins cannot be deleted */1600 // Site admins cannot be deleted 1664 1601 if ( is_super_admin( bp_core_get_username( $user_id ) ) ) 1665 1602 return false; 1666 1603 1667 / * Specifically handle multi-site environment */1604 // Specifically handle multi-site environment 1668 1605 if ( is_multisite() ) { 1669 1606 if ( $wp_version >= '3.0' ) … … 1676 1613 return wpmu_delete_user( $user_id ); 1677 1614 1678 / * Single site user deletion */1615 // Single site user deletion 1679 1616 } else { 1680 1617 require_once( ABSPATH . '/wp-admin/includes/user.php' ); … … 1684 1621 1685 1622 /** 1686 * bp_core_search_site()1687 *1688 1623 * A javascript free implementation of the search functions in BuddyPress 1689 1624 * … … 1712 1647 $slug = bp_is_active( 'blogs' ) ? $bp->blogs->slug : ''; 1713 1648 break; 1649 1714 1650 case 'forums': 1715 1651 $slug = bp_is_active( 'forums' ) ? $bp->forums->slug : ''; 1716 1652 $query_string = '/?fs='; 1717 1653 break; 1654 1718 1655 case 'groups': 1719 1656 $slug = bp_is_active( 'groups' ) ? $bp->groups->slug : ''; 1720 1657 break; 1658 1721 1659 case 'members': 1722 1660 default: … … 1735 1673 add_action( 'init', 'bp_core_action_search_site', 5 ); 1736 1674 1737 1738 /** 1739 * bp_core_ucfirst() 1740 * 1675 /** 1741 1676 * Localization safe ucfirst() support. 1742 1677 * … … 1752 1687 } 1753 1688 1754 1755 /** 1756 * bp_core_strip_username_spaces() 1757 * 1689 /** 1758 1690 * Strips spaces from usernames that are created using add_user() and wp_insert_user() 1759 1691 * … … 1761 1693 */ 1762 1694 function bp_core_strip_username_spaces( $username ) { 1763 1764 1765 1766 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; 1767 1699 1768 1700 return str_replace( ' ', '-', $username ); … … 1770 1702 add_action( 'pre_user_login', 'bp_core_strip_username_spaces' ); 1771 1703 1772 1773 /** 1774 * bp_core_clear_cache() 1704 /** 1775 1705 * REQUIRES WP-SUPER-CACHE 1776 1706 * … … 1791 1721 1792 1722 /** 1793 * bp_core_print_generation_time()1794 *1795 1723 * Prints the generation time in the footer of the site. 1796 1724 * … … 1807 1735 1808 1736 /** 1809 * bp_core_add_admin_menu_page()1810 *1811 1737 * A better version of add_admin_menu_page() that allows positioning of menus. 1812 1738 * … … 1854 1780 1855 1781 /** 1856 * bp_core_boot_spammer()1857 *1858 1782 * When a user logs in, check if they have been marked as a spammer. If yes then simply 1859 1783 * redirect them to the home page and stop them from logging in. … … 1870 1794 1871 1795 if ( !$user = get_userdatabylogin( $username ) ) 1872 1796 return false; 1873 1797 1874 1798 if ( ( is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status ) … … 1880 1804 1881 1805 /** 1882 * bp_core_remove_data()1883 *1884 1806 * Deletes usermeta for the user when the user is deleted. 1885 1807 * … … 1889 1811 */ 1890 1812 function bp_core_remove_data( $user_id ) { 1891 / * Remove usermeta */1813 // Remove usermeta 1892 1814 delete_user_meta( $user_id, 'last_activity' ); 1893 1815 1894 / * Flush the cache to remove the user from all cached objects */1816 // Flush the cache to remove the user from all cached objects 1895 1817 wp_cache_flush(); 1896 1818 } 1897 add_action( 'wpmu_delete_user', 'bp_core_remove_data' );1898 add_action( 'delete_user', 'bp_core_remove_data' );1819 add_action( 'wpmu_delete_user', 'bp_core_remove_data' ); 1820 add_action( 'delete_user', 'bp_core_remove_data' ); 1899 1821 add_action( 'bp_make_spam_user', 'bp_core_remove_data' ); 1900 1822 1901 1823 /** 1902 * bp_load_buddypress_textdomain()1903 *1904 1824 * Load the buddypress translation file for current language 1905 1825 * … … 1922 1842 1923 1843 function 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 1925 1845 if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) ) 1926 1846 do_action( 'wp_ajax_' . $_REQUEST['action'] ); … … 1929 1849 1930 1850 /** 1931 * bp_core_update_message()1932 *1933 1851 * Add an extra update message to the update plugin notification. 1934 1852 * … … 1941 1859 1942 1860 /** 1943 * bp_core_activation_notice()1944 *1945 1861 * When BuddyPress is activated we must make sure that mod_rewrite is enabled. 1946 1862 * We must also make sure a BuddyPress compatible theme is enabled. This function … … 1964 1880 1965 1881 if ( empty( $wp_rewrite->permalink_structure ) ) { ?> 1882 1966 1883 <div id="message" class="updated fade"> 1967 1884 <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> 1968 1885 </div><?php 1886 1969 1887 } else { 1970 / * Get current theme info */1888 // Get current theme info 1971 1889 $ct = current_theme_info(); 1972 1890 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. 1974 1893 if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?> 1894 1975 1895 <div id="message" class="updated fade"> 1976 1896 <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 1978 1900 } 1979 1901 } … … 1982 1904 1983 1905 /** 1984 * bp_core_activate_site_options()1985 *1986 1906 * When switching from single to multisite we need to copy blog options to 1987 1907 * site options. … … 2019 1939 2020 1940 /** 2021 * bp_include()2022 *2023 1941 * Allow plugins to include their files ahead of core filters 2024 1942 */ … … 2029 1947 2030 1948 /** 2031 * bp_setup_root_components()2032 *2033 1949 * Allow core components and dependent plugins to set root components 2034 1950 */ … … 2039 1955 2040 1956 /** 2041 * bp_setup_globals()2042 *2043 1957 * Allow core components and dependent plugins to set globals 2044 1958 */ … … 2049 1963 2050 1964 /** 2051 * bp_setup_nav()2052 *2053 1965 * Allow core components and dependent plugins to set their nav 2054 1966 */ … … 2059 1971 2060 1972 /** 2061 * bp_setup_widgets()2062 *2063 1973 * Allow core components and dependent plugins to register widgets 2064 1974 */ … … 2069 1979 2070 1980 /** 2071 * bp_init()2072 *2073 1981 * Allow components to initialize themselves cleanly 2074 1982 */ … … 2087 1995 2088 1996 /** 2089 * bp_core_add_global_group()2090 *2091 1997 * Add's 'bp' to global group of network wide cachable objects 2092 1998 * … … 2102 2008 2103 2009 /** 2104 * bp_core_clear_user_object_cache()2105 *2106 2010 * Clears all cached objects for a user, or a user is part of. 2107 2011 * … … 2113 2017 2114 2018 // List actions to clear super cached pages on, if super cache is installed 2115 add_action( 'wp_login', 'bp_core_clear_cache' );2019 add_action( 'wp_login', 'bp_core_clear_cache' ); 2116 2020 add_action( 'bp_core_render_notice', 'bp_core_clear_cache' ); 2117 2021 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 been2127 * updated to do so.2128 *2129 * @deprecated 1.32130 * @deprecated Use wp_insert_post() to create a page2131 * @package BuddyPress Core2132 * @param $slug str The slug of the component2133 * @global $bp BuddyPress global settings2134 */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 }2172 2022 ?>
Note: See TracChangeset
for help on using the changeset viewer.