Changeset 2077 for trunk/bp-core.php
- Timestamp:
- 11/02/2009 07:54:21 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core.php
r2059 r2077 4 4 define( 'BP_CORE_DB_VERSION', '1800' ); 5 5 6 /*** 7 * Define the path and url of the BuddyPress plugins directory. 8 * It is important to use plugins_url() core function to obtain 9 * the correct scheme used (http or https). 6 /*** 7 * Define the path and url of the BuddyPress plugins directory. 8 * It is important to use plugins_url() core function to obtain 9 * the correct scheme used (http or https). 10 10 */ 11 11 define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' ); … … 66 66 if ( !defined( 'BP_HOME_BLOG_SLUG' ) ) 67 67 define( 'BP_HOME_BLOG_SLUG', 'blog' ); 68 68 69 /* Register BuddyPress themes contained within the theme folder */ 70 if ( function_exists( 'register_theme_folder' ) ) 71 register_theme_folder( 'buddypress/bp-themes' ); 72 69 73 /* Register BuddyPress themes contained within the theme folder */ 70 74 if ( function_exists( 'register_theme_folder' ) ) … … 94 98 global $displayed_user_id; 95 99 global $action_variables; 96 100 97 101 $current_user = wp_get_current_user(); 98 102 99 /* The domain for the root of the site where the main blog resides */ 103 /* The domain for the root of the site where the main blog resides */ 100 104 $bp->root_domain = bp_core_get_root_domain(); 101 105 102 106 /* The user ID of the user who is currently logged in. */ 103 107 $bp->loggedin_user->id = $current_user->ID; … … 105 109 /* The domain for the user currently logged in. eg: http://domain.com/members/andy */ 106 110 $bp->loggedin_user->domain = bp_core_get_user_domain($current_user->ID); 107 111 108 112 /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */ 109 113 $bp->displayed_user->id = $displayed_user_id; 110 114 111 115 /* The domain for the user currently being displayed */ 112 116 $bp->displayed_user->domain = bp_core_get_user_domain($displayed_user_id); 113 117 114 118 /* The component being used eg: http://domain.com/members/andy/ [profile] */ 115 119 $bp->current_component = $current_component; // type: string 116 120 117 121 /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */ 118 122 $bp->current_action = $current_action; // type: string 119 123 120 124 /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */ 121 125 $bp->action_variables = $action_variables; // type: array 122 126 123 127 /* Only used where a component has a sub item, e.g. groups: http://domain.com/members/andy/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/ 124 128 $bp->current_item = ''; // type: string … … 135 139 /* Sets up the array container for the component navigation rendered by bp_get_nav() */ 136 140 $bp->bp_nav = array(); 137 141 138 142 /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */ 139 143 $bp->bp_options_nav = array(); 140 144 141 145 /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */ 142 146 $bp->bp_options_title = ''; 143 147 144 148 /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */ 145 149 $bp->bp_options_avatar = ''; 146 150 147 151 /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */ 148 152 $bp->active_components = array(); 149 153 150 154 /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */ 151 155 $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', get_site_option( 'user-avatar-default' ) ); 152 156 $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' ); 153 157 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' ); 154 158 155 159 /* Fetch the full name for the logged in and current user */ 156 160 $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id ); … … 162 166 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ 163 167 $bp->is_item_admin = bp_is_home(); 164 168 165 169 /* Used to determine if the logged in user is a moderator for the current content. */ 166 170 $bp->is_item_mod = false; … … 170 174 if ( !$bp->current_component ) 171 175 $bp->current_component = $bp->default_component; 172 176 173 177 do_action( 'bp_core_setup_globals' ); 174 178 } … … 183 187 * 184 188 * For example: http://example.org/search or http://example.org/members 185 * 189 * 186 190 * @package BuddyPress Core 187 191 * @uses bp_core_add_root_component() Adds a slug to the root components global variable. … … 202 206 * 203 207 * Installs the core DB tables for BuddyPress. 204 * 208 * 205 209 * @package BuddyPress Core 206 210 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 211 215 function bp_core_install() { 212 216 global $wpdb, $bp; 213 217 214 218 if ( !empty($wpdb->charset) ) 215 219 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 216 220 217 221 $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} ( 218 222 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 235 239 require_once( ABSPATH . 'wp-admin/upgrade-functions.php' ); 236 240 dbDelta( $sql ); 237 241 238 242 /* Add names of root components to the banned blog list to avoid conflicts */ 239 243 bp_core_add_illegal_names(); 240 244 241 245 update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION ); 242 246 } … … 246 250 * 247 251 * Checks to make sure the database tables are set up for the core component. 248 * 252 * 249 253 * @package BuddyPress Core 250 254 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 260 264 if ( !is_site_admin() ) 261 265 return false; 262 266 263 267 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' ); 264 268 … … 273 277 * 274 278 * Adds the "BuddyPress" admin submenu item to the Site Admin tab. 275 * 279 * 276 280 * @package BuddyPress Core 277 281 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 281 285 */ 282 286 function bp_core_add_admin_menu() { 283 global $wpdb, $bp, $menu;284 285 287 if ( !is_site_admin() ) 286 288 return false; 287 289 288 290 /* Add the administration tab under the "Site Admin" tab for site administrators */ 289 291 bp_core_add_admin_menu_page( array( … … 294 296 'position' => 2 295 297 ) ); 296 298 297 299 add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' ); 298 300 add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' ); … … 305 307 * Checks to see if a component's URL should be in the root, not under a member page: 306 308 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group 307 * 309 * 308 310 * @package BuddyPress Core 309 311 * @return true if root component, else false. … … 319 321 * 320 322 * Sets up the profile navigation item if the Xprofile component is not installed. 321 * 323 * 322 324 * @package BuddyPress Core 323 325 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 329 331 function bp_core_setup_nav() { 330 332 global $bp; 331 332 /*** 333 334 /*** 333 335 * If the extended profiles component is disabled, we need to revert to using the 334 336 * built in WordPress profile information … … 340 342 341 343 /* Add 'Profile' to the main navigation */ 342 bp_core_new_nav_item( array( 344 bp_core_new_nav_item( array( 343 345 'name' => __('Profile', 'buddypress'), 344 346 'slug' => $bp->core->profile->slug, … … 349 351 350 352 $profile_link = $bp->loggedin_user->domain . '/profile/'; 351 353 352 354 /* Add the subnav items to the profile */ 353 355 bp_core_new_subnav_item( array( … … 358 360 'screen_function' => 'bp_core_catch_profile_uri' 359 361 ) ); 360 362 361 363 362 364 if ( 'profile' == $bp->current_component ) { … … 365 367 } else { 366 368 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 367 $bp->bp_options_title = $bp->displayed_user->fullname; 369 $bp->bp_options_title = $bp->displayed_user->fullname; 368 370 } 369 371 } 370 } 372 } 371 373 } 372 374 add_action( 'plugins_loaded', 'bp_core_setup_nav' ); … … 397 399 * Listens to the $bp component and action variables to determine if the user is viewing the members 398 400 * directory page. If they are, it will set up the directory and load the members directory template. 399 * 401 * 400 402 * @package BuddyPress Core 401 403 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 421 423 * this action will fire and mark or unmark the user and their blogs as spam. 422 424 * Must be a site admin for this function to run. 423 * 425 * 424 426 * @package BuddyPress Core 425 427 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 427 429 function bp_core_action_set_spammer_status() { 428 430 global $bp; 429 431 430 432 if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id ) 431 433 return false; 432 434 433 435 if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) { 434 436 /* Check the nonce */ … … 437 439 /* Get the functions file */ 438 440 require( ABSPATH . 'wp-admin/includes/mu.php' ); 439 441 440 442 if ( 'mark-spammer' == $bp->current_action ) 441 443 $is_spam = 1; … … 445 447 /* Get the blogs for the user */ 446 448 $blogs = get_blogs_of_user( $bp->displayed_user->id, true ); 447 449 448 450 foreach ( (array) $blogs as $key => $details ) { 449 451 /* Do not mark the main or current root blog as spam */ 450 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 451 continue; 452 452 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 453 continue; 454 453 455 /* Update the blog status */ 454 456 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 455 457 456 458 /* Fire the standard WPMU hook */ 457 459 do_action( 'make_spam_blog', $details->userblog_id ); 458 460 } 459 461 460 462 /* Finally, mark this user as a spammer */ 461 463 update_user_status( $bp->displayed_user->id, 'spam', $is_spam, 1 ); 462 464 463 465 if ( $is_spam ) 464 466 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) ); 465 467 else 466 468 bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) ); 467 469 468 470 do_action( 'bp_core_action_set_spammer_status' ); 469 471 470 472 bp_core_redirect( wp_get_referer() ); 471 473 } … … 477 479 * 478 480 * Allows a site admin to delete a user from the adminbar menu. 479 * 481 * 480 482 * @package BuddyPress Core 481 483 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 483 485 function bp_core_action_delete_user() { 484 486 global $bp; 485 487 486 488 if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id ) 487 489 return false; 488 490 489 491 if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) { 490 492 /* Check the nonce */ … … 492 494 493 495 $errors = false; 494 496 495 497 if ( bp_core_delete_account( $bp->displayed_user->id ) ) { 496 498 bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) ); … … 499 501 $errors = true; 500 502 } 501 503 502 504 do_action( 'bp_core_action_set_spammer_status', $errors ); 503 505 504 506 if ( $errors ) 505 507 bp_core_redirect( $bp->displayed_user->domain ); … … 525 527 * Returns the domain for the passed user: 526 528 * e.g. http://domain.com/members/andy/ 527 * 529 * 528 530 * @package BuddyPress Core 529 531 * @global $current_user WordPress global variable containing current logged in user information … … 533 535 function bp_core_get_user_domain( $user_id ) { 534 536 global $bp; 535 537 536 538 if ( !$user_id ) return; 537 539 538 540 $ud = get_userdata($user_id); 539 541 540 542 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 541 543 $username = $ud->user_login; 542 544 else 543 545 $username = $ud->user_nicename; 544 546 545 547 /* If we are using a members slug, include it. */ 546 548 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) 547 549 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/' ); 548 550 else 549 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' ); 551 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' ); 550 552 } 551 553 … … 555 557 * Returns the domain for the root blog. 556 558 * eg: http://domain.com/ OR https://domain.com 557 * 559 * 558 560 * @package BuddyPress Core 559 561 * @uses get_blog_option() WordPress function to fetch blog meta. … … 562 564 function bp_core_get_root_domain() { 563 565 global $current_blog; 564 566 565 567 if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) 566 568 $domain = get_blog_option( $current_blog->blog_id, 'siteurl' ); … … 576 578 * Returns the user id for the user that is currently being displayed. 577 579 * eg: http://andy.domain.com/ or http://domain.com/andy/ 578 * 580 * 579 581 * @package BuddyPress Core 580 582 * @global $current_blog WordPress global containing information and settings for the current blog being viewed. … … 590 592 * 591 593 * Adds a navigation item to the main navigation array used in BuddyPress themes. 592 * 594 * 593 595 * @package BuddyPress Core 594 596 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 614 616 if ( empty($name) || empty($slug) ) 615 617 return false; 616 618 617 619 /* If this is for site admins only and the user is not one, don't create the subnav item */ 618 620 if ( $site_admin_only && !is_site_admin() ) 619 621 return false; 620 622 621 623 if ( empty( $item_css_id ) ) 622 624 $item_css_id = $slug; … … 637 639 if ( !$show_for_displayed_user && !bp_is_home() ) 638 640 return false; 639 641 640 642 /*** 641 643 * If we are not viewing a user, and this is a root component, don't attach the … … 660 662 * 661 663 * Modify the default subnav item to load when a top level nav item is clicked. 662 * 664 * 663 665 * @package BuddyPress Core 664 666 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 666 668 function bp_core_new_nav_default( $args = '' ) { 667 669 global $bp; 668 670 669 671 $defaults = array( 670 672 'parent_slug' => false, // Slug of the parent … … 692 694 * We can only sort nav items by their position integer at a later point in time, once all 693 695 * plugins have registered their navigation items. 694 * 696 * 695 697 * @package BuddyPress Core 696 698 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 698 700 function bp_core_sort_nav_items() { 699 701 global $bp; 700 702 701 703 if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) ) 702 704 return false; 703 705 704 706 foreach ( $bp->bp_nav as $slug => $nav_item ) { 705 707 if ( empty( $temp[$nav_item['position']]) ) … … 710 712 $nav_item['position']++; 711 713 } while ( !empty( $temp[$nav_item['position']] ) ); 712 714 713 715 $temp[$nav_item['position']] = $nav_item; 714 716 } 715 717 } 716 718 717 719 ksort( $temp ); 718 $bp->bp_nav = &$temp; 720 $bp->bp_nav = &$temp; 719 721 } 720 722 add_action( 'wp_head', 'bp_core_sort_nav_items' ); … … 724 726 * 725 727 * Removes a navigation item from the main navigation array. 726 * 728 * 727 729 * @package BuddyPress Core 728 730 * @param $slug The slug of the sub navigation item. … … 738 740 * 739 741 * Adds a navigation item to the sub navigation array used in BuddyPress themes. 740 * 742 * 741 743 * @package BuddyPress Core 742 744 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 756 758 'screen_function' => false // The name of the function to run when clicked 757 759 ); 758 760 759 761 $r = wp_parse_args( $args, $defaults ); 760 762 extract( $r, EXTR_SKIP ); … … 763 765 if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) ) 764 766 return false; 765 767 766 768 /* If this is for site admins only and the user is not one, don't create the subnav item */ 767 769 if ( $site_admin_only && !is_site_admin() ) 768 770 return false; 769 771 770 772 if ( empty( $item_css_id ) ) 771 773 $item_css_id = $slug; 772 774 773 775 $bp->bp_options_nav[$parent_slug][$slug] = array( 774 776 'name' => $name, … … 779 781 'user_has_access' => $user_has_access 780 782 ); 781 783 782 784 if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) { 783 785 if ( !is_object( $screen_function[0] ) ) … … 793 795 if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) ) 794 796 return false; 795 797 796 798 foreach ( $bp->bp_options_nav as $parent_slug => $subnav_items ) { 797 799 if ( !is_array( $subnav_items ) ) 798 800 continue; 799 801 800 802 foreach ( $subnav_items as $subnav_item ) { 801 803 if ( empty( $temp[$subnav_item['position']]) ) … … 806 808 $subnav_item['position']++; 807 809 } while ( !empty( $temp[$subnav_item['position']] ) ); 808 810 809 811 $temp[$subnav_item['position']] = $subnav_item; 810 812 } … … 821 823 * 822 824 * Removes a navigation item from the sub navigation array used in BuddyPress themes. 823 * 825 * 824 826 * @package BuddyPress Core 825 827 * @param $parent_id The id of the parent navigation item. … … 828 830 function bp_core_remove_subnav_item( $parent_id, $slug ) { 829 831 global $bp; 830 832 831 833 unset( $bp->bp_options_nav[$parent_id][$slug] ); 832 834 } … … 836 838 * 837 839 * Clear the subnav items for a specific nav item. 838 * 840 * 839 841 * @package BuddyPress Core 840 842 * @param $parent_id The id of the parent navigation item. … … 856 858 * Loads: 857 859 * wp-content/member-themes/[activated_theme]/profile/edit-profile.php 858 * 860 * 859 861 * @package BuddyPress Core 860 862 * @param $username str Username to check. … … 883 885 * http://community.domain.com/members/andy/friends 884 886 * http://domain.com/wpmu/members/andy/friends 885 * 887 * 886 888 * @package BuddyPress Core 887 889 * @param $slug str The slug of the component … … 898 900 * 899 901 * Returns the user_id for a user based on their username. 900 * 902 * 901 903 * @package BuddyPress Core 902 904 * @param $username str Username to check. … … 907 909 function bp_core_get_random_member() { 908 910 global $bp, $wpdb; 909 911 910 912 if ( isset( $_GET['random-member'] ) ) { 911 913 $user = BP_Core_User::get_random_users(1); 912 914 913 915 $ud = get_userdata( $user['users'][0]->user_id ); 914 915 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->user_id ) ); 916 917 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->user_id ) ); 916 918 } 917 919 } … … 922 924 * 923 925 * Returns the user_id for a user based on their username. 924 * 926 * 925 927 * @package BuddyPress Core 926 928 * @param $username str Username to check. … … 931 933 function bp_core_get_userid( $username ) { 932 934 global $wpdb; 933 935 934 936 if ( !empty( $username ) ) 935 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 937 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 936 938 } 937 939 … … 940 942 * 941 943 * Returns the username for a user based on their user id. 942 * 944 * 943 945 * @package BuddyPress Core 944 946 * @param $uid int User ID to check. … … 950 952 function bp_core_get_username( $uid ) { 951 953 global $userdata; 952 954 953 955 if ( $uid == $userdata->ID ) 954 956 $username = __( 'You', 'buddypress' ); 955 957 956 958 if ( !$ud = get_userdata($uid) ) 957 959 return false; 958 959 $username = $ud->user_login; 960 961 $username = $ud->user_login; 960 962 961 963 return apply_filters( 'bp_core_get_username', $username ); … … 966 968 * 967 969 * Returns the URL with no HTML markup for a user based on their user id. 968 * 970 * 969 971 * @package BuddyPress Core 970 972 * @param $uid int User ID to check. … … 976 978 function bp_core_get_userurl( $uid ) { 977 979 global $bp; 978 980 979 981 if ( !is_numeric($uid) ) 980 982 return false; … … 987 989 * 988 990 * Returns the email address for the user based on user ID 989 * 991 * 990 992 * @package BuddyPress Core 991 993 * @param $uid int User ID to check. … … 1005 1007 * eg: <a href="http://andy.domain.com/">Andy Peatling</a> 1006 1008 * Optional parameters will return just the name, or just the URL, or disable "You" text when 1007 * user matches the logged in user. 1009 * user matches the logged in user. 1008 1010 * 1009 1011 * [NOTES: This function needs to be cleaned up or split into separate functions] 1010 * 1012 * 1011 1013 * @package BuddyPress Core 1012 1014 * @param $uid int User ID to check. … … 1023 1025 function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false, $deprecated = false, $with_s = false ) { 1024 1026 global $userdata; 1025 1027 1026 1028 $ud = get_userdata($user_id); 1027 1029 1028 1030 if ( !$ud ) 1029 1031 return false; 1030 1032 1031 if ( function_exists('bp_fetch_user_fullname') ) { 1033 if ( function_exists('bp_fetch_user_fullname') ) { 1032 1034 $display_name = bp_core_get_user_displayname( $user_id ); 1033 1035 1034 1036 if ( $with_s ) 1035 1037 $display_name = sprintf( __( "%s's", 'buddypress' ), $display_name ); 1036 1038 1037 1039 } else { 1038 1040 $display_name = $ud->display_name; 1039 1041 } 1040 1042 1041 1043 if ( $no_anchor ) 1042 1044 return $display_name; … … 1044 1046 if ( !$url = bp_core_get_userurl($user_id) ) 1045 1047 return false; 1046 1048 1047 1049 if ( $just_link ) 1048 1050 return $url; 1049 1051 1050 return '<a href="' . $url . '">' . $display_name . '</a>'; 1052 return '<a href="' . $url . '">' . $display_name . '</a>'; 1051 1053 } 1052 1054 … … 1057 1059 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed. 1058 1060 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set. 1059 * 1061 * 1060 1062 * @package BuddyPress Core 1061 1063 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1068 1070 function bp_core_get_user_displayname( $user_id ) { 1069 1071 global $bp; 1070 1072 1071 1073 if ( !$user_id ) 1072 1074 return false; 1073 1075 1074 1076 if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) { 1075 1077 if ( function_exists('xprofile_install') ) { … … 1088 1090 } else { 1089 1091 $ud = get_userdata($user_id); 1090 1092 1091 1093 if ( !empty( $ud->display_name ) ) 1092 1094 $fullname = $ud->display_name; … … 1094 1096 $fullname = $ud->user_nicename; 1095 1097 } 1096 1098 1097 1099 wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' ); 1098 1100 } 1099 1101 1100 1102 return apply_filters( 'bp_core_get_user_displayname', $fullname ); 1101 1103 } … … 1109 1111 * 1110 1112 * Returns the user link for the user based on user email address 1111 * 1113 * 1112 1114 * @package BuddyPress Core 1113 1115 * @param $email str The email address for the user. … … 1125 1127 * 1126 1128 * Returns the user link for the user based on user's username 1127 * 1129 * 1128 1130 * @package BuddyPress Core 1129 1131 * @param $username str The username for the user. … … 1133 1135 function bp_core_get_userlink_by_username( $username ) { 1134 1136 global $wpdb; 1135 1136 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ); 1137 1138 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ); 1137 1139 return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) ); 1138 1140 } … … 1149 1151 function bp_core_is_user_spammer( $user_id ) { 1150 1152 global $wpdb; 1151 1152 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1153 1154 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1153 1155 } 1154 1156 … … 1164 1166 function bp_core_is_user_deleted( $user_id ) { 1165 1167 global $wpdb; 1166 1167 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1168 1169 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1168 1170 } 1169 1171 … … 1174 1176 if ( !$time ) 1175 1177 return false; 1176 1178 1177 1179 $date = date( "F j, Y ", $time ); 1178 1180 1179 1181 if ( !$just_date ) { 1180 1182 $date .= __('at', 'buddypress') . date( ' g:iA', $time ); 1181 1183 } 1182 1184 1183 1185 return $date; 1184 1186 } … … 1189 1191 * 1190 1192 * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads. 1191 * 1193 * 1192 1194 * @package BuddyPress Core 1193 1195 */ 1194 1196 function bp_core_add_message( $message, $type = false ) { 1195 1197 global $bp; 1196 1198 1197 1199 if ( !$type ) 1198 1200 $type = 'success'; 1199 1201 1200 1202 /* Send the values to the cookie for page reload display */ 1201 1203 @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH ); 1202 1204 @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH ); 1203 1205 1204 1206 /*** 1205 1207 * Send the values to the $bp global so we can still output messages … … 1218 1220 * After the message is displayed, it removes the message vars from the cookie so that the message 1219 1221 * is not shown to the user multiple times. 1220 * 1222 * 1221 1223 * @package BuddyPress Core 1222 1224 * @global $bp_message The message text … … 1229 1231 if ( empty( $bp->template_message ) ) 1230 1232 $bp->template_message = $_COOKIE['bp-message']; 1231 1233 1232 1234 if ( empty( $bp->template_message_type ) ) 1233 1235 $bp->template_message_type = $_COOKIE['bp-message-type']; 1234 1236 1235 1237 add_action( 'template_notices', 'bp_core_render_message' ); 1236 1238 1237 1239 @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH ); 1238 1240 @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH ); … … 1245 1247 * Renders a feedback message (either error or success message) to the theme template. 1246 1248 * The hook action 'template_notices' is used to call this function, it is not called directly. 1247 * 1249 * 1248 1250 * @package BuddyPress Core 1249 1251 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1251 1253 function bp_core_render_message() { 1252 1254 global $bp; 1253 1255 1254 1256 if ( $bp->template_message ) { 1255 1257 $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error'; … … 1260 1262 <?php 1261 1263 do_action( 'bp_core_render_message' ); 1262 } 1264 } 1263 1265 } 1264 1266 … … 1267 1269 * 1268 1270 * Based on function created by Dunstan Orchard - http://1976design.com 1269 * 1271 * 1270 1272 * This function will return an English representation of the time elapsed 1271 1273 * since a given date. … … 1273 1275 * eg: 4 days 1274 1276 * eg: 4 weeks and 6 days 1275 * 1277 * 1276 1278 * @package BuddyPress Core 1277 1279 * @param $older_date int Unix timestamp of date you want to calculate the time since for … … 1291 1293 array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) ) 1292 1294 ); 1293 1295 1294 1296 $older_date = strtotime( gmdate( 'Y-m-d H:i:s', $older_date ) ); 1295 1297 … … 1297 1299 /* $newer_date will have a value if we want to work out time elapsed between two known dates */ 1298 1300 $newer_date = ( !$newer_date ) ? ( strtotime( gmdate( 'Y-m-d H:i:s' ) ) + ( 60*60*0 ) ) : $newer_date; 1299 1301 1300 1302 /* Difference in seconds */ 1301 1303 $since = $newer_date - $older_date; 1302 1304 1303 1305 if ( 0 > $since ) 1304 1306 return __( '[Use GMT Timezone]', 'buddypress' ); … … 1327 1329 $seconds2 = $chunks[$i + 1][0]; 1328 1330 $name2 = $chunks[$i + 1][1]; 1329 1331 1330 1332 //if ( $chunks[$i + 1][1] == __( 'second', 'buddypress' ) ) return $output; 1331 1333 1332 1334 if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) { 1333 1335 /* Add to output var */ … … 1349 1351 * show the length of time since the user was last active. 1350 1352 * This function will update that time as a usermeta setting for the user every 5 minutes. 1351 * 1353 * 1352 1354 * @package BuddyPress Core 1353 1355 * @global $userdata WordPress user data for the current logged in user. … … 1356 1358 function bp_core_record_activity() { 1357 1359 global $bp; 1358 1360 1359 1361 if ( !is_user_logged_in() ) 1360 1362 return false; 1361 1363 1362 1364 $activity = get_usermeta( $bp->loggedin_user->id, 'last_activity' ); 1363 1365 1364 1366 if ( '' == $activity || time() >= strtotime( '+5 minutes', $activity ) ) 1365 1367 update_usermeta( $bp->loggedin_user->id, 'last_activity', time() ); … … 1372 1374 * 1373 1375 * Formats last activity based on time since date given. 1374 * 1376 * 1375 1377 * @package BuddyPress Core 1376 1378 * @param last_activity_date The date of last activity. … … 1384 1386 } else { 1385 1387 if ( strstr( $last_activity_date, '-' ) ) { 1386 $last_active = bp_core_time_since( strtotime( $last_activity_date ) ); 1388 $last_active = bp_core_time_since( strtotime( $last_activity_date ) ); 1387 1389 } else { 1388 $last_active = bp_core_time_since( $last_activity_date ); 1390 $last_active = bp_core_time_since( $last_activity_date ); 1389 1391 } 1390 1392 1391 1393 $last_active = sprintf( $string, $last_active ); 1392 1394 } 1393 1395 1394 1396 return $last_active; 1395 1397 } … … 1400 1402 * 1401 1403 * Fetch every post that is authored by the given user for the current blog. 1402 * 1404 * 1403 1405 * @package BuddyPress Core 1404 1406 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1408 1410 function bp_core_get_all_posts_for_user( $user_id = null ) { 1409 1411 global $bp, $wpdb; 1410 1412 1411 1413 if ( !$user_id ) 1412 1414 $user_id = $bp->displayed_user->id; 1413 1415 1414 1416 return $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type = 'post'", $user_id ) ); 1415 1417 } … … 1420 1422 * 1421 1423 * Get the path of of the current site. 1422 * 1424 * 1423 1425 * @package BuddyPress Core 1424 1426 * @global $comment WordPress comment global for the current comment. … … 1427 1429 function bp_core_get_site_path() { 1428 1430 global $current_site; 1429 1431 1430 1432 return $current_site->path; 1431 1433 } … … 1435 1437 * 1436 1438 * Performs a status safe wp_redirect() that is compatible with bp_catch_uri() 1437 * 1439 * 1438 1440 * @package BuddyPress Core 1439 1441 * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri() … … 1443 1445 function bp_core_redirect( $location, $status = 302 ) { 1444 1446 global $bp_no_status_set; 1445 1446 // Make sure we don't call status_header() in bp_core_do_catch_uri() 1447 1448 // Make sure we don't call status_header() in bp_core_do_catch_uri() 1447 1449 // as this conflicts with wp_redirect() 1448 1450 $bp_no_status_set = true; 1449 1451 1450 1452 wp_redirect( $location, $status ); 1451 1453 die; … … 1456 1458 * 1457 1459 * Returns the referrer URL without the http(s):// 1458 * 1460 * 1459 1461 * @package BuddyPress Core 1460 1462 * @return The referrer URL … … 1473 1475 * 1474 1476 * For example, it would stop someone creating a blog with the slug "groups". 1475 * 1477 * 1476 1478 * @package BuddyPress Core 1477 1479 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1479 1481 function bp_core_add_illegal_names() { 1480 1482 global $bp; 1481 1483 1482 1484 $current = maybe_unserialize( get_site_option( 'illegal_names' ) ); 1483 1485 $bp_illegal_names = $bp->root_components; 1484 1486 1485 1487 if ( is_array( $current ) ) { 1486 1488 foreach( $bp_illegal_names as $bp_illegal_name ) { … … 1501 1503 * 1502 1504 * Sets the "From" name in emails sent to the name of the site and not "WordPress" 1503 * 1505 * 1504 1506 * @package BuddyPress Core 1505 1507 * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table … … 1516 1518 * 1517 1519 * Sets the "From" address in emails sent 1518 * 1520 * 1519 1521 * @package BuddyPress Core 1520 1522 * @global $current_site Object containing current site metadata … … 1532 1534 * 1533 1535 * Allows a user to completely remove their account from the system 1534 * 1536 * 1535 1537 * @package BuddyPress Core 1536 1538 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1564 1566 * 1565 1567 * A javascript free implementation of the search functions in BuddyPress 1566 * 1568 * 1567 1569 * @package BuddyPress Core 1568 1570 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1575 1577 $search_terms = $_POST['search-terms']; 1576 1578 $search_which = $_POST['search-which']; 1577 1579 1578 1580 if ( !$slug || empty( $slug ) ) { 1579 1581 switch ( $search_which ) { … … 1596 1598 } 1597 1599 } 1598 1600 1599 1601 $search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms ); 1600 1602 1601 1603 bp_core_redirect( $search_url ); 1602 1604 } … … 1607 1609 /** 1608 1610 * bp_core_ucfirst() 1609 * 1611 * 1610 1612 * Localization safe ucfirst() support. 1611 * 1613 * 1612 1614 * @package BuddyPress Core 1613 1615 */ … … 1615 1617 if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) { 1616 1618 $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) ); 1617 return $fc.mb_substr( $str, 1 ); 1619 return $fc.mb_substr( $str, 1 ); 1618 1620 } else { 1619 1621 return ucfirst( $str ); … … 1624 1626 /** 1625 1627 * bp_core_strip_username_spaces() 1626 * 1628 * 1627 1629 * Strips spaces from usernames that are created using add_user() and wp_insert_user() 1628 * 1630 * 1629 1631 * @package BuddyPress Core 1630 1632 */ … … 1637 1639 /** 1638 1640 * bp_core_clear_cache() 1639 * REQUIRES WP-SUPER-CACHE 1640 * 1641 * REQUIRES WP-SUPER-CACHE 1642 * 1641 1643 * When wp-super-cache is installed this function will clear cached pages 1642 1644 * so that success/error messages are not cached, or time sensitive content. 1643 * 1645 * 1644 1646 * @package BuddyPress Core 1645 1647 */ 1646 1648 function bp_core_clear_cache() { 1647 1649 global $cache_path, $cache_filename; 1648 1650 1649 1651 if ( function_exists( 'prune_super_cache' ) ) { 1650 1652 do_action( 'bp_core_clear_cache' ); 1651 1652 return prune_super_cache( $cache_path, true ); 1653 1654 return prune_super_cache( $cache_path, true ); 1653 1655 } 1654 1656 } … … 1656 1658 /** 1657 1659 * bp_core_print_generation_time() 1658 * 1660 * 1659 1661 * Prints the generation time in the footer of the site. 1660 * 1662 * 1661 1663 * @package BuddyPress Core 1662 1664 */ … … 1671 1673 /** 1672 1674 * bp_core_add_admin_menu_page() 1673 * 1675 * 1674 1676 * A better version of add_admin_menu_page() that allows positioning of menus. 1675 * 1677 * 1676 1678 * @package BuddyPress Core 1677 1679 */ … … 1691 1693 $r = wp_parse_args( $args, $defaults ); 1692 1694 extract( $r, EXTR_SKIP ); 1693 1695 1694 1696 $file = plugin_basename( $file ); 1695 1697 … … 1708 1710 $position++; 1709 1711 } while ( !empty( $menu[$position] ) ); 1710 1712 1711 1713 $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); 1712 1714 … … 1721 1723 * When a user logs in, check if they have been marked as a spammer. If then simply 1722 1724 * redirect them to the home page and stop them from logging in. 1723 * 1725 * 1724 1726 * @package BuddyPress Core 1725 1727 * @param $username The username of the user … … 1728 1730 function bp_core_boot_spammer( $auth_obj, $username ) { 1729 1731 global $bp; 1730 1732 1731 1733 $user = get_userdatabylogin( $username ); 1732 1734 … … 1740 1742 * 1741 1743 * Deletes usermeta for the user when the user is deleted. 1742 * 1744 * 1743 1745 * @package BuddyPress Core 1744 1746 * @param $user_id The user id for the user to delete usermeta for … … 1758 1760 /** 1759 1761 * bp_load_buddypress_textdomain() 1760 * 1762 * 1761 1763 * Load the buddypress translation file for current language 1762 * 1764 * 1763 1765 * @package BuddyPress Core 1764 1766 */ … … 1766 1768 $locale = apply_filters( 'buddypress_locale', get_locale() ); 1767 1769 $mofile = BP_PLUGIN_DIR . "/bp-languages/buddypress-$locale.mo"; 1768 1770 1769 1771 if ( file_exists( $mofile ) ) 1770 1772 load_textdomain( 'buddypress', $mofile ); … … 1781 1783 /** 1782 1784 * bp_core_update_message() 1783 * 1785 * 1784 1786 * Add an extra update message to the update plugin notification. 1785 * 1787 * 1786 1788 * @package BuddyPress Core 1787 1789 */ … … 1793 1795 /** 1794 1796 * bp_core_clear_user_object_cache() 1795 * 1797 * 1796 1798 * Clears all cached objects for a user, or a user is part of. 1797 * 1799 * 1798 1800 * @package BuddyPress Core 1799 1801 */
Note: See TracChangeset
for help on using the changeset viewer.