Changeset 3767
- Timestamp:
- 01/20/2011 01:30:01 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
-
bp-core/admin/bp-core-admin.php (modified) (1 diff)
-
bp-core/bp-core-buddybar.php (added)
-
bp-core/bp-core-catchuri.php (modified) (11 diffs)
-
bp-core/bp-core-functions.php (added)
-
bp-core/bp-core-loader.php (modified) (11 diffs)
-
bp-core/bp-core-template.php (modified) (1 diff)
-
bp-users/bp-users-actions.php (modified) (1 diff)
-
bp-users/bp-users-filters.php (modified) (1 diff)
-
bp-users/bp-users-functions.php (modified) (1 diff)
-
bp-users/bp-users-loader.php (modified) (3 diffs)
-
bp-users/bp-users-screens.php (modified) (1 diff)
-
bp-users/bp-users-template.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/admin/bp-core-admin.php
r3746 r3767 1 1 <?php 2 3 /** 4 * Add an extra update message to the update plugin notification. 5 * 6 * @package BuddyPress Core 7 */ 8 function bp_core_update_message() { 9 echo '<p style="color: red; margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">' . __( 'IMPORTANT: <a href="http://codex.buddypress.org/getting-started/upgrading-from-10x/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>'; 10 } 11 add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' ); 12 13 /** 14 * When BuddyPress is activated we must make sure that mod_rewrite is enabled. 15 * We must also make sure a BuddyPress compatible theme is enabled. This function 16 * will show helpful messages to the administrator. 17 * 18 * @package BuddyPress Core 19 */ 20 function bp_core_activation_notice() { 21 global $wp_rewrite, $current_blog, $bp; 22 23 if ( isset( $_POST['permalink_structure'] ) ) 24 return false; 25 26 if ( !is_super_admin() ) 27 return false; 28 29 if ( !empty( $current_blog ) ) { 30 if ( $current_blog->blog_id != BP_ROOT_BLOG ) 31 return false; 32 } 33 34 if ( empty( $wp_rewrite->permalink_structure ) ) { ?> 35 36 <div id="message" class="updated fade"> 37 <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> 38 </div><?php 39 40 } else { 41 // Get current theme info 42 $ct = current_theme_info(); 43 44 // The best way to remove this notice is to add a "buddypress" tag to 45 // your active theme's CSS header. 46 if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?> 47 48 <div id="message" class="updated fade"> 49 <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> 50 </div> 51 52 <?php 53 } 54 } 55 } 56 add_action( 'admin_notices', 'bp_core_activation_notice' ); 2 57 3 58 /** -
trunk/bp-core/bp-core-catchuri.php
r3743 r3767 6 6 7 7 /** 8 * bp_core_set_uri_globals()9 *10 8 * Analyzes the URI structure and breaks it down into parts for use in code. 11 9 * The idea is that BuddyPress can use complete custom friendly URI's without the … … 13 11 * 14 12 * Future custom components would then be able to use their own custom URI structure. 13 * 14 * @package BuddyPress Core 15 * @since BuddyPress (r100) 15 16 * 16 17 * The URI's are broken down as follows: … … 24 25 * - $bp->action_variables: array ['group', 5] 25 26 * 26 * @package BuddyPress Core27 27 */ 28 28 function bp_core_set_uri_globals() { 29 global $current_component, $current_action, $action_variables; 30 global $displayed_user_id, $bp_pages; 31 global $is_member_page; 29 global $bp, $bp_pages; 32 30 global $bp_unfiltered_uri, $bp_unfiltered_uri_offset; 33 global $bp, $current_blog; 34 35 /* Fetch all the WP page names for each component */ 31 global $current_blog; 32 33 $current_component = ''; 34 35 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() ) { 36 // Only catch URI's on the root blog if we are not running 37 // on multiple blogs 38 if ( BP_ROOT_BLOG != (int) $current_blog->blog_id ) 39 return false; 40 } 41 42 // Fetch all the WP page names for each component 36 43 if ( empty( $bp_pages ) ) 37 44 $bp_pages = bp_core_get_page_names(); 38 39 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() ) {40 /* Only catch URI's on the root blog if we are not running BP on multiple blogs */41 if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )42 return false;43 }44 45 45 46 // Ajax or not? … … 53 54 // Take GET variables off the URL to avoid problems, 54 55 // they are still registered in the global $_GET variable 55 $noget = substr( $path, 0, strpos( $path, '?' ) ); 56 if ( $noget != '' ) 56 if ( $noget = substr( $path, 0, strpos( $path, '?' ) ) ) 57 57 $path = $noget; 58 58 … … 84 84 85 85 // Set the indexes, these are incresed by one if we are not on a VHOST install 86 $component_index = 0;87 $action_index = $component_index + 1;86 $component_index = 0; 87 $action_index = $component_index + 1; 88 88 89 89 // Get site path items … … 105 105 106 106 // Reset the keys by merging with an empty array 107 $bp_uri = array_merge( array(), $bp_uri );107 $bp_uri = array_merge( array(), $bp_uri ); 108 108 109 109 // If a component is set to the front page, force its name into $bp_uri so that $current_component is populated … … 147 147 148 148 // This is not a BuddyPress page, so just return. 149 if ( !isset( $matches ) ) 149 if ( !isset( $matches ) ) { 150 $bp->current_component = $current_component; 151 $bp->current_action = ''; 152 $bp->action_variables = ''; 153 $bp->current_item = ''; 150 154 return false; 155 } 151 156 152 157 // Find the offset … … 166 171 if ( !empty( $bp_uri[$uri_offset + 1] ) ) { 167 172 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 168 $ displayed_user_id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) );173 $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) ); 169 174 else 170 $ displayed_user_id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) );175 $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) ); 171 176 172 177 $uri_offset = $uri_offset + 2; … … 193 198 } 194 199 } 195 } else 200 } else { 196 201 $i = 1; 202 } 203 204 // Set the current component in the global 205 $bp->current_component = $current_component; 197 206 198 207 // Set the current action 199 $ current_action= isset( $bp_uri[$i] ) ? $bp_uri[$i] : '';208 $bp->current_action = isset( $bp_uri[$i] ) ? $bp_uri[$i] : ''; 200 209 201 210 // Unset the current_component and action from action_variables … … 204 213 205 214 // Set the entire URI as the action variables, we will unset the current_component and action in a second 206 $ action_variables = $bp_uri;215 $bp->action_variables = $bp_uri; 207 216 208 217 // Remove the username from action variables if this is not a VHOST install 209 218 if ( defined( 'VHOST' ) && 'no' == VHOST && empty( $is_root_component ) ) 210 array_shift( $bp_uri);219 array_shift( $bp_uri ); 211 220 212 221 // Reset the keys by merging with an empty array 213 $action_variables = array_merge( array(), $action_variables ); 222 $bp->action_variables = array_merge( array(), $bp->action_variables ); 223 224 // Set the current item to empty 225 $bp->current_item = ''; 214 226 } 215 227 … … 244 256 // Make the queried/post object an actual valid page 245 257 if ( !empty( $object_id ) ) { 246 $wp_query->queried_object = &get_post( $object_id );258 $wp_query->queried_object = &get_post( $object_id ); 247 259 $wp_query->queried_object_id = $object_id; 248 249 $post = $wp_query->queried_object; 260 $post = $wp_query->queried_object; 250 261 } 251 262 -
trunk/bp-core/bp-core-loader.php
r3757 r3767 2 2 3 3 // Load the files containing functions that we globally will need. 4 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-component.php' );5 4 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-hooks.php' ); 6 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-c atchuri.php');5 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' ); 7 6 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' ); 8 7 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' ); 9 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );10 8 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' ); 9 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' ); 11 10 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-template.php' ); 12 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' ); 11 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-buddybar.php' ); 12 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' ); 13 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-component.php' ); 14 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' ); 13 15 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-deprecated.php' ); 14 16 … … 25 27 * @package BuddyPress Core Core 26 28 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 27 * @global $current_user A WordPress global containing current user information28 * @global $current_component Which is set up in /bp-core/bp-core-catch-uri.php29 * @global $current_action Which is set up in /bp-core/bp-core-catch-uri.php30 * @global $action_variables Which is set up in /bp-core/bp-core-catch-uri.php31 29 * @uses bp_core_get_user_domain() Returns the domain for a user 32 30 */ 33 31 function bp_core_setup_globals() { 34 32 global $bp; 35 global $current_user, $current_component, $current_action, $current_blog; 36 global $displayed_user_id, $bp_pages; 37 global $action_variables; 38 39 $current_user = wp_get_current_user(); 33 //global $current_action, $current_blog; 34 global $bp_pages; 35 //global $action_variables; 40 36 41 37 // Get the base database prefix … … 48 44 $bp->pages = $bp_pages; 49 45 50 /** Members Component *****************************************************/51 52 // Set up the members id and active components entry53 $bp->members->id = 'members';54 55 // Members Slugs56 $bp->members->slug = $bp->pages->members->slug;57 $bp->active_components[$bp->members->slug] = $bp->members->id;58 59 // The user ID of the user who is currently logged in.60 $bp->loggedin_user->id = $current_user->ID;61 62 /** Logged in user ********************************************************/63 64 // The domain for the user currently logged in. eg: http://domain.com/members/andy65 $bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id );66 67 // The core userdata of the user who is currently logged in.68 $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id );69 70 // is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop.71 $bp->loggedin_user->is_super_admin = is_super_admin();72 $bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.673 74 /** Displayed user ********************************************************/75 76 // The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php77 $bp->displayed_user->id = $displayed_user_id;78 79 // The domain for the user currently being displayed80 $bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id );81 82 // The core userdata of the user who is currently being displayed83 $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );84 85 46 /** Component and Action **************************************************/ 86 87 // The component being used eg: http://domain.com/members/andy/ [profile]88 $bp->current_component = $current_component; // type: string89 90 // The current action for the component eg: http://domain.com/members/andy/profile/ [edit]91 $bp->current_action = $current_action; // type: string92 93 // The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6]94 $bp->action_variables = $action_variables; // type: array95 96 // 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.97 $bp->current_item = ''; // type: string98 47 99 48 // Used for overriding the 2nd level navigation menu so it can be used to … … 101 50 $bp->is_single_item = false; 102 51 103 // The default component to use if none are set and someone visits: http://domain.com/members/andy 52 // The default component to use if none are set and someone 53 // visits: http://domain.com/members/andy 104 54 if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) { 105 55 if ( isset( $bp->pages->activity ) ) … … 108 58 $bp->default_component = $bp->profile->id; 109 59 } else { 110 $bp->default_component = BP_DEFAULT_COMPONENT;60 $bp->default_component = BP_DEFAULT_COMPONENT; 111 61 } 112 62 … … 116 66 // Sets up the array container for the component navigation rendered 117 67 // by bp_get_nav() 118 $bp->bp_nav = array();68 $bp->bp_nav = array(); 119 69 120 70 // Sets up the array container for the component options navigation 121 71 // rendered by bp_get_options_nav() 122 $bp->bp_options_nav = array();72 $bp->bp_options_nav = array(); 123 73 124 74 // Contains an array of all the active components. The key is the slug, … … 133 83 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user ); 134 84 135 // Fetch the full name for the logged in and current user136 $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );137 $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );138 139 /**140 * Used to determine if user has admin rights on current content. If the logged in user is viewing141 * their own profile and wants to delete something, is_item_admin is used. This is a142 * generic variable so it can be used by other components. It can also be modified, so when viewing a group143 * 'is_item_admin' would be 1 if they are a group admin, 0 if they are not.144 */145 $bp->is_item_admin = bp_user_has_access();146 147 // Used to determine if the logged in user is a moderator for the current content.148 $bp->is_item_mod = false;149 150 85 // Notifications Table 151 86 $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; 152 153 // Default Component154 if ( !$bp->current_component && $bp->displayed_user->id )155 $bp->current_component = $bp->default_component;156 87 157 88 // The default text for the members directory search box … … 161 92 } 162 93 add_action( 'bp_setup_globals', 'bp_core_setup_globals', 1 ); 163 164 /**165 * Allow filtering of database prefix. Intended for use in multinetwork installations.166 *167 * @global object $wpdb WordPress database object168 * @return string Filtered database prefix169 */170 function bp_core_get_table_prefix() {171 global $wpdb;172 173 return apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );174 }175 176 /**177 * Define the slugs used for BuddyPress pages, based on the slugs of the WP pages used.178 * These can be overridden manually by defining these slugs in wp-config.php.179 *180 * The fallback values are only used during initial BP page creation, when no slugs have been181 * explicitly defined.182 *183 * @package BuddyPress Core Core184 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()185 */186 function bp_core_define_slugs() {187 global $bp;188 189 if ( !defined( 'BP_MEMBERS_SLUG' ) )190 define( 'BP_MEMBERS_SLUG', $bp->pages->members->slug );191 192 if ( !defined( 'BP_REGISTER_SLUG' ) )193 define( 'BP_REGISTER_SLUG', $bp->pages->register->slug );194 195 if ( !defined( 'BP_ACTIVATION_SLUG' ) )196 define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug );197 198 }199 add_action( 'bp_setup_globals', 'bp_core_define_slugs' );200 201 202 /**203 * Fetches BP pages from the meta table, depending on setup204 *205 * @package BuddyPress Core Core206 */207 function bp_core_get_page_meta() {208 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )209 $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );210 else211 $page_ids = get_option( 'bp-pages' );212 213 return $page_ids;214 }215 216 /**217 * Stores BP pages in the meta table, depending on setup218 *219 * @package BuddyPress Core Core220 */221 function bp_core_update_page_meta( $page_ids ) {222 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )223 update_blog_option( BP_ROOT_BLOG, 'bp-pages', $page_ids );224 else225 update_option( 'bp-pages', $page_ids );226 }227 228 function bp_core_get_page_names() {229 global $wpdb, $bp;230 231 // Set pages as standard class232 $pages = new stdClass;233 234 // When upgrading to BP 1.3+ from a version of BP that does not use WP235 // pages, $bp->pages must be populated with dummy info to avoid crashing the236 // site while the db is upgraded.237 if ( !$page_ids = bp_core_get_page_meta() ) {238 foreach ( $bp->active_components as $component ) {239 $pages->{$component->id}->name = $component->id;240 $pages->{$component->id}->slug = $component->id;241 $pages->{$component->id}->id = $component->id;242 }243 244 return $pages;245 }246 247 $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;248 $page_ids_sql = implode( ',', (array)$page_ids );249 $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) " ) );250 251 foreach ( (array)$page_ids as $key => $page_id ) {252 foreach ( (array)$page_names as $page_name ) {253 if ( $page_name->ID == $page_id ) {254 $pages->{$key}->name = $page_name->post_name;255 $pages->{$key}->id = $page_name->ID;256 $slug[] = $page_name->post_name;257 258 // Get the slug259 while ( $page_name->post_parent != 0 ) {260 $parent = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) );261 $slug[] = $parent[0]->post_name;262 $page_name->post_parent = $parent[0]->post_parent;263 }264 265 $pages->{$key}->slug = implode( '/', array_reverse( (array)$slug ) );266 }267 268 unset( $slug );269 }270 }271 272 return apply_filters( 'bp_core_get_page_names', $pages );273 }274 275 /**276 * Creates a default component slug from a WP page root_slug277 *278 * Since 1.3, BP components get their root_slug (the slug used immediately279 * following the root domain) from the slug of a corresponding WP page.280 *281 * E.g. if your BP installation at example.com has its members page at282 * example.com/community/people, $bp->members->root_slug will be 'community/people'.283 *284 * By default, this function creates a shorter version of the root_slug for285 * use elsewhere in the URL, by returning the content after the final '/'286 * in the root_slug ('people' in the example above).287 *288 * Filter on 'bp_core_component_slug_from_root_slug' to override this method289 * in general, or define a specific component slug constant (e.g. BP_MEMBERS_SLUG)290 * to override specific component slugs.291 *292 * @package BuddyPress Core293 * @since 1.3294 *295 * @param str $root_slug The root slug, which comes from $bp->pages->[component]->slug296 * @return str $slug The short slug for use in the middle of URLs297 */298 function bp_core_component_slug_from_root_slug( $root_slug ) {299 $slug_chunks = explode( '/', $root_slug );300 $slug = array_pop( $slug_chunks );301 302 return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );303 }304 305 /**306 * Initializes the wp-admin area "BuddyPress" menus and sub menus.307 *308 * @package BuddyPress Core309 * @uses is_super_admin() returns true if the current user is a site admin, false if not310 */311 function bp_core_admin_menu_init() {312 if ( !is_super_admin() )313 return false;314 315 require ( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin.php' );316 }317 add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_admin_menu_init' );318 319 /**320 * Adds the "BuddyPress" admin submenu item to the Site Admin tab.321 *322 * @package BuddyPress Core323 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()324 * @uses is_super_admin() returns true if the current user is a site admin, false if not325 * @uses add_submenu_page() WP function to add a submenu item326 */327 function bp_core_add_admin_menu() {328 if ( !is_super_admin() )329 return false;330 331 // Don't add this version of the admin menu if a BP upgrade is in progress332 // See bp_core_update_add_admin_menu()333 if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE )334 return false;335 336 $hooks = array();337 338 // Add the administration tab under the "Site Admin" tab for site administrators339 $hooks[] = bp_core_add_admin_menu_page( array(340 'menu_title' => __( 'BuddyPress', 'buddypress' ),341 'page_title' => __( 'BuddyPress', 'buddypress' ),342 'capability' => 'manage_options',343 'file' => 'bp-general-settings',344 'function' => 'bp_core_admin_dashboard',345 'position' => 2346 ) );347 348 $hooks[] = add_submenu_page( 'bp-general-settings', __( 'BuddyPress Dashboard', 'buddypress' ), __( 'Dashboard', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_dashboard' );349 $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Settings', 'buddypress' ), __( 'Settings', 'buddypress' ), 'manage_options', 'bp-settings', 'bp_core_admin_settings' );350 $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress' ), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );351 352 // Add a hook for css/js353 foreach( $hooks as $hook ) {354 add_action( "admin_print_styles-$hook", 'bp_core_add_admin_menu_styles' );355 }356 }357 add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_add_admin_menu', 9 );358 94 359 95 /** … … 389 125 ) ); 390 126 391 $profile_link = $bp->loggedin_user->domain . '/profile/';127 $profile_link = trailingslashit( $bp->loggedin_user->domain . '/' . $bp->core->profile->slug ); 392 128 393 129 // Add the subnav items to the profile … … 405 141 $bp->bp_options_title = __( 'My Profile', 'buddypress' ); 406 142 } else { 407 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 143 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 144 'item_id' => $bp->displayed_user->id, 145 'type' => 'thumb' 146 ) ); 408 147 $bp->bp_options_title = $bp->displayed_user->fullname; 409 148 } … … 413 152 add_action( 'bp_setup_nav', 'bp_core_setup_nav' ); 414 153 415 /********************************************************************************416 * Action Functions417 *418 * Action functions are exactly the same as screen functions, however they do not419 * have a template screen associated with them. Usually they will send the user420 * back to the default screen after execution.421 */422 423 /**424 * Listens to the $bp component and action variables to determine if the user is viewing the members425 * directory page. If they are, it will set up the directory and load the members directory template.426 *427 * @package BuddyPress Core428 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()429 * @uses wp_enqueue_script() Loads a JS script into the header of the page.430 * @uses bp_core_load_template() Loads a specific template file.431 */432 function bp_core_action_directory_members() {433 global $bp;434 435 if ( is_null( $bp->displayed_user->id ) && $bp->current_component == $bp->members->slug ) {436 $bp->is_directory = true;437 438 do_action( 'bp_core_action_directory_members' );439 bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'members/index' ) );440 }441 }442 add_action( 'wp', 'bp_core_action_directory_members', 2 );443 444 /**445 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu446 * this action will fire and mark or unmark the user and their blogs as spam.447 * Must be a site admin for this function to run.448 *449 * @package BuddyPress Core450 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()451 */452 function bp_core_action_set_spammer_status() {453 global $bp, $wpdb, $wp_version;454 455 if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )456 return false;457 458 if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {459 // Check the nonce460 check_admin_referer( 'mark-unmark-spammer' );461 462 // Get the functions file463 if ( is_multisite() )464 require_once( ABSPATH . 'wp-admin/includes/ms.php' );465 466 if ( 'mark-spammer' == $bp->current_action )467 $is_spam = 1;468 else469 $is_spam = 0;470 471 // Get the blogs for the user472 $blogs = get_blogs_of_user( $bp->displayed_user->id, true );473 474 foreach ( (array) $blogs as $key => $details ) {475 // Do not mark the main or current root blog as spam476 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )477 continue;478 479 // Update the blog status480 update_blog_status( $details->userblog_id, 'spam', $is_spam );481 482 // Fire the standard multisite hook483 do_action( 'make_spam_blog', $details->userblog_id );484 }485 486 // Finally, mark this user as a spammer487 if ( is_multisite() )488 $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );489 490 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );491 492 if ( $is_spam )493 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );494 else495 bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );496 497 // Hide this user's activity498 if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )499 bp_activity_hide_user_activity( $bp->displayed_user->id );500 501 // We need a special hook for is_spam so that components can502 // delete data at spam time503 if ( $is_spam )504 do_action( 'bp_make_spam_user', $bp->displayed_user->id );505 506 do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );507 508 bp_core_redirect( wp_get_referer() );509 }510 }511 add_action( 'wp', 'bp_core_action_set_spammer_status', 3 );512 513 /**514 * Allows a site admin to delete a user from the adminbar menu.515 *516 * @package BuddyPress Core517 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()518 */519 function bp_core_action_delete_user() {520 global $bp;521 522 if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )523 return false;524 525 if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {526 // Check the nonce527 check_admin_referer( 'delete-user' );528 529 $errors = false;530 531 if ( bp_core_delete_account( $bp->displayed_user->id ) ) {532 bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) );533 } else {534 bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' );535 $errors = true;536 }537 538 do_action( 'bp_core_action_delete_user', $errors );539 540 if ( $errors )541 bp_core_redirect( $bp->displayed_user->domain );542 else543 bp_core_redirect( $bp->loggedin_user->domain );544 }545 }546 add_action( 'wp', 'bp_core_action_delete_user', 3 );547 548 549 /********************************************************************************550 * Business Functions551 *552 * Business functions are where all the magic happens in BuddyPress. They will553 * handle the actual saving or manipulation of information. Usually they will554 * hand off to a database class for data access, then return555 * true or false on success or failure.556 */557 558 /**559 * Return an array of users IDs based on the parameters passed.560 *561 * @package BuddyPress Core562 */563 function bp_core_get_users( $args = '' ) {564 global $bp;565 566 $defaults = array(567 'type' => 'active', // active, newest, alphabetical, random or popular568 'user_id' => false, // Pass a user_id to limit to only friend connections for this user569 'exclude' => false, // Users to exclude from results570 'search_terms' => false, // Limit to users that match these search terms571 572 'include' => false, // Pass comma separated list of user_ids to limit to only these users573 'per_page' => 20, // The number of results to return per page574 'page' => 1, // The page to return if limiting per page575 'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update576 );577 578 $params = wp_parse_args( $args, $defaults );579 extract( $params, EXTR_SKIP );580 581 return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras, $exclude ), $params );582 }583 584 /**585 * Returns the domain for the passed user: e.g. http://domain.com/members/andy/586 *587 * @package BuddyPress Core588 * @global $current_user WordPress global variable containing current logged in user information589 * @param user_id The ID of the user.590 * @uses get_user_meta() WordPress function to get the usermeta for a user.591 */592 function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {593 global $bp;594 595 if ( !$user_id ) return;596 597 if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {598 $username = bp_core_get_username( $user_id, $user_nicename, $user_login );599 600 // If we are using a members slug, include it.601 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )602 $domain = $bp->root_domain . '/' . $bp->members->slug . '/' . $username . '/';603 else604 $domain = $bp->root_domain . '/' . $username . '/';605 606 // Cache the link607 if ( !empty( $domain ) )608 wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );609 }610 611 return apply_filters( 'bp_core_get_user_domain', $domain );612 }613 614 /**615 * Fetch everything in the wp_users table for a user, without any usermeta.616 *617 * @package BuddyPress Core618 * @param user_id The ID of the user.619 * @uses BP_Core_User::get_core_userdata() Performs the query.620 */621 function bp_core_get_core_userdata( $user_id ) {622 if ( empty( $user_id ) )623 return false;624 625 if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {626 $userdata = BP_Core_User::get_core_userdata( $user_id );627 wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );628 }629 return apply_filters( 'bp_core_get_core_userdata', $userdata );630 }631 632 /**633 * Returns the domain for the root blog.634 * eg: http://domain.com/ OR https://domain.com635 *636 * @package BuddyPress Core637 * @uses get_blog_option() WordPress function to fetch blog meta.638 * @return $domain The domain URL for the blog.639 */640 function bp_core_get_root_domain() {641 global $current_blog;642 643 if ( defined( 'BP_ENABLE_MULTIBLOG' ) )644 $domain = get_home_url( $current_blog->blog_id );645 else646 $domain = get_home_url( BP_ROOT_BLOG );647 648 return apply_filters( 'bp_core_get_root_domain', $domain );649 }650 651 /**652 * Returns the user id for the user that is currently being displayed.653 * eg: http://andy.domain.com/ or http://domain.com/andy/654 *655 * @package BuddyPress Core656 * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed657 * @return The user id for the user that is currently being displayed, return zero if this is not a user home and just a normal blog.658 */659 function bp_core_get_displayed_userid( $user_login ) {660 return apply_filters( 'bp_core_get_displayed_userid', bp_core_get_userid( $user_login ) );661 }662 663 /**664 * Adds a navigation item to the main navigation array used in BuddyPress themes.665 *666 * @package BuddyPress Core667 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()668 */669 function bp_core_new_nav_item( $args = '' ) {670 global $bp;671 672 $defaults = array(673 'name' => false, // Display name for the nav item674 'slug' => false, // URL slug for the nav item675 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item676 'show_for_displayed_user' => true, // When viewing another user does this nav item show up?677 'site_admin_only' => false, // Can only site admins see this nav item?678 'position' => 99, // Index of where this nav item should be positioned679 'screen_function' => false, // The name of the function to run when clicked680 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked681 );682 683 $r = wp_parse_args( $args, $defaults );684 extract( $r, EXTR_SKIP );685 686 // If we don't have the required info we need, don't create this subnav item687 if ( empty($name) || empty($slug) )688 return false;689 690 // If this is for site admins only and the user is not one, don't create the subnav item691 if ( $site_admin_only && !is_super_admin() )692 return false;693 694 if ( empty( $item_css_id ) )695 $item_css_id = $slug;696 697 $bp->bp_nav[$slug] = array(698 'name' => $name,699 'slug' => $slug,700 'link' => $bp->loggedin_user->domain . $slug . '/',701 'css_id' => $item_css_id,702 'show_for_displayed_user' => $show_for_displayed_user,703 'position' => $position,704 'screen_function' => &$screen_function705 );706 707 /***708 * If this nav item is hidden for the displayed user, and709 * the logged in user is not the displayed user710 * looking at their own profile, don't create the nav item.711 */712 if ( !$show_for_displayed_user && !bp_user_has_access() )713 return false;714 715 /***716 * If we are not viewing a user, and this is a root component, don't attach the717 * default subnav function so we can display a directory or something else.718 */719 if ( bp_is_root_component( $slug ) && !$bp->displayed_user->id )720 return;721 722 if ( $bp->current_component == $slug && !$bp->current_action ) {723 if ( !is_object( $screen_function[0] ) )724 add_action( 'wp', $screen_function, 3 );725 else726 add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );727 728 if ( $default_subnav_slug )729 $bp->current_action = $default_subnav_slug;730 }731 }732 733 /**734 * Modify the default subnav item to load when a top level nav item is clicked.735 *736 * @package BuddyPress Core737 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()738 */739 function bp_core_new_nav_default( $args = '' ) {740 global $bp;741 742 $defaults = array(743 'parent_slug' => false, // Slug of the parent744 'screen_function' => false, // The name of the function to run when clicked745 'subnav_slug' => false // The slug of the subnav item to select when clicked746 );747 748 $r = wp_parse_args( $args, $defaults );749 extract( $r, EXTR_SKIP );750 751 if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {752 if ( !is_object( $function[0] ) )753 remove_action( 'wp', $function, 3 );754 else755 remove_action( 'wp', array( &$function[0], $function[1] ), 3 );756 }757 758 $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function;759 760 if ( $bp->current_component == $parent_slug && !$bp->current_action ) {761 if ( !is_object( $screen_function[0] ) )762 add_action( 'wp', $screen_function, 3 );763 else764 add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );765 766 if ( $subnav_slug )767 $bp->current_action = $subnav_slug;768 }769 }770 771 /**772 * We can only sort nav items by their position integer at a later point in time, once all773 * plugins have registered their navigation items.774 *775 * @package BuddyPress Core776 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()777 */778 function bp_core_sort_nav_items() {779 global $bp;780 781 if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )782 return false;783 784 foreach ( (array)$bp->bp_nav as $slug => $nav_item ) {785 if ( empty( $temp[$nav_item['position']]) )786 $temp[$nav_item['position']] = $nav_item;787 else {788 // increase numbers here to fit new items in.789 do {790 $nav_item['position']++;791 } while ( !empty( $temp[$nav_item['position']] ) );792 793 $temp[$nav_item['position']] = $nav_item;794 }795 }796 797 ksort( $temp );798 $bp->bp_nav = &$temp;799 }800 add_action( 'wp_head', 'bp_core_sort_nav_items' );801 add_action( 'admin_head', 'bp_core_sort_nav_items' );802 803 /**804 * Adds a navigation item to the sub navigation array used in BuddyPress themes.805 *806 * @package BuddyPress Core807 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()808 */809 function bp_core_new_subnav_item( $args = '' ) {810 global $bp;811 812 $defaults = array(813 'name' => false, // Display name for the nav item814 'slug' => false, // URL slug for the nav item815 'parent_slug' => false, // URL slug of the parent nav item816 'parent_url' => false, // URL of the parent item817 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item818 'user_has_access' => true, // Can the logged in user see this nav item?819 'site_admin_only' => false, // Can only site admins see this nav item?820 'position' => 90, // Index of where this nav item should be positioned821 'screen_function' => false // The name of the function to run when clicked822 );823 824 $r = wp_parse_args( $args, $defaults );825 extract( $r, EXTR_SKIP );826 827 // If we don't have the required info we need, don't create this subnav item828 if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )829 return false;830 831 // If this is for site admins only and the user is not one, don't create the subnav item832 if ( $site_admin_only && !is_super_admin() )833 return false;834 835 if ( empty( $item_css_id ) )836 $item_css_id = $slug;837 838 $bp->bp_options_nav[$parent_slug][$slug] = array(839 'name' => $name,840 'link' => $parent_url . $slug . '/',841 'slug' => $slug,842 'css_id' => $item_css_id,843 'position' => $position,844 'user_has_access' => $user_has_access,845 'screen_function' => &$screen_function846 );847 848 if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {849 if ( !is_object( $screen_function[0] ) )850 add_action( 'wp', $screen_function, 3 );851 else852 add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );853 }854 }855 856 function bp_core_sort_subnav_items() {857 global $bp;858 859 if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )860 return false;861 862 foreach ( (array)$bp->bp_options_nav as $parent_slug => $subnav_items ) {863 if ( !is_array( $subnav_items ) )864 continue;865 866 foreach ( (array)$subnav_items as $subnav_item ) {867 if ( empty( $temp[$subnav_item['position']]) )868 $temp[$subnav_item['position']] = $subnav_item;869 else {870 // increase numbers here to fit new items in.871 do {872 $subnav_item['position']++;873 } while ( !empty( $temp[$subnav_item['position']] ) );874 875 $temp[$subnav_item['position']] = $subnav_item;876 }877 }878 ksort( $temp );879 $bp->bp_options_nav[$parent_slug] = &$temp;880 unset( $temp );881 }882 }883 add_action( 'wp_head', 'bp_core_sort_subnav_items' );884 add_action( 'admin_head', 'bp_core_sort_subnav_items' );885 886 /**887 * Removes a navigation item from the sub navigation array used in BuddyPress themes.888 *889 * @package BuddyPress Core890 * @param $parent_id The id of the parent navigation item.891 * @param $slug The slug of the sub navigation item.892 */893 function bp_core_remove_nav_item( $parent_id ) {894 global $bp;895 896 // Unset subnav items for this nav item897 if ( is_array( $bp->bp_options_nav[$parent_id] ) ) {898 foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {899 bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );900 }901 }902 903 if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) {904 if ( !is_object( $function[0] ) )905 remove_action( 'wp', $function, 3 );906 else907 remove_action( 'wp', array( &$function[0], $function[1] ), 3 );908 }909 910 unset( $bp->bp_nav[$parent_id] );911 }912 913 /**914 * Removes a navigation item from the sub navigation array used in BuddyPress themes.915 *916 * @package BuddyPress Core917 * @param $parent_id The id of the parent navigation item.918 * @param $slug The slug of the sub navigation item.919 */920 function bp_core_remove_subnav_item( $parent_id, $slug ) {921 global $bp;922 923 $screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];924 925 if ( $screen_function ) {926 if ( !is_object( $screen_function[0] ) )927 remove_action( 'wp', $screen_function, 3 );928 else929 remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );930 }931 932 unset( $bp->bp_options_nav[$parent_id][$slug] );933 934 if ( !count( $bp->bp_options_nav[$parent_id] ) )935 unset($bp->bp_options_nav[$parent_id]);936 }937 938 /**939 * Clear the subnav items for a specific nav item.940 *941 * @package BuddyPress Core942 * @param $parent_id The id of the parent navigation item.943 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()944 */945 function bp_core_reset_subnav_items( $parent_slug ) {946 global $bp;947 948 unset( $bp->bp_options_nav[$parent_slug] );949 }950 951 /**952 * Returns the user_id for a user based on their username.953 *954 * @package BuddyPress Core955 * @param $username str Username to check.956 * @return false on no match957 * @return int the user ID of the matched user.958 */959 function bp_core_get_random_member() {960 global $bp;961 962 if ( isset( $_GET['random-member'] ) ) {963 $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );964 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );965 }966 }967 add_action( 'wp', 'bp_core_get_random_member' );968 969 /**970 * Returns the user_id for a user based on their username.971 *972 * @package BuddyPress Core973 * @param $username str Username to check.974 * @global $wpdb WordPress DB access object.975 * @return false on no match976 * @return int the user ID of the matched user.977 */978 function bp_core_get_userid( $username ) {979 global $wpdb;980 981 if ( empty( $username ) )982 return false;983 984 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );985 }986 987 /**988 * Returns the user_id for a user based on their user_nicename.989 *990 * @package BuddyPress Core991 * @param $username str Username to check.992 * @global $wpdb WordPress DB access object.993 * @return false on no match994 * @return int the user ID of the matched user.995 */996 function bp_core_get_userid_from_nicename( $user_nicename ) {997 global $wpdb;998 999 if ( empty( $user_nicename ) )1000 return false;1001 1002 return apply_filters( 'bp_core_get_userid_from_nicename', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $user_nicename ) ) );1003 }1004 1005 /**1006 * Returns the username for a user based on their user id.1007 *1008 * @package BuddyPress Core1009 * @param $uid int User ID to check.1010 * @global $userdata WordPress user data for the current logged in user.1011 * @uses get_userdata() WordPress function to fetch the userdata for a user ID1012 * @return false on no match1013 * @return str the username of the matched user.1014 */1015 function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {1016 global $bp;1017 1018 if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {1019 if ( empty( $user_nicename ) && empty( $user_login ) ) {1020 $ud = false;1021 1022 if ( isset( $bp->loggedin_user->id ) && $bp->loggedin_user->id == $user_id )1023 $ud = &$bp->loggedin_user->userdata;1024 1025 if ( isset( $bp->displayed_user->id ) && $bp->displayed_user->id == $user_id )1026 $ud = &$bp->displayed_user->userdata;1027 1028 if ( empty( $ud ) ) {1029 if ( !$ud = bp_core_get_core_userdata( $user_id ) )1030 return false;1031 }1032 1033 $user_nicename = $ud->user_nicename;1034 $user_login = $ud->user_login;1035 }1036 1037 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )1038 $username = $user_login;1039 else1040 $username = $user_nicename;1041 }1042 1043 // Add this to cache1044 if ( !empty( $username ) )1045 wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );1046 1047 return apply_filters( 'bp_core_get_username', $username );1048 }1049 1050 /**1051 * Returns the email address for the user based on user ID1052 *1053 * @package BuddyPress Core1054 * @param $uid int User ID to check.1055 * @uses get_userdata() WordPress function to fetch the userdata for a user ID1056 * @return false on no match1057 * @return str The email for the matched user.1058 */1059 function bp_core_get_user_email( $uid ) {1060 if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {1061 $ud = bp_core_get_core_userdata($uid);1062 $email = $ud->user_email;1063 wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );1064 }1065 1066 return apply_filters( 'bp_core_get_user_email', $email );1067 }1068 1069 /**1070 * Returns a HTML formatted link for a user with the user's full name as the link text.1071 * eg: <a href="http://andy.domain.com/">Andy Peatling</a>1072 * Optional parameters will return just the name, or just the URL, or disable "You" text when1073 * user matches the logged in user.1074 *1075 * [NOTES: This function needs to be cleaned up or split into separate functions]1076 *1077 * @package BuddyPress Core1078 * @param $uid int User ID to check.1079 * @param $no_anchor bool Disable URL and HTML and just return full name. Default false.1080 * @param $just_link bool Disable full name and HTML and just return the URL text. Default false.1081 * @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false.1082 * @global $userdata WordPress user data for the current logged in user.1083 * @uses get_userdata() WordPress function to fetch the userdata for a user ID1084 * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID.1085 * @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID1086 * @return false on no match1087 * @return str The link text based on passed parameters.1088 */1089 function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) {1090 $display_name = bp_core_get_user_displayname( $user_id );1091 1092 if ( empty( $display_name ) )1093 return false;1094 1095 if ( $no_anchor )1096 return $display_name;1097 1098 if ( !$url = bp_core_get_user_domain($user_id) )1099 return false;1100 1101 if ( $just_link )1102 return $url;1103 1104 return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id );1105 }1106 1107 1108 /**1109 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.1110 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.1111 *1112 * @package BuddyPress Core1113 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()1114 * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.1115 * @uses get_userdata() Fetches the WP userdata for a specific user.1116 * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.1117 * @uses wp_cache_set() Adds a value to the cache.1118 * @return str The display name for the user in question.1119 */1120 function bp_core_get_user_displayname( $user_id_or_username ) {1121 global $bp;1122 1123 if ( !$user_id_or_username )1124 return false;1125 1126 if ( !is_numeric( $user_id_or_username ) )1127 $user_id = bp_core_get_userid( $user_id_or_username );1128 else1129 $user_id = $user_id_or_username;1130 1131 if ( !$user_id )1132 return false;1133 1134 if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {1135 if ( bp_is_active( 'xprofile' ) ) {1136 $fullname = xprofile_get_field_data( stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ), $user_id );1137 1138 if ( empty($fullname) ) {1139 $ud = bp_core_get_core_userdata( $user_id );1140 1141 if ( !empty( $ud->display_name ) )1142 $fullname = $ud->display_name;1143 else1144 $fullname = $ud->user_nicename;1145 1146 xprofile_set_field_data( 1, $user_id, $fullname );1147 }1148 } else {1149 $ud = bp_core_get_core_userdata($user_id);1150 1151 if ( !empty( $ud->display_name ) )1152 $fullname = $ud->display_name;1153 else1154 $fullname = $ud->user_nicename;1155 }1156 1157 if ( !empty( $fullname ) )1158 wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );1159 }1160 1161 return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id );1162 }1163 add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );1164 add_filter( 'bp_core_get_user_displayname', 'trim' );1165 add_filter( 'bp_core_get_user_displayname', 'stripslashes' );1166 1167 1168 /**1169 * Returns the user link for the user based on user email address1170 *1171 * @package BuddyPress Core1172 * @param $email str The email address for the user.1173 * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.1174 * @uses get_user_by_email() WordPress function to get userdata via an email address1175 * @return str The link to the users home base. False on no match.1176 */1177 function bp_core_get_userlink_by_email( $email ) {1178 $user = get_user_by_email( $email );1179 return apply_filters( 'bp_core_get_userlink_by_email', bp_core_get_userlink( $user->ID, false, false, true ) );1180 }1181 1182 /**1183 * Returns the user link for the user based on user's username1184 *1185 * @package BuddyPress Core1186 * @param $username str The username for the user.1187 * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.1188 * @return str The link to the users home base. False on no match.1189 */1190 function bp_core_get_userlink_by_username( $username ) {1191 global $wpdb;1192 1193 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );1194 return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );1195 }1196 1197 /**1198 * Returns the total number of members for the installation.1199 *1200 * @package BuddyPress Core1201 * @return int The total number of members.1202 */1203 function bp_core_get_total_member_count() {1204 global $wpdb, $bp;1205 1206 if ( !$count = wp_cache_get( 'bp_total_member_count', 'bp' ) ) {1207 $status_sql = bp_core_get_status_sql();1208 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql}" ) );1209 wp_cache_set( 'bp_total_member_count', $count, 'bp' );1210 }1211 1212 return apply_filters( 'bp_core_get_total_member_count', $count );1213 }1214 1215 /**1216 * Checks if the user has been marked as a spammer.1217 *1218 * @package BuddyPress Core1219 * @param $user_id int The id for the user.1220 * @return int 1 if spammer, 0 if not.1221 */1222 function bp_core_is_user_spammer( $user_id ) {1223 global $wpdb;1224 1225 if ( is_multisite() )1226 $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );1227 else1228 $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );1229 1230 return apply_filters( 'bp_core_is_user_spammer', $is_spammer );1231 }1232 1233 /**1234 * Checks if the user has been marked as deleted.1235 *1236 * @package BuddyPress Core1237 * @param $user_id int The id for the user.1238 * @return int 1 if deleted, 0 if not.1239 */1240 function bp_core_is_user_deleted( $user_id ) {1241 global $wpdb;1242 1243 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 ) ) );1244 }1245 1246 /**1247 * Get the current GMT time to save into the DB1248 *1249 * @package BuddyPress Core1250 * @since 1.2.61251 */1252 function bp_core_current_time( $gmt = true ) {1253 // Get current time in MYSQL format1254 $current_time = current_time( 'mysql', $gmt );1255 1256 return apply_filters( 'bp_core_current_time', $current_time );1257 }1258 1259 /**1260 * Adds a feedback (error/success) message to the WP cookie so it can be1261 * displayed after the page reloads.1262 *1263 * @package BuddyPress Core1264 *1265 * @global obj $bp1266 * @param str $message Feedback to give to user1267 * @param str $type updated|success|error|warning1268 */1269 function bp_core_add_message( $message, $type = '' ) {1270 global $bp;1271 1272 // Success is the default1273 if ( empty( $type ) )1274 $type = 'success';1275 1276 // Send the values to the cookie for page reload display1277 @setcookie( 'bp-message', $message, time() + 60 * 60 * 24, COOKIEPATH );1278 @setcookie( 'bp-message-type', $type, time() + 60 * 60 * 24, COOKIEPATH );1279 1280 /***1281 * Send the values to the $bp global so we can still output messages1282 * without a page reload1283 */1284 $bp->template_message = $message;1285 $bp->template_message_type = $type;1286 }1287 1288 /**1289 * Checks if there is a feedback message in the WP cookie, if so, adds a1290 * "template_notices" action so that the message can be parsed into the template1291 * and displayed to the user.1292 *1293 * After the message is displayed, it removes the message vars from the cookie1294 * so that the message is not shown to the user multiple times.1295 *1296 * @package BuddyPress Core1297 * @global $bp_message The message text1298 * @global $bp_message_type The type of message (error/success)1299 * @uses setcookie() Sets a cookie value for the user.1300 */1301 function bp_core_setup_message() {1302 global $bp;1303 1304 if ( empty( $bp->template_message ) && isset( $_COOKIE['bp-message'] ) )1305 $bp->template_message = $_COOKIE['bp-message'];1306 1307 if ( empty( $bp->template_message_type ) && isset( $_COOKIE['bp-message-type'] ) )1308 $bp->template_message_type = $_COOKIE['bp-message-type'];1309 1310 add_action( 'template_notices', 'bp_core_render_message' );1311 1312 @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );1313 @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );1314 }1315 add_action( 'wp', 'bp_core_setup_message', 2 );1316 1317 /**1318 * Renders a feedback message (either error or success message) to the theme template.1319 * The hook action 'template_notices' is used to call this function, it is not called directly.1320 *1321 * @package BuddyPress Core1322 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()1323 */1324 function bp_core_render_message() {1325 global $bp;1326 1327 if ( isset( $bp->template_message ) && $bp->template_message ) :1328 $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error'; ?>1329 1330 <div id="message" class="<?php echo $type; ?>">1331 <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p>1332 </div>1333 1334 <?php1335 1336 do_action( 'bp_core_render_message' );1337 1338 endif;1339 }1340 1341 /**1342 * Based on function created by Dunstan Orchard - http://1976design.com1343 *1344 * This function will return an English representation of the time elapsed1345 * since a given date.1346 * eg: 2 hours and 50 minutes1347 * eg: 4 days1348 * eg: 4 weeks and 6 days1349 *1350 * @package BuddyPress Core1351 * @param $older_date int Unix timestamp of date you want to calculate the time since for1352 * @param $newer_date int Unix timestamp of date to compare older date to. Default false (current time).1353 * @return str The time since.1354 */1355 function bp_core_time_since( $older_date, $newer_date = false ) {1356 1357 // array of time period chunks1358 $chunks = array(1359 array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),1360 array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),1361 array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),1362 array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),1363 array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),1364 array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),1365 array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )1366 );1367 1368 if ( !is_numeric( $older_date ) ) {1369 $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );1370 $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );1371 $older_date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );1372 }1373 1374 /**1375 * $newer_date will equal false if we want to know the time elapsed between1376 * a date and the current time. $newer_date will have a value if we want to1377 * work out time elapsed between two known dates.1378 */1379 $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;1380 1381 // Difference in seconds1382 $since = $newer_date - $older_date;1383 1384 // Something went wrong with date calculation and we ended up with a negative date.1385 if ( 0 > $since )1386 return __( 'sometime', 'buddypress' );1387 1388 /**1389 * We only want to output two chunks of time here, eg:1390 * x years, xx months1391 * x days, xx hours1392 * so there's only two bits of calculation below:1393 */1394 1395 // Step one: the first chunk1396 for ( $i = 0, $j = count($chunks); $i < $j; $i++) {1397 $seconds = $chunks[$i][0];1398 1399 // Finding the biggest chunk (if the chunk fits, break)1400 if ( ( $count = floor($since / $seconds) ) != 0 )1401 break;1402 }1403 1404 // If $i iterates all the way to $j, then the event happened 0 seconds ago1405 if ( !isset( $chunks[$i] ) )1406 return '0 ' . __( 'seconds', 'buddypress' );1407 1408 // Set output var1409 $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];1410 1411 // Step two: the second chunk1412 if ( $i + 2 < $j ) {1413 $seconds2 = $chunks[$i + 1][0];1414 $name2 = $chunks[$i + 1][1];1415 1416 if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {1417 // Add to output var1418 $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];1419 }1420 }1421 1422 if ( !(int)trim( $output ) )1423 $output = '0 ' . __( 'seconds', 'buddypress' );1424 1425 return $output;1426 }1427 1428 /**1429 * Record user activity to the database. Many functions use a "last active" feature to1430 * show the length of time since the user was last active.1431 * This function will update that time as a usermeta setting for the user every 5 minutes.1432 *1433 * @package BuddyPress Core1434 * @global $userdata WordPress user data for the current logged in user.1435 * @uses update_user_meta() WordPress function to update user metadata in the usermeta table.1436 */1437 function bp_core_record_activity() {1438 global $bp;1439 1440 if ( !is_user_logged_in() )1441 return false;1442 1443 $activity = get_user_meta( $bp->loggedin_user->id, 'last_activity', true );1444 1445 if ( !is_numeric( $activity ) )1446 $activity = strtotime( $activity );1447 1448 // Get current time1449 $current_time = bp_core_current_time();1450 1451 if ( empty( $activity ) || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )1452 update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time );1453 }1454 add_action( 'wp_head', 'bp_core_record_activity' );1455 1456 /**1457 * Formats last activity based on time since date given.1458 *1459 * @package BuddyPress Core1460 * @param last_activity_date The date of last activity.1461 * @param $before The text to prepend to the activity time since figure.1462 * @param $after The text to append to the activity time since figure.1463 * @uses bp_core_time_since() This function will return an English representation of the time elapsed.1464 */1465 function bp_core_get_last_activity( $last_activity_date, $string ) {1466 if ( !$last_activity_date || empty( $last_activity_date ) )1467 $last_active = __( 'not recently active', 'buddypress' );1468 else1469 $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );1470 1471 return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );1472 }1473 1474 function bp_core_number_format( $number, $decimals = false ) {1475 // Check we actually have a number first.1476 if ( empty( $number ) )1477 return $number;1478 1479 return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );1480 }1481 1482 /**1483 * Fetch every post that is authored by the given user for the current blog.1484 *1485 * @package BuddyPress Core1486 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()1487 * @global $wpdb WordPress user data for the current logged in user.1488 * @return array of post ids.1489 */1490 function bp_core_get_all_posts_for_user( $user_id = 0 ) {1491 global $bp, $wpdb;1492 1493 if ( empty( $user_id ) )1494 $user_id = $bp->displayed_user->id;1495 1496 return apply_filters( 'bp_core_get_all_posts_for_user', $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 ) ) );1497 }1498 1499 /**1500 * Get the path of of the current site.1501 *1502 * @package BuddyPress Core1503 *1504 * @global $bp $bp1505 * @global object $current_site1506 * @return string1507 */1508 function bp_core_get_site_path() {1509 global $bp, $current_site;1510 1511 if ( is_multisite() )1512 $site_path = $current_site->path;1513 else {1514 $site_path = (array) explode( '/', site_url() );1515 1516 if ( count( $site_path ) < 2 )1517 $site_path = '/';1518 else {1519 // Unset the first three segments (http(s)://domain.com part)1520 unset( $site_path[0] );1521 unset( $site_path[1] );1522 unset( $site_path[2] );1523 1524 if ( !count( $site_path ) )1525 $site_path = '/';1526 else1527 $site_path = '/' . implode( '/', $site_path ) . '/';1528 }1529 }1530 1531 return apply_filters( 'bp_core_get_site_path', $site_path );1532 }1533 1534 /**1535 * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()1536 *1537 * @package BuddyPress Core1538 * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()1539 * @uses get_themes()1540 * @return An array containing all of the themes.1541 */1542 function bp_core_redirect( $location, $status = 302 ) {1543 global $bp_no_status_set;1544 1545 // Make sure we don't call status_header() in bp_core_do_catch_uri()1546 // as this conflicts with wp_redirect()1547 $bp_no_status_set = true;1548 1549 wp_redirect( $location, $status );1550 die;1551 }1552 1553 /**1554 * Returns the referrer URL without the http(s)://1555 *1556 * @package BuddyPress Core1557 * @return The referrer URL1558 */1559 function bp_core_referrer() {1560 $referer = explode( '/', wp_get_referer() );1561 unset( $referer[0], $referer[1], $referer[2] );1562 return implode( '/', $referer );1563 }1564 1565 /**1566 * Adds illegal names to WP so that root components will not conflict with1567 * blog names on a subdirectory installation.1568 *1569 * For example, it would stop someone creating a blog with the slug "groups".1570 */1571 function bp_core_add_illegal_names() {1572 update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );1573 }1574 1575 /**1576 * Allows a user to completely remove their account from the system1577 *1578 * @package BuddyPress Core1579 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()1580 * @uses is_super_admin() Checks to see if the user is a site administrator.1581 * @uses wpmu_delete_user() Deletes a user from the system on multisite installs.1582 * @uses wp_delete_user() Deletes a user from the system on singlesite installs.1583 * @uses get_site_option Checks if account deletion is allowed1584 */1585 function bp_core_delete_account( $user_id = false ) {1586 global $bp, $wp_version;1587 1588 if ( !$user_id )1589 $user_id = $bp->loggedin_user->id;1590 1591 // Make sure account deletion is not disabled1592 if ( !empty( $bp->site_options['bp-disable-account-deletion'] ) && !$bp->loggedin_user->is_super_admin )1593 return false;1594 1595 // Site admins cannot be deleted1596 if ( is_super_admin( bp_core_get_username( $user_id ) ) )1597 return false;1598 1599 // Specifically handle multi-site environment1600 if ( is_multisite() ) {1601 if ( $wp_version >= '3.0' )1602 require_once( ABSPATH . '/wp-admin/includes/ms.php' );1603 else1604 require_once( ABSPATH . '/wp-admin/includes/mu.php' );1605 1606 require_once( ABSPATH . '/wp-admin/includes/user.php' );1607 1608 return wpmu_delete_user( $user_id );1609 1610 // Single site user deletion1611 } else {1612 require_once( ABSPATH . '/wp-admin/includes/user.php' );1613 return wp_delete_user( $user_id );1614 }1615 }1616 1617 /**1618 * A javascript free implementation of the search functions in BuddyPress1619 *1620 * @package BuddyPress Core1621 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()1622 * @param string $slug The slug to redirect to for searching.1623 */1624 function bp_core_action_search_site( $slug = '' ) {1625 global $bp;1626 1627 if ( BP_SEARCH_SLUG != $bp->current_component )1628 return;1629 1630 if ( empty( $_POST['search-terms'] ) ) {1631 bp_core_redirect( $bp->root_domain );1632 return;1633 }1634 1635 $search_terms = stripslashes( $_POST['search-terms'] );1636 $search_which = !empty( $_POST['search-which'] ) ? $_POST['search-which'] : '';1637 $query_string = '/?s=';1638 1639 if ( empty( $slug ) ) {1640 switch ( $search_which ) {1641 case 'blogs':1642 $slug = bp_is_active( 'blogs' ) ? $bp->blogs->slug : '';1643 break;1644 1645 case 'forums':1646 $slug = bp_is_active( 'forums' ) ? $bp->forums->slug : '';1647 $query_string = '/?fs=';1648 break;1649 1650 case 'groups':1651 $slug = bp_is_active( 'groups' ) ? $bp->groups->slug : '';1652 break;1653 1654 case 'members':1655 default:1656 $slug = $bp->members->slug;1657 break;1658 }1659 1660 if ( empty( $slug ) ) {1661 bp_core_redirect( $bp->root_domain );1662 return;1663 }1664 }1665 1666 bp_core_redirect( apply_filters( 'bp_core_search_site', site_url( $slug . $query_string . urlencode( $search_terms ) ), $search_terms ) );1667 }1668 add_action( 'bp_init', 'bp_core_action_search_site', 7 );1669 1670 /**1671 * Localization safe ucfirst() support.1672 *1673 * @package BuddyPress Core1674 */1675 function bp_core_ucfirst( $str ) {1676 if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {1677 $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );1678 return $fc.mb_substr( $str, 1 );1679 } else {1680 return ucfirst( $str );1681 }1682 }1683 1684 /**1685 * Strips spaces from usernames that are created using add_user() and wp_insert_user()1686 *1687 * @package BuddyPress Core1688 */1689 function bp_core_strip_username_spaces( $username ) {1690 // Don't alter the user_login of existing users, as it causes user_nicename problems.1691 // See http://trac.buddypress.org/ticket/26421692 if ( username_exists( $username ) && ( !defined( 'BP_ENABLE_USER_COMPATIBILITY_MODE' ) || !BP_ENABLE_USER_COMPATIBILITY_MODE ) )1693 return $username;1694 1695 return str_replace( ' ', '-', $username );1696 }1697 add_action( 'pre_user_login', 'bp_core_strip_username_spaces' );1698 1699 /**1700 * REQUIRES WP-SUPER-CACHE1701 *1702 * When wp-super-cache is installed this function will clear cached pages1703 * so that success/error messages are not cached, or time sensitive content.1704 *1705 * @package BuddyPress Core1706 */1707 function bp_core_clear_cache() {1708 global $cache_path, $cache_filename;1709 1710 if ( function_exists( 'prune_super_cache' ) ) {1711 do_action( 'bp_core_clear_cache' );1712 1713 return prune_super_cache( $cache_path, true );1714 }1715 }1716 1717 /**1718 * Prints the generation time in the footer of the site.1719 *1720 * @package BuddyPress Core1721 */1722 function bp_core_print_generation_time() {1723 ?>1724 1725 <!-- Generated in <?php timer_stop(1); ?> seconds. (<?php echo get_num_queries(); ?> q) -->1726 1727 <?php1728 }1729 add_action( 'wp_footer', 'bp_core_print_generation_time' );1730 1731 /**1732 * A better version of add_admin_menu_page() that allows positioning of menus.1733 *1734 * @package BuddyPress Core1735 */1736 function bp_core_add_admin_menu_page( $args = '' ) {1737 global $menu, $admin_page_hooks, $_registered_pages;1738 1739 $defaults = array(1740 'page_title' => '',1741 'menu_title' => '',1742 'capability' => 'manage_options',1743 'file' => false,1744 'function' => false,1745 'icon_url' => false,1746 'position' => 1001747 );1748 1749 $r = wp_parse_args( $args, $defaults );1750 extract( $r, EXTR_SKIP );1751 1752 $file = plugin_basename( $file );1753 1754 $admin_page_hooks[$file] = sanitize_title( $menu_title );1755 1756 $hookname = get_plugin_page_hookname( $file, '' );1757 if (!empty ( $function ) && !empty ( $hookname ))1758 add_action( $hookname, $function );1759 1760 if ( empty($icon_url) )1761 $icon_url = 'images/generic.png';1762 elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )1763 $icon_url = 'https://' . substr($icon_url, 7);1764 1765 do {1766 $position++;1767 } while ( !empty( $menu[$position] ) );1768 1769 $menu[$position] = array ( $menu_title, $capability, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );1770 1771 $_registered_pages[$hookname] = true;1772 1773 return $hookname;1774 }1775 1776 /**1777 * When a user logs in, check if they have been marked as a spammer. If yes then simply1778 * redirect them to the home page and stop them from logging in.1779 *1780 * @package BuddyPress Core1781 * @param $auth_obj The WP authorization object1782 * @param $username The username of the user logging in.1783 * @uses get_userdatabylogin() Get the userdata object for a user based on their username1784 * @uses bp_core_redirect() Safe redirect to a page1785 * @return $auth_obj If the user is not a spammer, return the authorization object1786 */1787 function bp_core_boot_spammer( $auth_obj, $username ) {1788 global $bp;1789 1790 if ( !$user = get_userdatabylogin( $username ) )1791 return false;1792 1793 if ( ( is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )1794 return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.', 'buddypress' ) );1795 else1796 return $auth_obj;1797 }1798 add_filter( 'authenticate', 'bp_core_boot_spammer', 30, 2 );1799 1800 /**1801 * Deletes usermeta for the user when the user is deleted.1802 *1803 * @package BuddyPress Core1804 * @param $user_id The user id for the user to delete usermeta for1805 * @uses delete_user_meta() deletes a row from the wp_usermeta table based on meta_key1806 */1807 function bp_core_remove_data( $user_id ) {1808 // Remove usermeta1809 delete_user_meta( $user_id, 'last_activity' );1810 1811 // Flush the cache to remove the user from all cached objects1812 wp_cache_flush();1813 }1814 add_action( 'wpmu_delete_user', 'bp_core_remove_data' );1815 add_action( 'delete_user', 'bp_core_remove_data' );1816 add_action( 'bp_make_spam_user', 'bp_core_remove_data' );1817 1818 /**1819 * Load the buddypress translation file for current language1820 *1821 * @package BuddyPress Core1822 */1823 function bp_core_load_buddypress_textdomain() {1824 $locale = apply_filters( 'buddypress_locale', get_locale() );1825 $mofile = sprintf( 'buddypress-%s.mo', $locale );1826 $mofile_global = WP_LANG_DIR . '/' . $mofile;1827 $mofile_local = BP_PLUGIN_DIR . '/bp-languages/' . $mofile;1828 1829 if ( file_exists( $mofile_global ) )1830 return load_textdomain( 'buddypress', $mofile_global );1831 elseif ( file_exists( $mofile_local ) )1832 return load_textdomain( 'buddypress', $mofile_local );1833 else1834 return false;1835 }1836 add_action ( 'bp_init', 'bp_core_load_buddypress_textdomain', 2 );1837 1838 function bp_core_add_ajax_hook() {1839 // Theme only, we already have the wp_ajax_ hook firing in wp-admin1840 if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) )1841 do_action( 'wp_ajax_' . $_REQUEST['action'] );1842 }1843 add_action( 'bp_init', 'bp_core_add_ajax_hook' );1844 1845 /**1846 * Add an extra update message to the update plugin notification.1847 *1848 * @package BuddyPress Core1849 */1850 function bp_core_update_message() {1851 echo '<p style="color: red; margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">' . __( 'IMPORTANT: <a href="http://codex.buddypress.org/getting-started/upgrading-from-10x/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>';1852 }1853 add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );1854 1855 /**1856 * When BuddyPress is activated we must make sure that mod_rewrite is enabled.1857 * We must also make sure a BuddyPress compatible theme is enabled. This function1858 * will show helpful messages to the administrator.1859 *1860 * @package BuddyPress Core1861 */1862 function bp_core_activation_notice() {1863 global $wp_rewrite, $current_blog, $bp;1864 1865 if ( isset( $_POST['permalink_structure'] ) )1866 return false;1867 1868 if ( !is_super_admin() )1869 return false;1870 1871 if ( !empty( $current_blog ) ) {1872 if ( $current_blog->blog_id != BP_ROOT_BLOG )1873 return false;1874 }1875 1876 if ( empty( $wp_rewrite->permalink_structure ) ) { ?>1877 1878 <div id="message" class="updated fade">1879 <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>1880 </div><?php1881 1882 } else {1883 // Get current theme info1884 $ct = current_theme_info();1885 1886 // The best way to remove this notice is to add a "buddypress" tag to1887 // your active theme's CSS header.1888 if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?>1889 1890 <div id="message" class="updated fade">1891 <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>1892 </div>1893 1894 <?php1895 }1896 }1897 }1898 add_action( 'admin_notices', 'bp_core_activation_notice' );1899 1900 /**1901 * When switching from single to multisite we need to copy blog options to1902 * site options.1903 *1904 * @package BuddyPress Core1905 */1906 function bp_core_activate_site_options( $keys = array() ) {1907 global $bp;1908 1909 if ( !empty( $keys ) && is_array( $keys ) ) {1910 $errors = false;1911 1912 foreach ( $keys as $key => $default ) {1913 if ( empty( $bp->site_options[ $key ] ) ) {1914 $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );1915 1916 if ( !update_site_option( $key, $bp->site_options[ $key ] ) )1917 $errors = true;1918 }1919 }1920 1921 if ( empty( $errors ) )1922 return true;1923 }1924 1925 return false;1926 }1927 1928 /**1929 * BuddyPress uses site options to store configuration settings. Many of these settings are needed1930 * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch1931 * them all in one go.1932 *1933 * @package BuddyPress Core1934 */1935 function bp_core_get_site_options() {1936 global $bp, $wpdb;1937 1938 // These options come from the options table in WP single, and sitemeta in MS1939 $site_options = apply_filters( 'bp_core_site_options', array(1940 'bp-deactivated-components',1941 'bp-blogs-first-install',1942 'bp-disable-blog-forum-comments',1943 'bp-xprofile-base-group-name',1944 'bp-xprofile-fullname-field-name',1945 'bp-disable-profile-sync',1946 'bp-disable-avatar-uploads',1947 'bp-disable-account-deletion',1948 'bp-disable-forum-directory',1949 'bp-disable-blogforum-comments',1950 'bb-config-location',1951 'hide-loggedout-adminbar',1952 1953 // Useful WordPress settings used often1954 'tags_blog_id',1955 'registration',1956 'fileupload_maxk'1957 ) );1958 1959 // These options always come from the options table of BP_ROOT_BLOG1960 $root_blog_options = apply_filters( 'bp_core_root_blog_options', array(1961 'avatar_default'1962 ) );1963 1964 $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";1965 1966 if ( is_multisite() )1967 $site_meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );1968 else1969 $site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );1970 1971 $root_blog_meta_keys = "'" . implode( "','", (array)$root_blog_options ) ."'";1972 $root_blog_meta_table = $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'options';1973 $root_blog_meta = $wpdb->get_results( $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$root_blog_meta_table} WHERE option_name IN ({$root_blog_meta_keys})" ) );1974 1975 $site_options = array();1976 foreach( array( $site_meta, $root_blog_meta ) as $meta ) {1977 if ( !empty( $meta ) ) {1978 foreach( (array)$meta as $meta_item )1979 $site_options[$meta_item->name] = $meta_item->value;1980 }1981 }1982 return apply_filters( 'bp_core_get_site_options', $site_options );1983 }1984 1985 /********************************************************************************1986 * Caching1987 *1988 * Caching functions handle the clearing of cached objects and pages on specific1989 * actions throughout BuddyPress.1990 */1991 1992 /**1993 * Add's 'bp' to global group of network wide cachable objects1994 *1995 * @package BuddyPress Core1996 */1997 function bp_core_add_global_group() {1998 wp_cache_init();1999 2000 if ( function_exists( 'wp_cache_add_global_groups' ) )2001 wp_cache_add_global_groups( array( 'bp' ) );2002 }2003 add_action( 'bp_loaded', 'bp_core_add_global_group' );2004 2005 /**2006 * Clears all cached objects for a user, or a user is part of.2007 *2008 * @package BuddyPress Core2009 */2010 function bp_core_clear_user_object_cache( $user_id ) {2011 wp_cache_delete( 'bp_user_' . $user_id, 'bp' );2012 }2013 2014 // List actions to clear super cached pages on, if super cache is installed2015 add_action( 'wp_login', 'bp_core_clear_cache' );2016 add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );2017 154 2018 155 ?> -
trunk/bp-core/bp-core-template.php
r3757 r3767 1721 1721 1722 1722 function bp_is_blog_page() { 1723 global $bp, $ is_member_page, $wp_query;1723 global $bp, $wp_query; 1724 1724 1725 1725 if ( $wp_query->is_home && ( !isset( $bp->is_directory ) || !$bp->is_directory ) ) -
trunk/bp-users/bp-users-actions.php
r3757 r3767 1 <?php 2 3 /******************************************************************************* 4 * Action Functions 5 * 6 * Action functions are exactly the same as screen functions, however they do not 7 * have a template screen associated with them. Usually they will send the user 8 * back to the default screen after execution. 9 */ 10 11 /** 12 * Listens to the $bp component and action variables to determine if the user is viewing the members 13 * directory page. If they are, it will set up the directory and load the members directory template. 14 * 15 * @package BuddyPress Core 16 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 17 * @uses wp_enqueue_script() Loads a JS script into the header of the page. 18 * @uses bp_core_load_template() Loads a specific template file. 19 */ 20 /** 21 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu 22 * this action will fire and mark or unmark the user and their blogs as spam. 23 * Must be a site admin for this function to run. 24 * 25 * @package BuddyPress Core 26 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 27 */ 28 function bp_users_action_set_spammer_status() { 29 global $bp, $wpdb, $wp_version; 30 31 if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id ) 32 return false; 33 34 if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) { 35 // Check the nonce 36 check_admin_referer( 'mark-unmark-spammer' ); 37 38 // Get the functions file 39 if ( is_multisite() ) 40 require_once( ABSPATH . 'wp-admin/includes/ms.php' ); 41 42 if ( 'mark-spammer' == $bp->current_action ) 43 $is_spam = 1; 44 else 45 $is_spam = 0; 46 47 // Get the blogs for the user 48 $blogs = get_blogs_of_user( $bp->displayed_user->id, true ); 49 50 foreach ( (array) $blogs as $key => $details ) { 51 // Do not mark the main or current root blog as spam 52 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 53 continue; 54 55 // Update the blog status 56 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 57 58 // Fire the standard multisite hook 59 do_action( 'make_spam_blog', $details->userblog_id ); 60 } 61 62 // Finally, mark this user as a spammer 63 if ( is_multisite() ) 64 $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) ); 65 66 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) ); 67 68 if ( $is_spam ) 69 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) ); 70 else 71 bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) ); 72 73 // Hide this user's activity 74 if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) ) 75 bp_activity_hide_user_activity( $bp->displayed_user->id ); 76 77 // We need a special hook for is_spam so that components can 78 // delete data at spam time 79 if ( $is_spam ) 80 do_action( 'bp_make_spam_user', $bp->displayed_user->id ); 81 82 do_action( 'bp_users_action_set_spammer_status', $bp->displayed_user->id, $is_spam ); 83 84 bp_core_redirect( wp_get_referer() ); 85 } 86 } 87 add_action( 'wp', 'bp_users_action_set_spammer_status', 3 ); 88 89 /** 90 * Allows a site admin to delete a user from the adminbar menu. 91 * 92 * @package BuddyPress Core 93 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 94 */ 95 function bp_users_action_delete_user() { 96 global $bp; 97 98 if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id ) 99 return false; 100 101 if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) { 102 // Check the nonce 103 check_admin_referer( 'delete-user' ); 104 105 $errors = false; 106 107 if ( bp_core_delete_account( $bp->displayed_user->id ) ) { 108 bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) ); 109 } else { 110 bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' ); 111 $errors = true; 112 } 113 114 do_action( 'bp_users_action_delete_user', $errors ); 115 116 if ( $errors ) 117 bp_core_redirect( $bp->displayed_user->domain ); 118 else 119 bp_core_redirect( $bp->loggedin_user->domain ); 120 } 121 } 122 add_action( 'wp', 'bp_users_action_delete_user', 3 ); 123 124 ?> -
trunk/bp-users/bp-users-filters.php
r3757 r3767 1 1 <?php 2 /*3 * To change this template, choose Tools | Templates4 * and open the template in the editor.5 */6 2 7 3 ?> -
trunk/bp-users/bp-users-functions.php
r3757 r3767 1 1 <?php 2 3 /******************************************************************************** 4 * Business Functions 5 * 6 * Business functions are where all the magic happens in BuddyPress. They will 7 * handle the actual saving or manipulation of information. Usually they will 8 * hand off to a database class for data access, then return 9 * true or false on success or failure. 10 */ 11 12 /** 13 * Define the slugs used for BuddyPress pages, based on the slugs of the WP pages used. 14 * These can be overridden manually by defining these slugs in wp-config.php. 15 * 16 * The fallback values are only used during initial BP page creation, when no slugs have been 17 * explicitly defined. 18 * 19 * @package BuddyPress Core Core 20 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 21 */ 22 function bp_core_define_slugs() { 23 global $bp; 24 25 if ( !defined( 'BP_MEMBERS_SLUG' ) ) 26 define( 'BP_MEMBERS_SLUG', $bp->pages->members->slug ); 27 28 if ( !defined( 'BP_REGISTER_SLUG' ) ) 29 define( 'BP_REGISTER_SLUG', $bp->pages->register->slug ); 30 31 if ( !defined( 'BP_ACTIVATION_SLUG' ) ) 32 define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug ); 33 34 } 35 add_action( 'bp_setup_globals', 'bp_core_define_slugs' ); 36 37 /** 38 * Return an array of users IDs based on the parameters passed. 39 * 40 * @package BuddyPress Core 41 */ 42 function bp_core_get_users( $args = '' ) { 43 global $bp; 44 45 $defaults = array( 46 'type' => 'active', // active, newest, alphabetical, random or popular 47 'user_id' => false, // Pass a user_id to limit to only friend connections for this user 48 'exclude' => false, // Users to exclude from results 49 'search_terms' => false, // Limit to users that match these search terms 50 51 'include' => false, // Pass comma separated list of user_ids to limit to only these users 52 'per_page' => 20, // The number of results to return per page 53 'page' => 1, // The page to return if limiting per page 54 'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update 55 ); 56 57 $params = wp_parse_args( $args, $defaults ); 58 extract( $params, EXTR_SKIP ); 59 60 return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras, $exclude ), $params ); 61 } 62 63 /** 64 * Returns the domain for the passed user: e.g. http://domain.com/members/andy/ 65 * 66 * @package BuddyPress Core 67 * @global $current_user WordPress global variable containing current logged in user information 68 * @param user_id The ID of the user. 69 * @uses get_user_meta() WordPress function to get the usermeta for a user. 70 */ 71 function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) { 72 global $bp; 73 74 if ( empty( $user_id ) ) 75 return; 76 77 if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) { 78 $username = bp_core_get_username( $user_id, $user_nicename, $user_login ); 79 80 // If we are using a members slug, include it. 81 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) 82 $domain = $bp->root_domain . '/' . $bp->members->root_slug . '/' . $username; 83 else 84 $domain = $bp->root_domain . '/' . $username; 85 86 // Add a slash at the end 87 $domain = trailingslashit( $domain ); 88 89 // Cache the link 90 if ( !empty( $domain ) ) 91 wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' ); 92 } 93 94 return apply_filters( 'bp_core_get_user_domain', $domain ); 95 } 96 97 /** 98 * Fetch everything in the wp_users table for a user, without any usermeta. 99 * 100 * @package BuddyPress Core 101 * @param user_id The ID of the user. 102 * @uses BP_Core_User::get_core_userdata() Performs the query. 103 */ 104 function bp_core_get_core_userdata( $user_id ) { 105 if ( empty( $user_id ) ) 106 return false; 107 108 if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) { 109 $userdata = BP_Core_User::get_core_userdata( $user_id ); 110 wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' ); 111 } 112 return apply_filters( 'bp_core_get_core_userdata', $userdata ); 113 } 114 115 /** 116 * Returns the user id for the user that is currently being displayed. 117 * eg: http://andy.domain.com/ or http://domain.com/andy/ 118 * 119 * @package BuddyPress Core 120 * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed 121 * @return The user id for the user that is currently being displayed, return zero if this is not a user home and just a normal blog. 122 */ 123 function bp_core_get_displayed_userid( $user_login ) { 124 return apply_filters( 'bp_core_get_displayed_userid', bp_core_get_userid( $user_login ) ); 125 } 126 127 /** 128 * Returns the user_id for a user based on their username. 129 * 130 * @package BuddyPress Core 131 * @param $username str Username to check. 132 * @return false on no match 133 * @return int the user ID of the matched user. 134 */ 135 function bp_core_get_random_member() { 136 global $bp; 137 138 if ( isset( $_GET['random-member'] ) ) { 139 $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) ); 140 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) ); 141 } 142 } 143 add_action( 'wp', 'bp_core_get_random_member' ); 144 145 /** 146 * Returns the user_id for a user based on their username. 147 * 148 * @package BuddyPress Core 149 * @param $username str Username to check. 150 * @global $wpdb WordPress DB access object. 151 * @return false on no match 152 * @return int the user ID of the matched user. 153 */ 154 function bp_core_get_userid( $username ) { 155 global $wpdb; 156 157 if ( empty( $username ) ) 158 return false; 159 160 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 161 } 162 163 /** 164 * Returns the user_id for a user based on their user_nicename. 165 * 166 * @package BuddyPress Core 167 * @param $username str Username to check. 168 * @global $wpdb WordPress DB access object. 169 * @return false on no match 170 * @return int the user ID of the matched user. 171 */ 172 function bp_core_get_userid_from_nicename( $user_nicename ) { 173 global $wpdb; 174 175 if ( empty( $user_nicename ) ) 176 return false; 177 178 return apply_filters( 'bp_core_get_userid_from_nicename', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $user_nicename ) ) ); 179 } 180 181 /** 182 * Returns the username for a user based on their user id. 183 * 184 * @package BuddyPress Core 185 * @param $uid int User ID to check. 186 * @global $userdata WordPress user data for the current logged in user. 187 * @uses get_userdata() WordPress function to fetch the userdata for a user ID 188 * @return false on no match 189 * @return str the username of the matched user. 190 */ 191 function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) { 192 global $bp; 193 194 if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) { 195 if ( empty( $user_nicename ) && empty( $user_login ) ) { 196 $ud = false; 197 198 if ( isset( $bp->loggedin_user->id ) && $bp->loggedin_user->id == $user_id ) 199 $ud = &$bp->loggedin_user->userdata; 200 201 if ( isset( $bp->displayed_user->id ) && $bp->displayed_user->id == $user_id ) 202 $ud = &$bp->displayed_user->userdata; 203 204 if ( empty( $ud ) ) { 205 if ( !$ud = bp_core_get_core_userdata( $user_id ) ) 206 return false; 207 } 208 209 $user_nicename = $ud->user_nicename; 210 $user_login = $ud->user_login; 211 } 212 213 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 214 $username = $user_login; 215 else 216 $username = $user_nicename; 217 } 218 219 // Add this to cache 220 if ( !empty( $username ) ) 221 wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' ); 222 223 return apply_filters( 'bp_core_get_username', $username ); 224 } 225 226 /** 227 * Returns the email address for the user based on user ID 228 * 229 * @package BuddyPress Core 230 * @param $uid int User ID to check. 231 * @uses get_userdata() WordPress function to fetch the userdata for a user ID 232 * @return false on no match 233 * @return str The email for the matched user. 234 */ 235 function bp_core_get_user_email( $uid ) { 236 if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) { 237 $ud = bp_core_get_core_userdata($uid); 238 $email = $ud->user_email; 239 wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' ); 240 } 241 242 return apply_filters( 'bp_core_get_user_email', $email ); 243 } 244 245 /** 246 * Returns a HTML formatted link for a user with the user's full name as the link text. 247 * eg: <a href="http://andy.domain.com/">Andy Peatling</a> 248 * Optional parameters will return just the name, or just the URL, or disable "You" text when 249 * user matches the logged in user. 250 * 251 * [NOTES: This function needs to be cleaned up or split into separate functions] 252 * 253 * @package BuddyPress Core 254 * @param $uid int User ID to check. 255 * @param $no_anchor bool Disable URL and HTML and just return full name. Default false. 256 * @param $just_link bool Disable full name and HTML and just return the URL text. Default false. 257 * @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false. 258 * @global $userdata WordPress user data for the current logged in user. 259 * @uses get_userdata() WordPress function to fetch the userdata for a user ID 260 * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID. 261 * @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID 262 * @return false on no match 263 * @return str The link text based on passed parameters. 264 */ 265 function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) { 266 $display_name = bp_core_get_user_displayname( $user_id ); 267 268 if ( empty( $display_name ) ) 269 return false; 270 271 if ( $no_anchor ) 272 return $display_name; 273 274 if ( !$url = bp_core_get_user_domain( $user_id ) ) 275 return false; 276 277 if ( $just_link ) 278 return $url; 279 280 return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id ); 281 } 282 283 284 /** 285 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed. 286 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set. 287 * 288 * @package BuddyPress Core 289 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 290 * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again. 291 * @uses get_userdata() Fetches the WP userdata for a specific user. 292 * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id. 293 * @uses wp_cache_set() Adds a value to the cache. 294 * @return str The display name for the user in question. 295 */ 296 function bp_core_get_user_displayname( $user_id_or_username ) { 297 global $bp; 298 299 if ( !$user_id_or_username ) 300 return false; 301 302 if ( !is_numeric( $user_id_or_username ) ) 303 $user_id = bp_core_get_userid( $user_id_or_username ); 304 else 305 $user_id = $user_id_or_username; 306 307 if ( !$user_id ) 308 return false; 309 310 if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) { 311 if ( bp_is_active( 'xprofile' ) ) { 312 $fullname = xprofile_get_field_data( stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ), $user_id ); 313 314 if ( empty($fullname) ) { 315 $ud = bp_core_get_core_userdata( $user_id ); 316 317 if ( !empty( $ud->display_name ) ) 318 $fullname = $ud->display_name; 319 else 320 $fullname = $ud->user_nicename; 321 322 xprofile_set_field_data( 1, $user_id, $fullname ); 323 } 324 } else { 325 $ud = bp_core_get_core_userdata($user_id); 326 327 if ( !empty( $ud->display_name ) ) 328 $fullname = $ud->display_name; 329 else 330 $fullname = $ud->user_nicename; 331 } 332 333 if ( !empty( $fullname ) ) 334 wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' ); 335 } 336 337 return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id ); 338 } 339 add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 ); 340 add_filter( 'bp_core_get_user_displayname', 'trim' ); 341 add_filter( 'bp_core_get_user_displayname', 'stripslashes' ); 342 343 344 /** 345 * Returns the user link for the user based on user email address 346 * 347 * @package BuddyPress Core 348 * @param $email str The email address for the user. 349 * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID. 350 * @uses get_user_by_email() WordPress function to get userdata via an email address 351 * @return str The link to the users home base. False on no match. 352 */ 353 function bp_core_get_userlink_by_email( $email ) { 354 $user = get_user_by_email( $email ); 355 return apply_filters( 'bp_core_get_userlink_by_email', bp_core_get_userlink( $user->ID, false, false, true ) ); 356 } 357 358 /** 359 * Returns the user link for the user based on user's username 360 * 361 * @package BuddyPress Core 362 * @param $username str The username for the user. 363 * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID. 364 * @return str The link to the users home base. False on no match. 365 */ 366 function bp_core_get_userlink_by_username( $username ) { 367 global $wpdb; 368 369 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ); 370 return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) ); 371 } 372 373 /** 374 * Returns the total number of members for the installation. 375 * 376 * @package BuddyPress Core 377 * @return int The total number of members. 378 */ 379 function bp_core_get_total_member_count() { 380 global $wpdb, $bp; 381 382 if ( !$count = wp_cache_get( 'bp_total_member_count', 'bp' ) ) { 383 $status_sql = bp_core_get_status_sql(); 384 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql}" ) ); 385 wp_cache_set( 'bp_total_member_count', $count, 'bp' ); 386 } 387 388 return apply_filters( 'bp_core_get_total_member_count', $count ); 389 } 390 391 /** 392 * Checks if the user has been marked as a spammer. 393 * 394 * @package BuddyPress Core 395 * @param $user_id int The id for the user. 396 * @return int 1 if spammer, 0 if not. 397 */ 398 function bp_core_is_user_spammer( $user_id ) { 399 global $wpdb; 400 401 if ( is_multisite() ) 402 $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ); 403 else 404 $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ); 405 406 return apply_filters( 'bp_core_is_user_spammer', $is_spammer ); 407 } 408 409 /** 410 * Checks if the user has been marked as deleted. 411 * 412 * @package BuddyPress Core 413 * @param $user_id int The id for the user. 414 * @return int 1 if deleted, 0 if not. 415 */ 416 function bp_core_is_user_deleted( $user_id ) { 417 global $wpdb; 418 419 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 ) ) ); 420 } 421 422 /** 423 * Fetch every post that is authored by the given user for the current blog. 424 * 425 * @package BuddyPress Core 426 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 427 * @global $wpdb WordPress user data for the current logged in user. 428 * @return array of post ids. 429 */ 430 function bp_core_get_all_posts_for_user( $user_id = 0 ) { 431 global $bp, $wpdb; 432 433 if ( empty( $user_id ) ) 434 $user_id = $bp->displayed_user->id; 435 436 return apply_filters( 'bp_core_get_all_posts_for_user', $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 ) ) ); 437 } 438 439 /** 440 * Allows a user to completely remove their account from the system 441 * 442 * @package BuddyPress Core 443 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 444 * @uses is_super_admin() Checks to see if the user is a site administrator. 445 * @uses wpmu_delete_user() Deletes a user from the system on multisite installs. 446 * @uses wp_delete_user() Deletes a user from the system on singlesite installs. 447 * @uses get_site_option Checks if account deletion is allowed 448 */ 449 function bp_core_delete_account( $user_id = false ) { 450 global $bp, $wp_version; 451 452 if ( !$user_id ) 453 $user_id = $bp->loggedin_user->id; 454 455 // Make sure account deletion is not disabled 456 if ( !empty( $bp->site_options['bp-disable-account-deletion'] ) && !$bp->loggedin_user->is_super_admin ) 457 return false; 458 459 // Site admins cannot be deleted 460 if ( is_super_admin( bp_core_get_username( $user_id ) ) ) 461 return false; 462 463 // Specifically handle multi-site environment 464 if ( is_multisite() ) { 465 if ( $wp_version >= '3.0' ) 466 require_once( ABSPATH . '/wp-admin/includes/ms.php' ); 467 else 468 require_once( ABSPATH . '/wp-admin/includes/mu.php' ); 469 470 require_once( ABSPATH . '/wp-admin/includes/user.php' ); 471 472 return wpmu_delete_user( $user_id ); 473 474 // Single site user deletion 475 } else { 476 require_once( ABSPATH . '/wp-admin/includes/user.php' ); 477 return wp_delete_user( $user_id ); 478 } 479 } 480 481 /** 482 * Localization safe ucfirst() support. 483 * 484 * @package BuddyPress Core 485 */ 486 function bp_core_ucfirst( $str ) { 487 if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) { 488 $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) ); 489 return $fc.mb_substr( $str, 1 ); 490 } else { 491 return ucfirst( $str ); 492 } 493 } 494 495 /** 496 * Strips spaces from usernames that are created using add_user() and wp_insert_user() 497 * 498 * @package BuddyPress Core 499 */ 500 function bp_core_strip_username_spaces( $username ) { 501 // Don't alter the user_login of existing users, as it causes user_nicename problems. 502 // See http://trac.buddypress.org/ticket/2642 503 if ( username_exists( $username ) && ( !defined( 'BP_ENABLE_USER_COMPATIBILITY_MODE' ) || !BP_ENABLE_USER_COMPATIBILITY_MODE ) ) 504 return $username; 505 506 return str_replace( ' ', '-', $username ); 507 } 508 add_action( 'pre_user_login', 'bp_core_strip_username_spaces' ); 509 510 /** 511 * When a user logs in, check if they have been marked as a spammer. If yes then simply 512 * redirect them to the home page and stop them from logging in. 513 * 514 * @package BuddyPress Core 515 * @param $auth_obj The WP authorization object 516 * @param $username The username of the user logging in. 517 * @uses get_userdatabylogin() Get the userdata object for a user based on their username 518 * @uses bp_core_redirect() Safe redirect to a page 519 * @return $auth_obj If the user is not a spammer, return the authorization object 520 */ 521 function bp_core_boot_spammer( $auth_obj, $username ) { 522 global $bp; 523 524 if ( !$user = get_userdatabylogin( $username ) ) 525 return false; 526 527 if ( ( is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status ) 528 return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.', 'buddypress' ) ); 529 else 530 return $auth_obj; 531 } 532 add_filter( 'authenticate', 'bp_core_boot_spammer', 30, 2 ); 533 534 /** 535 * Deletes usermeta for the user when the user is deleted. 536 * 537 * @package BuddyPress Core 538 * @param $user_id The user id for the user to delete usermeta for 539 * @uses delete_user_meta() deletes a row from the wp_usermeta table based on meta_key 540 */ 541 function bp_core_remove_data( $user_id ) { 542 // Remove usermeta 543 delete_user_meta( $user_id, 'last_activity' ); 544 545 // Flush the cache to remove the user from all cached objects 546 wp_cache_flush(); 547 } 548 add_action( 'wpmu_delete_user', 'bp_core_remove_data' ); 549 add_action( 'delete_user', 'bp_core_remove_data' ); 550 add_action( 'bp_make_spam_user', 'bp_core_remove_data' ); 2 551 3 552 function bp_users_can_edit_settings() { -
trunk/bp-users/bp-users-loader.php
r3757 r3767 31 31 */ 32 32 function _setup_globals() { 33 global $bp ;33 global $bp, $current_user, $displayed_user_id; 34 34 35 35 // Define a slug, if necessary … … 39 39 // Do some slug checks 40 40 $this->slug = BP_MEMBERS_SLUG; 41 $this->root_slug = isset( $bp->pages-> users->slug ) ? $bp->pages->users->slug : $this->slug;41 $this->root_slug = isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : $this->slug; 42 42 43 43 // Tables 44 44 $this->table_name = $bp->table_prefix . 'bp_users'; 45 45 $this->table_name_meta = $bp->table_prefix . 'bp_users_meta'; 46 47 /** Logged in user ****************************************************/ 48 49 // Logged in user is the 'current_user' 50 $current_user = wp_get_current_user(); 51 52 // The user ID of the user who is currently logged in. 53 $bp->loggedin_user->id = $current_user->ID; 54 55 // The domain for the user currently logged in. eg: http://domain.com/members/andy 56 $bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id ); 57 58 // The core userdata of the user who is currently logged in. 59 $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id ); 60 61 // Fetch the full name for the logged in user 62 $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id ); 63 64 // is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. 65 $bp->loggedin_user->is_super_admin = is_super_admin(); 66 $bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6 67 68 /** 69 * Used to determine if user has admin rights on current content. If the 70 * logged in user is viewing their own profile and wants to delete 71 * something, is_item_admin is used. This is a generic variable so it 72 * can be used by other components. It can also be modified, so when 73 * viewing a group 'is_item_admin' would be 1 if they are a group 74 * admin, 0 if they are not. 75 */ 76 $bp->is_item_admin = bp_user_has_access(); 77 78 // Used to determine if the logged in user is a moderator for 79 // the current content. 80 $bp->is_item_mod = false; 81 82 /** Displayed user ****************************************************/ 83 84 // The user id of the user currently being viewed: 85 // $bp->displayed_user->id is set in /bp-core/bp-core-catchuri.php 86 if ( empty( $bp->displayed_user->id ) ) 87 $bp->displayed_user->id = 0; 88 89 // The domain for the user currently being displayed 90 $bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id ); 91 92 // The core userdata of the user who is currently being displayed 93 $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id ); 94 95 // Fetch the full name displayed user 96 $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id ); 97 98 /** Active Component **************************************************/ 99 100 // Users is active 101 $bp->active_components[$this->slug] = $this->id; 102 103 /** Default Profile Component *****************************************/ 104 if ( !$bp->current_component && $bp->displayed_user->id ) 105 $bp->current_component = $bp->default_component; 106 46 107 } 47 108 … … 163 224 } 164 225 // Create the users component 165 $bp-> users = new BP_User_Component();226 $bp->members = new BP_User_Component(); 166 227 167 228 ?> -
trunk/bp-users/bp-users-screens.php
r3757 r3767 1 1 <?php 2 /* 3 * To change this template, choose Tools | Templates 4 * and open the template in the editor. 5 */ 2 3 function bp_users_screen_index() { 4 global $bp; 5 6 if ( is_null( $bp->displayed_user->id ) && $bp->current_component == $bp->members->slug ) { 7 $bp->is_directory = true; 8 9 do_action( 'bp_users_screen_index' ); 10 11 bp_core_load_template( apply_filters( 'bp_users_screen_index', 'members/index' ) ); 12 } 13 } 14 add_action( 'wp', 'bp_users_screen_index', 2 ); 15 6 16 7 17 ?> -
trunk/bp-users/bp-users-template.php
r3757 r3767 1 1 <?php 2 /*3 * To change this template, choose Tools | Templates4 * and open the template in the editor.5 */6 7 2 8 3 function bp_displayed_user_email() {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)