Changeset 10356
- Timestamp:
- 11/15/2015 07:57:03 PM (9 years ago)
- Location:
- trunk/src/bp-core
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-actions.php
r10153 r10356 44 44 45 45 /** 46 * bp_loaded- Attached to 'plugins_loaded' above.46 * The bp_loaded hook - Attached to 'plugins_loaded' above. 47 47 * 48 48 * Attach various loader actions to the bp_loaded action. … … 59 59 60 60 /** 61 * bp_init- Attached to 'init' above.61 * The bp_init hook - Attached to 'init' above. 62 62 * 63 63 * Attach various initialization actions to the bp_init action. … … 77 77 78 78 /** 79 * bp_template_redirect- Attached to 'template_redirect' above.79 * The bp_template_redirect hook - Attached to 'template_redirect' above. 80 80 * 81 81 * Attach various template actions to the bp_template_redirect action. -
trunk/src/bp-core/bp-core-admin.php
r10318 r10356 17 17 * @package BuddyPress 18 18 * @subpackage CoreAdministration 19 * @todo Break this apart into each applicable Component 19 * @todo Break this apart into each applicable Component. 20 20 * 21 21 * @since 1.6.0 … … 97 97 98 98 // Paths and URLs 99 $this->admin_dir = trailingslashit( $bp->plugin_dir . 'bp-core/admin' ); // Admin path 100 $this->admin_url = trailingslashit( $bp->plugin_url . 'bp-core/admin' ); // Admin url 101 $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL 102 $this->css_url = trailingslashit( $this->admin_url . 'css' ); // Admin css URL 103 $this->js_url = trailingslashit( $this->admin_url . 'js' ); // Admin css URL 104 105 // Main settings page 99 $this->admin_dir = trailingslashit( $bp->plugin_dir . 'bp-core/admin' ); // Admin path. 100 $this->admin_url = trailingslashit( $bp->plugin_url . 'bp-core/admin' ); // Admin url. 101 $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL. 102 $this->css_url = trailingslashit( $this->admin_url . 'css' ); // Admin css URL. 103 $this->js_url = trailingslashit( $this->admin_url . 'js' ); // Admin css URL. 104 105 // Main settings page. 106 106 $this->settings_page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php'; 107 107 108 // Main capability 108 // Main capability. 109 109 $this->capability = bp_core_do_network_admin() ? 'manage_network_options' : 'manage_options'; 110 110 } … … 134 134 private function setup_actions() { 135 135 136 /* *General Actions ***************************************************/137 138 // Add some page specific output to the <head> 136 /* General Actions ***************************************************/ 137 138 // Add some page specific output to the <head>. 139 139 add_action( 'bp_admin_head', array( $this, 'admin_head' ), 999 ); 140 140 141 // Add menu item to settings menu 141 // Add menu item to settings menu. 142 142 add_action( bp_core_admin_hook(), array( $this, 'admin_menus' ), 5 ); 143 143 144 // Enqueue all admin JS and CSS 144 // Enqueue all admin JS and CSS. 145 145 add_action( 'bp_admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 146 146 147 /* *BuddyPress Actions ************************************************/148 149 // Load the BuddyPress metabox in the WP Nav Menu Admin UI 147 /* BuddyPress Actions ************************************************/ 148 149 // Load the BuddyPress metabox in the WP Nav Menu Admin UI. 150 150 add_action( 'load-nav-menus.php', 'bp_admin_wp_nav_menu_meta_box' ); 151 151 152 // Add settings 152 // Add settings. 153 153 add_action( 'bp_register_admin_settings', array( $this, 'register_admin_settings' ) ); 154 154 155 // Add a link to BuddyPress About page to the admin bar 155 // Add a link to BuddyPress About page to the admin bar. 156 156 add_action( 'admin_bar_menu', array( $this, 'admin_bar_about_link' ), 15 ); 157 157 158 // Add a description of new BuddyPress tools in the available tools page 158 // Add a description of new BuddyPress tools in the available tools page. 159 159 add_action( 'tool_box', 'bp_core_admin_available_tools_intro' ); 160 160 add_action( 'bp_network_tool_box', 'bp_core_admin_available_tools_intro' ); 161 161 162 // On non-multisite, catch 162 // On non-multisite, catch. 163 163 add_action( 'load-users.php', 'bp_core_admin_user_manage_spammers' ); 164 164 165 /* *Filters ***********************************************************/166 167 // Add link to settings page 165 /* Filters ***********************************************************/ 166 167 // Add link to settings page. 168 168 add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); 169 169 add_filter( 'network_admin_plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); 170 170 171 // Add "Mark as Spam" row actions on users.php 171 // Add "Mark as Spam" row actions on users.php. 172 172 add_filter( 'ms_user_row_actions', 'bp_core_admin_user_row_actions', 10, 2 ); 173 173 add_filter( 'user_row_actions', 'bp_core_admin_user_row_actions', 10, 2 ); … … 185 185 public function admin_menus() { 186 186 187 // Bail if user cannot moderate 187 // Bail if user cannot moderate. 188 188 if ( ! bp_current_user_can( 'manage_options' ) ) { 189 189 return; 190 190 } 191 191 192 // About 192 // About. 193 193 add_dashboard_page( 194 194 __( 'Welcome to BuddyPress', 'buddypress' ), … … 199 199 ); 200 200 201 // Credits 201 // Credits. 202 202 add_dashboard_page( 203 203 __( 'Welcome to BuddyPress', 'buddypress' ), … … 210 210 $hooks = array(); 211 211 212 // Changed in BP 1.6 . See bp_core_admin_backpat_menu() 212 // Changed in BP 1.6 . See bp_core_admin_backpat_menu(). 213 213 $hooks[] = add_menu_page( 214 214 __( 'BuddyPress', 'buddypress' ), … … 229 229 ); 230 230 231 // Add the option pages 231 // Add the option pages. 232 232 $hooks[] = add_submenu_page( 233 233 $this->settings_page, … … 258 258 259 259 // For consistency with non-Multisite, we add a Tools menu in 260 // the Network Admin as a home for our Tools panel 260 // the Network Admin as a home for our Tools panel. 261 261 if ( is_multisite() && bp_core_do_network_admin() ) { 262 262 $tools_parent = 'network-tools'; … … 269 269 'bp_core_tools_top_level_item', 270 270 '', 271 24 // just above Settings271 24 // Just above Settings. 272 272 ); 273 273 … … 293 293 ); 294 294 295 // Fudge the highlighted subnav item when on a BuddyPress admin page 295 // Fudge the highlighted subnav item when on a BuddyPress admin page. 296 296 foreach( $hooks as $hook ) { 297 297 add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' ); … … 310 310 public function register_admin_settings() { 311 311 312 /* *Main Section ******************************************************/313 314 // Add the main section 312 /* Main Section ******************************************************/ 313 314 // Add the main section. 315 315 add_settings_section( 'bp_main', __( 'Main Settings', 'buddypress' ), 'bp_admin_setting_callback_main_section', 'buddypress' ); 316 316 317 // Hide toolbar for logged out users setting 317 // Hide toolbar for logged out users setting. 318 318 add_settings_field( 'hide-loggedout-adminbar', __( 'Toolbar', 'buddypress' ), 'bp_admin_setting_callback_admin_bar', 'buddypress', 'bp_main' ); 319 319 register_setting( 'buddypress', 'hide-loggedout-adminbar', 'intval' ); 320 320 321 // Only show 'switch to Toolbar' option if the user chose to retain the BuddyBar during the 1.6 upgrade 321 // Only show 'switch to Toolbar' option if the user chose to retain the BuddyBar during the 1.6 upgrade. 322 322 if ( (bool) bp_get_option( '_bp_force_buddybar', false ) ) { 323 323 add_settings_field( '_bp_force_buddybar', __( 'Toolbar', 'buddypress' ), 'bp_admin_setting_callback_force_buddybar', 'buddypress', 'bp_main' ); … … 325 325 } 326 326 327 // Allow account deletion 327 // Allow account deletion. 328 328 add_settings_field( 'bp-disable-account-deletion', __( 'Account Deletion', 'buddypress' ), 'bp_admin_setting_callback_account_deletion', 'buddypress', 'bp_main' ); 329 329 register_setting( 'buddypress', 'bp-disable-account-deletion', 'intval' ); 330 330 331 /* *XProfile Section **************************************************/331 /* XProfile Section **************************************************/ 332 332 333 333 if ( bp_is_active( 'xprofile' ) ) { 334 334 335 // Add the main section 335 // Add the main section. 336 336 add_settings_section( 'bp_xprofile', _x( 'Profile Settings', 'BuddyPress setting tab', 'buddypress' ), 'bp_admin_setting_callback_xprofile_section', 'buddypress' ); 337 337 338 // Avatars 338 // Avatars. 339 339 add_settings_field( 'bp-disable-avatar-uploads', __( 'Profile Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', 'bp_xprofile' ); 340 340 register_setting( 'buddypress', 'bp-disable-avatar-uploads', 'intval' ); 341 341 342 // Cover images 342 // Cover images. 343 343 if ( bp_is_active( 'xprofile', 'cover_image' ) ) { 344 344 add_settings_field( 'bp-disable-cover-image-uploads', __( 'Cover Image Uploads', 'buddypress' ), 'bp_admin_setting_callback_cover_image_uploads', 'buddypress', 'bp_xprofile' ); … … 346 346 } 347 347 348 // Profile sync setting 348 // Profile sync setting. 349 349 add_settings_field( 'bp-disable-profile-sync', __( 'Profile Syncing', 'buddypress' ), 'bp_admin_setting_callback_profile_sync', 'buddypress', 'bp_xprofile' ); 350 350 register_setting ( 'buddypress', 'bp-disable-profile-sync', 'intval' ); 351 351 } 352 352 353 /* *Groups Section ****************************************************/353 /* Groups Section ****************************************************/ 354 354 355 355 if ( bp_is_active( 'groups' ) ) { 356 356 357 // Add the main section 357 // Add the main section. 358 358 add_settings_section( 'bp_groups', __( 'Groups Settings', 'buddypress' ), 'bp_admin_setting_callback_groups_section', 'buddypress' ); 359 359 360 // Allow subscriptions setting 360 // Allow subscriptions setting. 361 361 add_settings_field( 'bp_restrict_group_creation', __( 'Group Creation', 'buddypress' ), 'bp_admin_setting_callback_group_creation', 'buddypress', 'bp_groups' ); 362 362 register_setting( 'buddypress', 'bp_restrict_group_creation', 'intval' ); … … 373 373 } 374 374 375 /* *Forums ************************************************************/375 /* Forums ************************************************************/ 376 376 377 377 if ( bp_is_active( 'forums' ) ) { 378 378 379 // Add the main section 379 // Add the main section. 380 380 add_settings_section( 'bp_forums', __( 'Legacy Group Forums', 'buddypress' ), 'bp_admin_setting_callback_bbpress_section', 'buddypress' ); 381 381 382 // Allow subscriptions setting 382 // Allow subscriptions setting. 383 383 add_settings_field( 'bb-config-location', __( 'bbPress Configuration', 'buddypress' ), 'bp_admin_setting_callback_bbpress_configuration', 'buddypress', 'bp_forums' ); 384 384 register_setting( 'buddypress', 'bb-config-location', '' ); 385 385 } 386 386 387 /* *Activity Section **************************************************/387 /* Activity Section **************************************************/ 388 388 389 389 if ( bp_is_active( 'activity' ) ) { 390 390 391 // Add the main section 391 // Add the main section. 392 392 add_settings_section( 'bp_activity', __( 'Activity Settings', 'buddypress' ), 'bp_admin_setting_callback_activity_section', 'buddypress' ); 393 393 394 // Activity commenting on blog and forum posts 394 // Activity commenting on blog and forum posts. 395 395 add_settings_field( 'bp-disable-blogforum-comments', __( 'Blog & Forum Comments', 'buddypress' ), 'bp_admin_setting_callback_blogforum_comments', 'buddypress', 'bp_activity' ); 396 396 register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'bp_admin_sanitize_callback_blogforum_comments' ); 397 397 398 // Activity Heartbeat refresh 398 // Activity Heartbeat refresh. 399 399 add_settings_field( '_bp_enable_heartbeat_refresh', __( 'Activity auto-refresh', 'buddypress' ), 'bp_admin_setting_callback_heartbeat', 'buddypress', 'bp_activity' ); 400 400 register_setting( 'buddypress', '_bp_enable_heartbeat_refresh', 'intval' ); 401 401 402 // Allow activity akismet 402 // Allow activity akismet. 403 403 if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) { 404 404 add_settings_field( '_bp_enable_akismet', __( 'Akismet', 'buddypress' ), 'bp_admin_setting_callback_activity_akismet', 'buddypress', 'bp_activity' ); … … 433 433 * @param array $links Links array in which we would prepend our link. 434 434 * @param string $file Current plugin basename. 435 *436 435 * @return array Processed links. 437 436 */ 438 437 public function modify_plugin_action_links( $links, $file ) { 439 438 440 // Return normal links if not BuddyPress 439 // Return normal links if not BuddyPress. 441 440 if ( plugin_basename( buddypress()->basename ) != $file ) { 442 441 return $links; 443 442 } 444 443 445 // Add a few links to the existing links array 444 // Add a few links to the existing links array. 446 445 return array_merge( $links, array( 447 446 'settings' => '<a href="' . esc_url( add_query_arg( array( 'page' => 'bp-components' ), bp_get_admin_url( $this->settings_page ) ) ) . '">' . esc_html__( 'Settings', 'buddypress' ) . '</a>', … … 457 456 public function admin_head() { 458 457 459 // Settings pages 458 // Settings pages. 460 459 remove_submenu_page( $this->settings_page, 'bp-page-settings' ); 461 460 remove_submenu_page( $this->settings_page, 'bp-settings' ); 462 461 463 // Network Admin Tools 462 // Network Admin Tools. 464 463 remove_submenu_page( 'network-tools', 'network-tools' ); 465 464 466 // About and Credits pages 465 // About and Credits pages. 467 466 remove_submenu_page( 'index.php', 'bp-about' ); 468 467 remove_submenu_page( 'index.php', 'bp-credits' ); … … 797 796 public static function welcome_text() { 798 797 799 // Switch welcome text based on whether this is a new installation or not 798 // Switch welcome text based on whether this is a new installation or not. 800 799 $welcome_text = ( self::is_new_install() ) 801 800 ? __( 'Thank you for installing BuddyPress! BuddyPress helps you run any kind of social network on your WordPress, with member profiles, activity streams, user groups, messaging, and more.', 'buddypress' ) … … 825 824 * 826 825 * @since 2.2.0 827 * @param string $tab 826 * 827 * @param string $tab Tab to highlight as active. 828 828 */ 829 829 public static function tab_navigation( $tab = 'whats_new' ) { … … 865 865 public static function display_version() { 866 866 867 // Use static variable to prevent recalculations 867 // Use static variable to prevent recalculations. 868 868 static $display = ''; 869 869 870 // Only calculate on first run 870 // Only calculate on first run. 871 871 if ( '' === $display ) { 872 872 873 // Get current version 873 // Get current version. 874 874 $version = bp_get_version(); 875 875 876 // Check for prerelease hyphen 876 // Check for prerelease hyphen. 877 877 $pre = strpos( $version, '-' ); 878 878 879 // Strip prerelease suffix 879 // Strip prerelease suffix. 880 880 $display = ( false !== $pre ) 881 881 ? substr( $version, 0, $pre ) … … 887 887 } 888 888 } 889 endif; // class_exists check889 endif; // End class_exists check. 890 890 891 891 /** … … 902 902 903 903 // These are strings we may use to describe maintenance/security releases, where we aim for no new strings. 904 905 904 _n_noop( 'Maintenance Release', 'Maintenance Releases', 'buddypress' ); 906 905 _n_noop( 'Security Release', 'Security Releases', 'buddypress' ); -
trunk/src/bp-core/bp-core-adminbar.php
r10108 r10356 17 17 * @since 1.6.0 18 18 * 19 * @global WP_Admin_Bar $wp_admin_bar 19 * @global WP_Admin_Bar $wp_admin_bar. 20 20 */ 21 21 function bp_admin_bar_my_account_root() { 22 22 global $wp_admin_bar; 23 23 24 // Bail if this is an ajax request 24 // Bail if this is an ajax request. 25 25 if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) ) 26 26 return; 27 27 28 // Only add menu for logged in user 28 // Only add menu for logged in user. 29 29 if ( is_user_logged_in() ) { 30 30 31 // Add secondary parent item for all BuddyPress components 31 // Add secondary parent item for all BuddyPress components. 32 32 $wp_admin_bar->add_menu( array( 33 33 'parent' => 'my-account', … … 40 40 ) ); 41 41 42 // Remove 'Edit' post link as it's not applicable to BP 43 // Remove when https://core.trac.wordpress.org/ticket/29538 is addressed 42 // Remove 'Edit' post link as it's not applicable to BP. 43 // Remove when https://core.trac.wordpress.org/ticket/29538 is addressed. 44 44 if ( is_buddypress() ) { 45 45 $wp_admin_bar->remove_node( 'edit' ); … … 69 69 function bp_core_load_admin_bar() { 70 70 71 // Show the Toolbar for logged out users 71 // Show the Toolbar for logged out users. 72 72 if ( ! is_user_logged_in() && (int) bp_get_option( 'hide-loggedout-adminbar' ) != 1 ) { 73 73 show_admin_bar( true ); 74 74 } 75 75 76 // Hide the WordPress Toolbar and show the BuddyBar 76 // Hide the WordPress Toolbar and show the BuddyBar. 77 77 if ( ! bp_use_wp_admin_bar() ) { 78 78 _doing_it_wrong( __FUNCTION__, __( 'The BuddyBar is no longer supported. Please migrate to the WordPress toolbar as soon as possible.', 'buddypress' ), '2.1.0' ); 79 79 80 // Keep the WP Toolbar from loading 80 // Keep the WP Toolbar from loading. 81 81 show_admin_bar( false ); 82 82 83 // Actions used to build the BP Toolbar 83 // Actions used to build the BP Toolbar. 84 84 add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' ); 85 85 add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 ); … … 88 88 add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 ); 89 89 90 // Actions used to append BP Toolbar to footer 90 // Actions used to append BP Toolbar to footer. 91 91 add_action( 'wp_footer', 'bp_core_admin_bar', 8 ); 92 92 add_action( 'admin_footer', 'bp_core_admin_bar' ); … … 125 125 } 126 126 127 // Enqueue the additional adminbar css 127 // Enqueue the additional adminbar css. 128 128 wp_enqueue_style( 'bp-admin-bar' ); 129 129 } -
trunk/src/bp-core/bp-core-attachments.php
r10193 r10356 17 17 * match with our needs. 18 18 * 19 * @since 19 * @since 2.3.0 20 20 * 21 21 * @return bool True if WordPress is 3.9+, false otherwise. … … 26 26 27 27 /** 28 * Get the Attachments Uploads dir data 29 * 30 * @since 31 * 32 * @param string $data The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'33 * 34 * @return string|array 28 * Get the Attachments Uploads dir data. 29 * 30 * @since 2.4.0 31 * 32 * @param string $data The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'. 33 * Leave empty to get all datas. 34 * @return string|array The needed Upload dir data. 35 35 */ 36 36 function bp_attachments_uploads_dir_get( $data = '' ) { … … 43 43 $upload_data = bp_upload_dir(); 44 44 45 // Build the Upload data array for BuddyPress attachments 45 // Build the Upload data array for BuddyPress attachments. 46 46 foreach ( $upload_data as $key => $value ) { 47 47 if ( 'basedir' === $key || 'baseurl' === $key ) { … … 52 52 } 53 53 54 // Add the dir to the array 54 // Add the dir to the array. 55 55 $upload_data['dir'] = $attachments_dir; 56 56 … … 65 65 * Filter here to edit the Attachments upload dir data. 66 66 * 67 * @since 68 * 69 * @param string|array $retvalThe needed Upload dir data or the full array of data70 * @param string $dataThe data requested67 * @since 2.4.0 68 * 69 * @param string|array $retval The needed Upload dir data or the full array of data 70 * @param string $data The data requested 71 71 */ 72 72 return apply_filters( 'bp_attachments_uploads_dir_get', $retval, $data ); … … 74 74 75 75 /** 76 * Get the max upload file size for any attachment 77 * 78 * @since 79 * 80 * @param 81 * we wish to get the max upload file size for82 * @return int max upload file size for any attachment76 * Get the max upload file size for any attachment. 77 * 78 * @since 2.4.0 79 * 80 * @param string $type A string to inform about the type of attachment 81 * we wish to get the max upload file size for. 82 * @return int Max upload file size for any attachment. 83 83 */ 84 84 function bp_attachments_get_max_upload_file_size( $type = '' ) { … … 94 94 * Filter here to edit the max upload file size. 95 95 * 96 * @since 97 * 98 * @param int $fileupload_maxk Max upload file size for any attachment99 * @param string $type The attachment type (eg: 'avatar' or 'cover_image')96 * @since 2.4.0 97 * 98 * @param int $fileupload_maxk Max upload file size for any attachment. 99 * @param string $type The attachment type (eg: 'avatar' or 'cover_image'). 100 100 */ 101 101 return apply_filters( 'bp_attachments_get_max_upload_file_size', $fileupload_maxk, $type ); … … 103 103 104 104 /** 105 * Get allowed types for any attachment 106 * 107 * @since 108 * 109 * @param string $typeThe extension types to get.110 * Default: 'avatar'111 * @return array The list of allowed extensions for attachments105 * Get allowed types for any attachment. 106 * 107 * @since 2.4.0 108 * 109 * @param string $type The extension types to get. 110 * Default: 'avatar'. 111 * @return array The list of allowed extensions for attachments. 112 112 */ 113 113 function bp_attachments_get_allowed_types( $type = 'avatar' ) { 114 // Defaults to BuddyPress supported image extensions 114 // Defaults to BuddyPress supported image extensions. 115 115 $exts = array( 'jpeg', 'gif', 'png' ); 116 116 117 117 /** 118 118 * It's not a BuddyPress feature, get the allowed extensions 119 * matching the $type requested 119 * matching the $type requested. 120 120 */ 121 121 if ( 'avatar' !== $type && 'cover_image' !== $type ) { 122 // Reset the default exts 122 // Reset the default exts. 123 123 $exts = array(); 124 124 … … 136 136 137 137 /** 138 * Search for allowed mimes matching the type 138 * Search for allowed mimes matching the type. 139 139 * 140 * eg: using 'application/vnd.oasis' as the $type140 * Eg: using 'application/vnd.oasis' as the $type 141 141 * parameter will get all OpenOffice extensions supported 142 142 * by WordPress and allowed for the current user. … … 148 148 $allowed_types = array_keys( $allowed_mimes ); 149 149 150 // Loop to explode keys using '|' 150 // Loop to explode keys using '|'. 151 151 foreach ( $allowed_types as $allowed_type ) { 152 152 $t = explode( '|', $allowed_type ); … … 160 160 * Filter here to edit the allowed extensions by attachment type. 161 161 * 162 * @since 163 * 164 * @param array $exts List of allowed extensions165 * @param string $type The requested file type162 * @since 2.4.0 163 * 164 * @param array $exts List of allowed extensions. 165 * @param string $type The requested file type. 166 166 */ 167 167 return apply_filters( 'bp_attachments_get_allowed_types', $exts, $type ); … … 173 173 * @since 2.4.0 174 174 * 175 * @param string $typeThe extension types to get (Optional).176 * @param array $allowed_types List of allowed extensions177 * @return array List of allowed mime types175 * @param string $type The extension types to get (Optional). 176 * @param array $allowed_types List of allowed extensions. 177 * @return array List of allowed mime types. 178 178 */ 179 179 function bp_attachments_get_allowed_mimes( $type = '', $allowed_types = array() ) { … … 196 196 197 197 /** 198 * Check the uploaded attachment type is allowed 199 * 200 * @since 201 * 202 * @param 203 * @param 204 * 205 * @param array $allowed_mimes The attachment allowed mimes (Required)206 * @return bool 198 * Check the uploaded attachment type is allowed. 199 * 200 * @since 2.4.0 201 * 202 * @param string $file Full path to the file. 203 * @param string $filename The name of the file (may differ from $file due to $file being 204 * in a tmp directory). 205 * @param array $allowed_mimes The attachment allowed mimes (Required). 206 * @return bool True if the attachment type is allowed. False otherwise 207 207 */ 208 208 function bp_attachments_check_filetype( $file, $filename, $allowed_mimes ) { … … 221 221 * @since 2.4.0 222 222 * 223 * @param string $typeThe attachment type to create (avatar or cover_image). Default: avatar.224 * @param 223 * @param string $type The attachment type to create (avatar or cover_image). Default: avatar. 224 * @param array $args { 225 225 * @type int $item_id The ID of the object (Required). Default: 0. 226 226 * @type string $object The object type (eg: group, user, blog) (Required). Default: 'user'. … … 232 232 * @type int $crop_y The vertical starting point of the crop. Default: 0. 233 233 * } 234 * @return bool 234 * @return bool True on success, false otherwise. 235 235 */ 236 236 function bp_attachments_create_item_type( $type = 'avatar', $args = array() ) { … … 254 254 } 255 255 256 // Make sure the file path is safe 256 // Make sure the file path is safe. 257 257 if ( 0 !== validate_file( $r['image'] ) ) { 258 258 return false; 259 259 } 260 260 261 // Set the component if not already done 261 // Set the component if not already done. 262 262 if ( empty( $r['component'] ) ) { 263 263 if ( 'user' === $r['object'] ) { … … 277 277 } 278 278 279 // Init the Attachment data 279 // Init the Attachment data. 280 280 $attachment_data = array(); 281 281 282 282 if ( 'avatar' === $type ) { 283 // Set crop width for the avatar if not given 283 // Set crop width for the avatar if not given. 284 284 if ( empty( $r['crop_w'] ) ) { 285 285 $r['crop_w'] = bp_core_avatar_full_width(); 286 286 } 287 287 288 // Set crop height for the avatar if not given 288 // Set crop height for the avatar if not given. 289 289 if ( empty( $r['crop_h'] ) ) { 290 290 $r['crop_h'] = bp_core_avatar_full_height(); … … 294 294 $dir_args = array( $r['item_id'] ); 295 295 296 // In case of xprofile, we need an extra argument 296 // In case of xprofile, we need an extra argument. 297 297 if ( 'xprofile' === $r['component'] ) { 298 298 $dir_args = array( false, $r['item_id'] ); … … 304 304 $attachment_data = bp_attachments_uploads_dir_get(); 305 305 306 // Default to members for xProfile 306 // Default to members for xProfile. 307 307 $object_subdir = 'members'; 308 308 … … 311 311 } 312 312 313 // Set Subdir 313 // Set Subdir. 314 314 $attachment_data['subdir'] = $object_subdir . '/' . $r['item_id'] . '/cover-image'; 315 315 316 // Set Path 316 // Set Path. 317 317 $attachment_data['path'] = trailingslashit( $attachment_data['basedir'] ) . $attachment_data['subdir']; 318 318 } … … 322 322 } 323 323 324 // It's not a regular upload, we may need to create some folders 324 // It's not a regular upload, we may need to create some folders. 325 325 if ( ! is_dir( $attachment_data['path'] ) ) { 326 326 if ( ! wp_mkdir_p( $attachment_data['path'] ) ) { … … 329 329 } 330 330 331 // Set the image name and path 331 // Set the image name and path. 332 332 $image_file_name = wp_unique_filename( $attachment_data['path'], basename( $r['image'] ) ); 333 333 $image_file_path = $attachment_data['path'] . '/' . $image_file_name; 334 334 335 // Copy the image file into the avatar dir 335 // Copy the image file into the avatar dir. 336 336 if ( ! copy( $r['image'], $image_file_path ) ) { 337 337 return false; 338 338 } 339 339 340 // Init the response 340 // Init the response. 341 341 $created = false; 342 342 … … 354 354 ) ); 355 355 356 // It's a cover image we need to fit it to feature's dimensions 356 // It's a cover image we need to fit it to feature's dimensions. 357 357 } elseif ( 'cover_image' === $type ) { 358 358 $cover_image = bp_attachments_cover_image_generate_file( array( … … 365 365 } 366 366 367 // Remove copied file if it fails 367 // Remove copied file if it fails. 368 368 if ( ! $created ) { 369 369 @unlink( $image_file_path ); 370 370 } 371 371 372 // Return the response 372 // Return the response. 373 373 return $created; 374 374 } 375 375 376 376 /** 377 * Get the url or the path for a type of attachment 378 * 379 * @since 380 * 381 * @param string $data whether to get the url or the path382 * @param 377 * Get the url or the path for a type of attachment. 378 * 379 * @since 2.4.0 380 * 381 * @param string $data whether to get the url or the path. 382 * @param array $args { 383 383 * @type string $object_dir The object dir (eg: members/groups). Defaults to members. 384 384 * @type int $item_id The object id (eg: a user or a group id). Defaults to current user. … … 387 387 * @type string $file The name of the file. 388 388 * } 389 * @return string|bool the url or the path to the attachment, false otherwise389 * @return string|bool The url or the path to the attachment, false otherwise 390 390 */ 391 391 function bp_attachments_get_attachment( $data = 'url', $args = array() ) { 392 // Default value 392 // Default value. 393 393 $attachment_data = false; 394 394 … … 400 400 ), 'attachments_get_attachment_src' ); 401 401 402 // Get BuddyPress Attachments Uploads Dir datas 402 // Get BuddyPress Attachments Uploads Dir datas. 403 403 $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get(); 404 404 … … 424 424 $file = false; 425 425 426 // Open the directory and get the first file 426 // Open the directory and get the first file. 427 427 if ( $att_dir = opendir( $type_dir ) ) { 428 428 429 429 while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) { 430 // Look for the first file having the type in its name 430 // Look for the first file having the type in its name. 431 431 if ( false !== strpos( $attachment_file, $r['type'] ) && empty( $file ) ) { 432 432 $file = $attachment_file; … … 453 453 * Delete an attachment for the given arguments 454 454 * 455 * @since 2.4.0 456 * 457 * @param array $args 458 * @see bp_attachments_get_attachment() For more information on accepted arguments. 459 * @return bool True if the attachment was deleted, false otherwise 455 * @since 2.4.0 456 * 457 * @see bp_attachments_get_attachment() For more information on accepted arguments. 458 * 459 * @param array $args Array of arguments for the attachment deletion. 460 * @return bool True if the attachment was deleted, false otherwise. 460 461 */ 461 462 function bp_attachments_delete_file( $args = array() ) { … … 473 474 * Get the BuddyPress Plupload settings. 474 475 * 475 * @since 476 * 477 * @return array list of BuddyPress Plupload settings.476 * @since 2.3.0 477 * 478 * @return array List of BuddyPress Plupload settings. 478 479 */ 479 480 function bp_attachments_get_plupload_default_settings() { … … 523 524 * @since 2.3.0 524 525 * 525 * @param array $ params Default Plupload parameters array.526 * @param array $settings Default Plupload parameters array. 526 527 */ 527 528 return apply_filters( 'bp_attachments_get_plupload_default_settings', $settings ); … … 531 532 * Builds localization strings for the BuddyPress Uploader scripts. 532 533 * 533 * @since 534 * @since 2.3.0 534 535 * 535 536 * @return array Plupload default localization strings. 536 537 */ 537 538 function bp_attachments_get_plupload_l10n() { 538 // Localization strings 539 // Localization strings. 539 540 return apply_filters( 'bp_attachments_get_plupload_l10n', array( 540 541 'queue_limit_exceeded' => __( 'You have attempted to queue too many files.', 'buddypress' ), … … 567 568 * Enqueues the script needed for the Uploader UI. 568 569 * 569 * @see 570 * @see BP_Attachment::script_data() && BP_Attachment_Avatar::script_data() for examples showing how 570 571 * to set specific script data. 571 572 * 572 * @since 2.3.0 573 * 574 * @param string $class name of the class extending BP_Attachment (eg: BP_Attachment_Avatar). 575 * 573 * @since 2.3.0 574 * 575 * @param string $class Name of the class extending BP_Attachment (eg: BP_Attachment_Avatar). 576 576 * @return null|WP_Error 577 577 */ … … 586 586 } 587 587 588 // Get an instance of the class and get the script data 588 // Get an instance of the class and get the script data. 589 589 $attachment = new $class; 590 590 $script_data = $attachment->script_data(); … … 607 607 } 608 608 609 // Get the BuddyPress uploader strings 609 // Get the BuddyPress uploader strings. 610 610 $strings = bp_attachments_get_plupload_l10n(); 611 611 612 // Get the BuddyPress uploader settings 612 // Get the BuddyPress uploader settings. 613 613 $settings = bp_attachments_get_plupload_default_settings(); 614 614 615 // Set feedback messages 615 // Set feedback messages. 616 616 if ( ! empty( $args['feedback_messages'] ) ) { 617 617 $strings['feedback_messages'] = $args['feedback_messages']; 618 618 } 619 619 620 // Use a temporary var to ease manipulation 620 // Use a temporary var to ease manipulation. 621 621 $defaults = $settings['defaults']; 622 622 623 // Set the upload action 623 // Set the upload action. 624 624 $defaults['multipart_params']['action'] = $args['action']; 625 625 626 // Set BuddyPress upload parameters if provided 626 // Set BuddyPress upload parameters if provided. 627 627 if ( ! empty( $args['bp_params'] ) ) { 628 628 $defaults['multipart_params']['bp_params'] = $args['bp_params']; 629 629 } 630 630 631 // Merge other arguments 631 // Merge other arguments. 632 632 $ui_args = array_intersect_key( $args, array( 633 633 'file_data_name' => true, … … 643 643 } 644 644 645 // Specific to BuddyPress Avatars 645 // Specific to BuddyPress Avatars. 646 646 if ( 'bp_avatar_upload' === $defaults['multipart_params']['action'] ) { 647 647 648 // Include the cropping informations for avatars 648 // Include the cropping informations for avatars. 649 649 $settings['crop'] = array( 650 650 'full_h' => bp_core_avatar_full_height(), … … 655 655 $defaults['multi_selection'] = false; 656 656 657 // Does the object already has an avatar set 657 // Does the object already has an avatar set. 658 658 $has_avatar = $defaults['multipart_params']['bp_params']['has_avatar']; 659 659 660 // What is the object the avatar belongs to 660 // What is the object the avatar belongs to. 661 661 $object = $defaults['multipart_params']['bp_params']['object']; 662 662 663 // Init the Avatar nav 663 // Init the Avatar nav. 664 664 $avatar_nav = array( 665 665 'upload' => array( 'id' => 'upload', 'caption' => __( 'Upload', 'buddypress' ), 'order' => 0 ), 666 666 667 // The delete view will only show if the object has an avatar 667 // The delete view will only show if the object has an avatar. 668 668 'delete' => array( 'id' => 'delete', 'caption' => __( 'Delete', 'buddypress' ), 'order' => 100, 'hide' => (int) ! $has_avatar ), 669 669 ); 670 670 671 // Create the Camera Nav if the WebCam capture feature is enabled 671 // Create the Camera Nav if the WebCam capture feature is enabled. 672 672 if ( bp_avatar_use_webcam() && 'user' === $object ) { 673 673 $avatar_nav['camera'] = array( 'id' => 'camera', 'caption' => __( 'Take Photo', 'buddypress' ), 'order' => 10 ); 674 674 675 // Set warning messages 675 // Set warning messages. 676 676 $strings['camera_warnings'] = array( 677 677 'requesting' => __( 'Please allow us to access to your camera.', 'buddypress'), … … 691 691 * @since 2.3.0 692 692 * 693 * @param array $avatar_nav An associative array of available nav items where each item is an array organized this way: 694 * $avatar_nav[ $nav_item_id ] { 693 * @param array $avatar_nav { 694 * An associative array of available nav items where each item is an array organized this way: 695 * $avatar_nav[ $nav_item_id ]. 695 696 * @type string $nav_item_id The nav item id in lower case without special characters or space. 696 697 * @type string $caption The name of the item nav that will be displayed in the nav. … … 700 701 * (only used for the delete nav item). 701 702 * } 702 * @param string $object the object the avatar belongs to (eg: user or group)703 * @param string $object The object the avatar belongs to (eg: user or group). 703 704 */ 704 705 $settings['nav'] = bp_sort_by_key( apply_filters( 'bp_attachments_avatar_nav', $avatar_nav, $object ), 'order', 'num' ); 705 706 706 // Specific to BuddyPress cover images 707 // Specific to BuddyPress cover images. 707 708 } elseif ( 'bp_cover_image_upload' === $defaults['multipart_params']['action'] ) { 708 709 … … 710 711 $defaults['multi_selection'] = false; 711 712 712 // Default cover component is xprofile 713 // Default cover component is xprofile. 713 714 $cover_component = 'xprofile'; 714 715 715 // Get the object we're editing the cover image of 716 // Get the object we're editing the cover image of. 716 717 $object = $defaults['multipart_params']['bp_params']['object']; 717 718 718 // Set the cover component according to the object 719 // Set the cover component according to the object. 719 720 if ( 'group' === $object ) { 720 721 $cover_component = 'groups'; … … 722 723 $cover_component = apply_filters( 'bp_attachments_cover_image_ui_component', $cover_component ); 723 724 } 724 // Get cover image advised dimensions 725 // Get cover image advised dimensions. 725 726 $cover_dimensions = bp_attachments_get_cover_image_dimensions( $cover_component ); 726 727 727 // Set warning messages 728 // Set warning messages. 728 729 $strings['cover_image_warnings'] = apply_filters( 'bp_attachments_cover_image_ui_warnings', array( 729 730 'dimensions' => sprintf( … … 735 736 } 736 737 737 // Set Plupload settings 738 // Set Plupload settings. 738 739 $settings['defaults'] = $defaults; 739 740 … … 783 784 * Check the current user's capability to edit an avatar for a given object. 784 785 * 785 * @since 2.3.0 786 * 787 * @param string $capability The capability to check. 788 * @param array $args An array containing the item_id and the object to check. 789 * 786 * @since 2.3.0 787 * 788 * @param string $capability The capability to check. 789 * @param array $args An array containing the item_id and the object to check. 790 790 * @return bool 791 791 */ … … 798 798 */ 799 799 if ( isset( $args['item_id'] ) && isset( $args['object'] ) ) { 800 // Group profile photo 800 // Group profile photo. 801 801 if ( bp_is_active( 'groups' ) && 'group' === $args['object'] ) { 802 802 if ( bp_is_group_create() ) { … … 805 805 $can = (bool) groups_is_user_admin( bp_loggedin_user_id(), $args['item_id'] ) || bp_current_user_can( 'bp_moderate' ); 806 806 } 807 // User profile photo 807 // User profile photo. 808 808 } elseif ( bp_is_active( 'xprofile' ) && 'user' === $args['object'] ) { 809 809 $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can( 'bp_moderate' ); … … 828 828 * Send a JSON response back to an Ajax upload request. 829 829 * 830 * @since 831 * 832 * @param 833 * @param 834 * @param 830 * @since 2.3.0 831 * 832 * @param bool $success True for a success, false otherwise. 833 * @param bool $is_html4 True if the Plupload runtime used is html4, false otherwise. 834 * @param mixed $data Data to encode as JSON, then print and die. 835 835 */ 836 836 function bp_attachments_json_response( $success, $is_html4 = false, $data = null ) { … … 841 841 } 842 842 843 // Send regular json response 843 // Send regular json response. 844 844 if ( ! $is_html4 ) { 845 845 wp_send_json( $response ); … … 863 863 * 864 864 * @param string $slug Template part slug. eg 'uploader' for 'uploader.php'. 865 *866 865 * @return bool 867 866 */ … … 892 891 * Get the cover image settings 893 892 * 894 * @since 895 * 896 * @param string $component the component to get the settings for ("xprofile" for user or "groups")897 * @return array the cover image settings893 * @since 2.4.0 894 * 895 * @param string $component The component to get the settings for ("xprofile" for user or "groups"). 896 * @return array The cover image settings. 898 897 */ 899 898 function bp_attachments_get_cover_image_settings( $component = 'xprofile' ) { 900 // Default parameters 899 // Default parameters. 901 900 $args = array(); 902 901 903 // First look in BP Theme Compat 902 // First look in BP Theme Compat. 904 903 $cover_image = bp_get_theme_compat_feature( 'cover_image' ); 905 904 … … 911 910 * Then let people override/set the feature using this dynamic filter 912 911 * 913 * eg: for the user's profile cover image use:912 * Eg: for the user's profile cover image use: 914 913 * add_filter( 'bp_before_xprofile_cover_image_settings_parse_args', 'your_filter', 10, 1 ); 915 914 * 916 915 * @since 2.4.0 917 916 * 918 * @param array $settings the cover image settings917 * @param array $settings The cover image settings 919 918 */ 920 919 $settings = bp_parse_args( $args, array( … … 931 930 } 932 931 933 // Current component is not supported 932 // Current component is not supported. 934 933 if ( ! in_array( $component, $settings['components'] ) ) { 935 934 return false; 936 935 } 937 936 938 // Finally return the settings 937 // Finally return the settings. 939 938 return $settings; 940 939 } … … 943 942 * Get cover image Width and Height 944 943 * 945 * @since 946 * 947 * @param string $component the BuddyPress component concerned ("xprofile" for user or "groups")948 * @return array an associative array containing the advised width and height for the cover image944 * @since 2.4.0 945 * 946 * @param string $component The BuddyPress component concerned ("xprofile" for user or "groups"). 947 * @return array An associative array containing the advised width and height for the cover image. 949 948 */ 950 949 function bp_attachments_get_cover_image_dimensions( $component = 'xprofile' ) { 951 // Let's prevent notices when setting the warning strings 950 // Let's prevent notices when setting the warning strings. 952 951 $default = array( 'width' => 0, 'height' => 0 ); 953 952 … … 958 957 } 959 958 960 // Get width and height 959 // Get width and height. 961 960 $wh = array_intersect_key( $settings, $default ); 962 961 … … 964 963 * Filter here to edit the cover image dimensions if needed. 965 964 * 966 * @since 967 * 968 * @param array $wh an associative array containing the width and height values969 * @param array $settings an associative array containing all the feature settings970 * @param string $compnent the requested component965 * @since 2.4.0 966 * 967 * @param array $wh An associative array containing the width and height values. 968 * @param array $settings An associative array containing all the feature settings. 969 * @param string $compnent The requested component. 971 970 */ 972 971 return apply_filters( 'bp_attachments_get_cover_image_dimensions', $wh, $settings, $component ); … … 974 973 975 974 /** 976 * Are we on a page to edit a cover image 977 * 978 * @since 979 * 980 * @return bool True if on a page to edit a cover image, false otherwise 975 * Are we on a page to edit a cover image? 976 * 977 * @since 2.4.0 978 * 979 * @return bool True if on a page to edit a cover image, false otherwise. 981 980 */ 982 981 function bp_attachments_cover_image_is_edit() { … … 1005 1004 1006 1005 /** 1007 * Does the user has a cover image 1008 * 1009 * @since 1010 * 1011 * @param int $user_id1012 * @return bool True if the user has a cover image, false otherwise 1006 * Does the user has a cover image? 1007 * 1008 * @since 2.4.0 1009 * 1010 * @param int $user_id User ID to retrieve cover image for. 1011 * @return bool True if the user has a cover image, false otherwise. 1013 1012 */ 1014 1013 function bp_attachments_get_user_has_cover_image( $user_id = 0 ) { … … 1025 1024 1026 1025 /** 1027 * Does the group has a cover image 1028 * 1029 * @since 1030 * 1031 * @param int $group_id1032 * @return bool True if the group has a cover image, false otherwise 1026 * Does the group has a cover image? 1027 * 1028 * @since 2.4.0 1029 * 1030 * @param int $group_id Group ID to check cover image existence for. 1031 * @return bool True if the group has a cover image, false otherwise. 1033 1032 */ 1034 1033 function bp_attachments_get_group_has_cover_image( $group_id = 0 ) { … … 1050 1049 * @since 2.4.0 1051 1050 * 1052 * @param array$args {1051 * @param array $args { 1053 1052 * @type string $file The absolute path to the image. Required. 1054 1053 * @type string $component The component for the object (eg: groups, xprofile). Required. 1055 1054 * @type string $cover_image_dir The Cover image dir to write the image into. Required. 1056 1055 * } 1057 * @param 1058 * @return bool|array 1056 * @param BP_Attachment_Cover_Image $cover_image_class The class to use to fit the cover image. 1057 * @return bool|array An array containing cover image data on success, false otherwise. 1059 1058 */ 1060 1059 function bp_attachments_cover_image_generate_file( $args = array(), $cover_image_class = null ) { 1061 // Bail if an argument is missing 1060 // Bail if an argument is missing. 1062 1061 if ( empty( $args['file'] ) || empty( $args['component'] ) || empty( $args['cover_image_dir'] ) ) { 1063 1062 return false; 1064 1063 } 1065 1064 1066 // Get advised dimensions for the cover image 1065 // Get advised dimensions for the cover image. 1067 1066 $dimensions = bp_attachments_get_cover_image_dimensions( $args['component'] ); 1068 1067 … … 1081 1080 } 1082 1081 1083 // Resize the image so that it fit with the cover image dimensions 1082 // Resize the image so that it fit with the cover image dimensions. 1084 1083 $cover_image = $cover_image_class->fit( $args['file'], $dimensions ); 1085 1084 $is_too_small = false; 1086 1085 1087 // Image is too small in width and height 1086 // Image is too small in width and height. 1088 1087 if ( empty( $cover_image ) ) { 1089 1088 $cover_file = $cover_image_class->generate_filename( $args['file'] ); … … 1095 1094 $cover_file = $cover_image['path']; 1096 1095 1097 // Image is too small in width or height 1096 // Image is too small in width or height. 1098 1097 if ( $cover_image['width'] < $dimensions['width'] || $cover_image['height'] < $dimensions['height'] ) { 1099 1098 $is_too_small = true; … … 1111 1110 if ( $att_dir = opendir( $args['cover_image_dir'] ) ) { 1112 1111 while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) { 1113 // skip directories and the new cover image1112 // Skip directories and the new cover image. 1114 1113 if ( 2 < strlen( $attachment_file ) && 0 !== strpos( $attachment_file, '.' ) && $cover_basename !== $attachment_file ) { 1115 1114 @unlink( $args['cover_image_dir'] . '/' . $attachment_file ); … … 1129 1128 * Ajax Upload and set a cover image 1130 1129 * 1131 * @since 1132 * 1133 * @return 1134 * 1130 * @since 2.4.0 1131 * 1132 * @return string|null A json object containing success data if the upload succeeded 1133 * error message otherwise. 1135 1134 */ 1136 1135 function bp_attachments_cover_image_ajax_upload() { 1137 // Bail if not a POST action 1136 // Bail if not a POST action. 1138 1137 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 1139 1138 wp_die(); … … 1149 1148 } 1150 1149 1151 // Check the nonce 1150 // Check the nonce. 1152 1151 check_admin_referer( 'bp-uploader' ); 1153 1152 1154 // Init the BuddyPress parameters 1153 // Init the BuddyPress parameters. 1155 1154 $bp_params = array(); 1156 1155 1157 // We need it to carry on 1156 // We need it to carry on. 1158 1157 if ( ! empty( $_POST['bp_params'] ) ) { 1159 1158 $bp_params = bp_parse_args( $_POST['bp_params'], array( … … 1165 1164 } 1166 1165 1167 // We need the object to set the uploads dir filter 1166 // We need the object to set the uploads dir filter. 1168 1167 if ( empty( $bp_params['object'] ) ) { 1169 1168 bp_attachments_json_response( false, $is_html4 ); 1170 1169 } 1171 1170 1172 // Capability check 1171 // Capability check. 1173 1172 if ( ! bp_attachments_current_user_can( 'edit_cover_image', $bp_params ) ) { 1174 1173 bp_attachments_json_response( false, $is_html4 ); … … 1178 1177 $needs_reset = array(); 1179 1178 1180 // Member's cover image 1179 // Member's cover image. 1181 1180 if ( 'user' === $bp_params['object'] ) { 1182 1181 $object_data = array( 'dir' => 'members', 'component' => 'xprofile' ); … … 1187 1186 } 1188 1187 1189 // Group's cover image 1188 // Group's cover image. 1190 1189 } elseif ( 'group' === $bp_params['object'] ) { 1191 1190 $object_data = array( 'dir' => 'groups', 'component' => 'groups' ); … … 1199 1198 } 1200 1199 1201 // Other object's cover image 1200 // Other object's cover image. 1202 1201 } else { 1203 1202 $object_data = apply_filters( 'bp_attachments_cover_image_object_dir', array(), $bp_params['object'] ); 1204 1203 } 1205 1204 1206 // Stop here in case of a missing parameter for the object 1205 // Stop here in case of a missing parameter for the object. 1207 1206 if ( empty( $object_data['dir'] ) || empty( $object_data['component'] ) ) { 1208 1207 bp_attachments_json_response( false, $is_html4 ); … … 1212 1211 $uploaded = $cover_image_attachment->upload( $_FILES ); 1213 1212 1214 // Reset objects 1213 // Reset objects. 1215 1214 if ( ! empty( $needs_reset ) ) { 1216 1215 if ( ! empty( $needs_reset['component'] ) ) { … … 1222 1221 1223 1222 if ( ! empty( $uploaded['error'] ) ) { 1224 // Upload error response 1223 // Upload error response. 1225 1224 bp_attachments_json_response( false, $is_html4, array( 1226 1225 'type' => 'upload_error', … … 1229 1228 } 1230 1229 1231 // Default error message 1230 // Default error message. 1232 1231 $error_message = __( 'There was a problem uploading the cover image.', 'buddypress' ); 1233 1232 1234 // Get BuddyPress Attachments Uploads Dir datas 1233 // Get BuddyPress Attachments Uploads Dir datas. 1235 1234 $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get(); 1236 1235 … … 1239 1238 1240 1239 if ( ! is_dir( $cover_dir ) ) { 1241 // Upload error response 1240 // Upload error response. 1242 1241 bp_attachments_json_response( false, $is_html4, array( 1243 1242 'type' => 'upload_error', … … 1260 1259 1261 1260 if ( ! $cover ) { 1262 // Upload error response 1261 // Upload error response. 1263 1262 bp_attachments_json_response( false, $is_html4, array( 1264 1263 'type' => 'upload_error', … … 1267 1266 } 1268 1267 1269 // Build the url to the file 1268 // Build the url to the file. 1270 1269 $cover_url = trailingslashit( $bp_attachments_uploads_dir['baseurl'] ) . $cover_subdir . '/' . $cover['cover_basename']; 1271 1270 1272 // Init Feedback code, 1 is success 1271 // Init Feedback code, 1 is success. 1273 1272 $feedback_code = 1; 1274 1273 1275 // 0 is the size warning 1274 // 0 is the size warning. 1276 1275 if ( $cover['is_too_small'] ) { 1277 1276 $feedback_code = 0; 1278 1277 } 1279 1278 1280 // Set the name of the file 1279 // Set the name of the file. 1281 1280 $name = $_FILES['file']['name']; 1282 1281 $name_parts = pathinfo( $name ); … … 1297 1296 do_action( $object_data['component'] . '_cover_image_uploaded', (int) $bp_params['item_id'] ); 1298 1297 1299 // Finally return the cover image url to the UI 1298 // Finally return the cover image url to the UI. 1300 1299 bp_attachments_json_response( true, $is_html4, array( 1301 1300 'name' => $name, … … 1326 1325 } 1327 1326 1328 // Check the nonce 1327 // Check the nonce. 1329 1328 check_admin_referer( 'bp_delete_cover_image', 'nonce' ); 1330 1329 1331 // Capability check 1330 // Capability check. 1332 1331 if ( ! bp_attachments_current_user_can( 'edit_cover_image', $cover_image_data ) ) { 1333 1332 wp_send_json_error(); 1334 1333 } 1335 1334 1336 // Set object for the user's case 1335 // Set object for the user's case. 1337 1336 if ( 'user' === $cover_image_data['object'] ) { 1338 1337 $component = 'xprofile'; 1339 1338 $dir = 'members'; 1340 1339 1341 // Set it for any other cases 1340 // Set it for any other cases. 1342 1341 } else { 1343 1342 $component = $cover_image_data['object'] . 's'; … … 1345 1344 } 1346 1345 1347 // Handle delete 1346 // Handle delete. 1348 1347 if ( bp_attachments_delete_file( array( 'item_id' => $cover_image_data['item_id'], 'object_dir' => $dir, 'type' => 'cover-image' ) ) ) { 1349 1348 1350 // Defaults no cover image 1349 // Defaults no cover image. 1351 1350 $response = array( 1352 1351 'reset_url' => '', … … 1354 1353 ); 1355 1354 1356 // Get cover image settings in case there's a default header 1355 // Get cover image settings in case there's a default header. 1357 1356 $cover_params = bp_attachments_get_cover_image_settings( $component ); 1358 1357 1359 // Check if there's a default cover 1358 // Check if there's a default cover. 1360 1359 if ( ! empty( $cover_params['default_cover'] ) ) { 1361 1360 $response['reset_url'] = $cover_params['default_cover']; 1362 1361 } 1363 1362 1364 // Finally send the reset url 1363 // Finally send the reset url. 1365 1364 wp_send_json_success( $response ); 1366 1365 -
trunk/src/bp-core/bp-core-avatars.php
r10287 r10356 54 54 $bp->avatar->full = new stdClass; 55 55 56 // Dimensions 56 // Dimensions. 57 57 $bp->avatar->thumb->width = BP_AVATAR_THUMB_WIDTH; 58 58 $bp->avatar->thumb->height = BP_AVATAR_THUMB_HEIGHT; … … 60 60 $bp->avatar->full->height = BP_AVATAR_FULL_HEIGHT; 61 61 62 // Upload maximums 62 // Upload maximums. 63 63 $bp->avatar->original_max_width = BP_AVATAR_ORIGINAL_MAX_WIDTH; 64 64 $bp->avatar->original_max_filesize = BP_AVATAR_ORIGINAL_MAX_FILESIZE; 65 65 66 // Defaults 66 // Defaults. 67 67 $bp->avatar->thumb->default = bp_core_avatar_default_thumb(); 68 68 $bp->avatar->full->default = bp_core_avatar_default(); 69 69 70 // These have to be set on page load in order to avoid infinite filter loops at runtime 70 // These have to be set on page load in order to avoid infinite filter loops at runtime. 71 71 $bp->avatar->upload_path = bp_core_avatar_upload_path(); 72 72 $bp->avatar->url = bp_core_avatar_url(); 73 73 74 74 // Cache the root blog's show_avatars setting, to avoid unnecessary 75 // calls to switch_to_blog() 75 // calls to switch_to_blog(). 76 76 $bp->avatar->show_avatars = (bool) BP_SHOW_AVATARS; 77 77 78 // Backpat for pre-1.5 78 // Backpat for pre-1.5. 79 79 if ( ! defined( 'BP_AVATAR_UPLOAD_PATH' ) ) 80 80 define( 'BP_AVATAR_UPLOAD_PATH', $bp->avatar->upload_path ); 81 81 82 // Backpat for pre-1.5 82 // Backpat for pre-1.5. 83 83 if ( ! defined( 'BP_AVATAR_URL' ) ) 84 84 define( 'BP_AVATAR_URL', $bp->avatar->url ); … … 184 184 * image regardless if the Gravatar exists. Default: false. 185 185 * } 186 *187 186 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg. 188 187 */ … … 190 189 $bp = buddypress(); 191 190 192 // If avatars are disabled for the root site, obey that request and bail 191 // If avatars are disabled for the root site, obey that request and bail. 193 192 if ( ! $bp->avatar->show_avatars ) { 194 193 return; … … 218 217 ) ); 219 218 220 /* *Set item_id ***********************************************************/219 /* Set item_id ***********************************************************/ 221 220 222 221 if ( empty( $params['item_id'] ) ) { … … 259 258 } 260 259 261 /* *Set avatar_dir ********************************************************/260 /* Set avatar_dir ********************************************************/ 262 261 263 262 if ( empty( $params['avatar_dir'] ) ) { … … 300 299 } 301 300 302 /* *<img> alt *************************************************************/301 /* <img> alt *************************************************************/ 303 302 304 303 if ( false !== strpos( $params['alt'], '%s' ) || false !== strpos( $params['alt'], '%1$s' ) ) { … … 334 333 } 335 334 336 /* *Sanity Checks *********************************************************/335 /* Sanity Checks *********************************************************/ 337 336 338 337 // Get a fallback for the 'alt' parameter, create html output. … … 361 360 } 362 361 363 // Extra attributes 362 // Extra attributes. 364 363 $extra_attr = ! empty( $args['extra_attr'] ) ? ' ' . $args['extra_attr'] : ''; 365 364 … … 383 382 } 384 383 385 // Set image width 384 // Set image width. 386 385 if ( false !== $params['width'] ) { 387 386 // Width has been specified. No modification necessary. … … 393 392 $html_width = ' width="' . $params['width'] . '"'; 394 393 395 // Set image height 394 // Set image height. 396 395 if ( false !== $params['height'] ) { 397 396 // Height has been specified. No modification necessary. … … 415 414 $params['class'] = apply_filters( 'bp_core_avatar_class', $params['class'], $params['item_id'], $params['object'], $params ); 416 415 417 // Use an alias to leave the param unchanged 416 // Use an alias to leave the param unchanged. 418 417 $avatar_classes = $params['class']; 419 418 if ( ! is_array( $avatar_classes ) ) { … … 421 420 } 422 421 423 // merge classes422 // Merge classes. 424 423 $avatar_classes = array_merge( $avatar_classes, array( 425 424 $params['object'] . '-' . $params['item_id'] . '-avatar', … … 427 426 ) ); 428 427 429 // Sanitize each class 428 // Sanitize each class. 430 429 $avatar_classes = array_map( 'sanitize_html_class', $avatar_classes ); 431 430 432 // populate the class attribute431 // Populate the class attribute. 433 432 $html_class = ' class="' . join( ' ', $avatar_classes ) . ' photo"'; 434 433 435 // Set img URL and DIR based on prepopulated constants 434 // Set img URL and DIR based on prepopulated constants. 436 435 $avatar_loc = new stdClass(); 437 436 $avatar_loc->path = trailingslashit( bp_core_avatar_upload_path() ); … … 473 472 $legacy_group_avatar_name = ( 'full' == $params['type'] ) ? '-groupavatar-full' : '-groupavatar-thumb'; 474 473 475 // Check for directory 474 // Check for directory. 476 475 if ( file_exists( $avatar_folder_dir ) ) { 477 476 478 // Open directory 477 // Open directory. 479 478 if ( $av_dir = opendir( $avatar_folder_dir ) ) { 480 479 481 // Stash files in an array once to check for one that matches 480 // Stash files in an array once to check for one that matches. 482 481 $avatar_files = array(); 483 482 while ( false !== ( $avatar_file = readdir( $av_dir ) ) ) { 484 // Only add files to the array (skip directories) 483 // Only add files to the array (skip directories). 485 484 if ( 2 < strlen( $avatar_file ) ) { 486 485 $avatar_files[] = $avatar_file; … … 488 487 } 489 488 490 // Check for array 489 // Check for array. 491 490 if ( 0 < count( $avatar_files ) ) { 492 491 493 // Check for current avatar 492 // Check for current avatar. 494 493 foreach( $avatar_files as $key => $value ) { 495 494 if ( strpos ( $value, $avatar_size )!== false ) { … … 498 497 } 499 498 500 // Legacy avatar check 499 // Legacy avatar check. 501 500 if ( !isset( $avatar_url ) ) { 502 501 foreach( $avatar_files as $key => $value ) { … … 506 505 } 507 506 508 // Legacy group avatar check 507 // Legacy group avatar check. 509 508 if ( !isset( $avatar_url ) ) { 510 509 foreach( $avatar_files as $key => $value ) { … … 518 517 } 519 518 520 // Close the avatar directory 519 // Close the avatar directory. 521 520 closedir( $av_dir ); 522 521 523 // If we found a locally uploaded avatar 522 // If we found a locally uploaded avatar. 524 523 if ( isset( $avatar_url ) ) { 525 // Support custom scheme 524 // Support custom scheme. 526 525 $avatar_url = set_url_scheme( $avatar_url, $params['scheme'] ); 527 526 528 // Return it wrapped in an <img> element 527 // Return it wrapped in an <img> element. 529 528 if ( true === $params['html'] ) { 530 529 … … 572 571 if ( ! apply_filters( 'bp_core_fetch_avatar_no_grav', $params['no_grav'], $params ) ) { 573 572 574 // Set gravatar type 573 // Set gravatar type. 575 574 if ( empty( $bp->grav_default->{$params['object']} ) ) { 576 575 $default_grav = 'wavatar'; … … 590 589 } 591 590 592 // Set gravatar object 591 // Set gravatar object. 593 592 if ( empty( $params['email'] ) ) { 594 593 if ( 'user' == $params['object'] ) { … … 619 618 $gravatar = apply_filters( 'bp_gravatar_url', '//www.gravatar.com/avatar/' ); 620 619 621 // Append email hash to Gravatar 620 // Append email hash to Gravatar. 622 621 $gravatar .= md5( strtolower( $params['email'] ) ); 623 622 624 // Main Gravatar URL args 623 // Main Gravatar URL args. 625 624 $url_args = array( 626 625 'd' => $default_grav, … … 628 627 ); 629 628 630 // Custom Gravatar URL args 629 // Custom Gravatar URL args. 631 630 if ( ! empty( $params['force_default'] ) ) { 632 631 $url_args['f'] = 'y'; … … 636 635 } 637 636 638 // Set up the Gravatar URL 637 // Set up the Gravatar URL. 639 638 $gravatar = esc_url( add_query_arg( 640 639 rawurlencode_deep( array_filter( $url_args ) ), … … 689 688 $defaults = array( 690 689 'item_id' => false, 691 'object' => 'user', // user OR group OR blog OR custom type (if you use filters)690 'object' => 'user', // User OR group OR blog OR custom type (if you use filters). 692 691 'avatar_dir' => false 693 692 ); … … 777 776 } 778 777 779 // Check the nonce 778 // Check the nonce. 780 779 check_admin_referer( $nonce, 'nonce' ); 781 780 782 // Capability check 781 // Capability check. 783 782 if ( ! bp_attachments_current_user_can( 'edit_avatar', $avatar_data ) ) { 784 783 wp_send_json_error(); 785 784 } 786 785 787 // Handle delete 786 // Handle delete. 788 787 if ( bp_core_delete_existing_avatar( array( 'item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'] ) ) ) { 789 788 $return = array( … … 821 820 * @param array $file The appropriate entry the from $_FILES superglobal. 822 821 * @param string $upload_dir_filter A filter to be applied to 'upload_dir'. 823 *824 822 * @return bool True on success, false on failure. 825 823 */ … … 855 853 } 856 854 857 // The Avatar UI available width 855 // The Avatar UI available width. 858 856 $ui_available_width = 0; 859 857 860 // Try to set the ui_available_width using the avatar_admin global 858 // Try to set the ui_available_width using the avatar_admin global. 861 859 if ( isset( $bp->avatar_admin->ui_available_width ) ) { 862 860 $ui_available_width = $bp->avatar_admin->ui_available_width; … … 903 901 */ 904 902 function bp_avatar_ajax_upload() { 905 // Bail if not a POST action 903 // Bail if not a POST action. 906 904 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 907 905 wp_die(); … … 917 915 } 918 916 919 // Check the nonce 917 // Check the nonce. 920 918 check_admin_referer( 'bp-uploader' ); 921 919 922 // Init the BuddyPress parameters 920 // Init the BuddyPress parameters. 923 921 $bp_params = array(); 924 922 925 // We need it to carry on 923 // We need it to carry on. 926 924 if ( ! empty( $_POST['bp_params' ] ) ) { 927 925 $bp_params = $_POST['bp_params' ]; … … 930 928 } 931 929 932 // We need the object to set the uploads dir filter 930 // We need the object to set the uploads dir filter. 933 931 if ( empty( $bp_params['object'] ) ) { 934 932 bp_attachments_json_response( false, $is_html4 ); 935 933 } 936 934 937 // Capability check 935 // Capability check. 938 936 if ( ! bp_attachments_current_user_can( 'edit_avatar', $bp_params ) ) { 939 937 bp_attachments_json_response( false, $is_html4 ); … … 984 982 } 985 983 986 // Upload the avatar 984 // Upload the avatar. 987 985 $avatar = bp_core_avatar_handle_upload( $_FILES, $bp_params['upload_dir_filter'] ); 988 986 989 // Reset objects 987 // Reset objects. 990 988 if ( ! empty( $needs_reset ) ) { 991 989 if ( ! empty( $needs_reset['component'] ) ) { … … 996 994 } 997 995 998 // Init the feedback message 996 // Init the feedback message. 999 997 $feedback_message = false; 1000 998 … … 1010 1008 1011 1009 if ( empty( $avatar ) ) { 1012 // Default upload error 1010 // Default upload error. 1013 1011 $message = __( 'Upload failed.', 'buddypress' ); 1014 1012 1015 // Use the template message if set 1013 // Use the template message if set. 1016 1014 if ( ! empty( $feedback_message ) ) { 1017 1015 $message = $feedback_message; 1018 1016 } 1019 1017 1020 // Upload error reply 1018 // Upload error reply. 1021 1019 bp_attachments_json_response( false, $is_html4, array( 1022 1020 'type' => 'upload_error', … … 1031 1029 $uploaded_image = @getimagesize( $bp->avatar_admin->image->file ); 1032 1030 1033 // Set the name of the file 1031 // Set the name of the file. 1034 1032 $name = $_FILES['file']['name']; 1035 1033 $name_parts = pathinfo( $name ); 1036 1034 $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) ); 1037 1035 1038 // Finally return the avatar to the editor 1036 // Finally return the avatar to the editor. 1039 1037 bp_attachments_json_response( true, $is_html4, array( 1040 1038 'name' => $name, … … 1054 1052 * @param string $data Base64 encoded image. 1055 1053 * @param int $item_id Item to associate. 1056 *1057 1054 * @return bool True on success, false on failure. 1058 1055 */ … … 1095 1092 $avatar_to_crop = str_replace( bp_core_avatar_upload_path(), '', $original_file ); 1096 1093 1097 // Crop to default values 1094 // Crop to default values. 1098 1095 $crop_args = array( 'item_id' => $item_id, 'original_file' => $avatar_to_crop, 'crop_x' => 0, 'crop_y' => 0 ); 1099 1096 … … 1134 1131 * @type int $crop_y The vertical starting point of the crop. Default: 0. 1135 1132 * } 1136 *1137 1133 * @return bool True on success, false on failure. 1138 1134 */ … … 1164 1160 } 1165 1161 1166 // Crop the file 1162 // Crop the file. 1167 1163 $avatar_attachment = new BP_Attachment_Avatar(); 1168 1164 $cropped = $avatar_attachment->crop( $r ); 1169 1165 1170 // Check for errors 1166 // Check for errors. 1171 1167 if ( empty( $cropped['full'] ) || empty( $cropped['thumb'] ) || is_wp_error( $cropped['full'] ) || is_wp_error( $cropped['thumb'] ) ) { 1172 1168 return false; … … 1185 1181 */ 1186 1182 function bp_avatar_ajax_set() { 1187 // Bail if not a POST action 1183 // Bail if not a POST action. 1188 1184 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 1189 1185 wp_send_json_error(); 1190 1186 } 1191 1187 1192 // Check the nonce 1188 // Check the nonce. 1193 1189 check_admin_referer( 'bp_avatar_cropstore', 'nonce' ); 1194 1190 … … 1204 1200 } 1205 1201 1206 // Capability check 1202 // Capability check. 1207 1203 if ( ! bp_attachments_current_user_can( 'edit_avatar', $avatar_data ) ) { 1208 1204 wp_send_json_error(); … … 1255 1251 $original_file = str_replace( bp_core_avatar_url(), '', $avatar_data['original_file'] ); 1256 1252 1257 // Set avatars dir & feedback part 1253 // Set avatars dir & feedback part. 1258 1254 if ( 'user' === $avatar_data['object'] ) { 1259 1255 $avatar_dir = 'avatars'; 1260 1256 1261 // Defaults to object-avatars dir 1257 // Defaults to object-avatars dir. 1262 1258 } else { 1263 1259 $avatar_dir = sanitize_key( $avatar_data['object'] ) . '-avatars'; 1264 1260 } 1265 1261 1266 // Crop args 1262 // Crop args. 1267 1263 $r = array( 1268 1264 'item_id' => $avatar_data['item_id'], … … 1276 1272 ); 1277 1273 1278 // Handle crop 1274 // Handle crop. 1279 1275 if ( bp_core_avatar_handle_crop( $r ) ) { 1280 1276 $return = array( … … 1326 1322 * @param string $alt Alternate text to use in image tag. Default: ''. 1327 1323 * @param array $args Arguments passed to get_avatar_data(), after processing. 1328 *1329 1324 * @return string BP avatar path, if found; else the original avatar path. 1330 1325 */ … … 1332 1327 global $pagenow; 1333 1328 1334 // Do not filter if inside WordPress options page 1329 // Do not filter if inside WordPress options page. 1335 1330 if ( 'options-discussion.php' == $pagenow ) 1336 1331 return $avatar; 1337 1332 1338 // If passed an object, assume $user->user_id 1333 // If passed an object, assume $user->user_id. 1339 1334 if ( is_object( $user ) ) { 1340 1335 if ( isset( $user->user_id ) ) { … … 1344 1339 } 1345 1340 1346 // If passed a number, assume it was a $user_id 1341 // If passed a number, assume it was a $user_id. 1347 1342 } elseif ( is_numeric( $user ) ) { 1348 1343 $id = $user; 1349 1344 1350 // If passed a string and that string returns a user, get the $id 1345 // If passed a string and that string returns a user, get the $id. 1351 1346 } elseif ( is_string( $user ) && ( $user_by_email = get_user_by( 'email', $user ) ) ) { 1352 1347 $id = $user_by_email->ID; 1353 1348 } 1354 1349 1355 // If somehow $id hasn't been assigned, return the result of get_avatar 1350 // If somehow $id hasn't been assigned, return the result of get_avatar. 1356 1351 if ( empty( $id ) ) { 1357 1352 return !empty( $avatar ) ? $avatar : $default; 1358 1353 } 1359 1354 1360 // Image alt tag 1355 // Image alt tag. 1361 1356 if ( empty( $alt ) ) { 1362 1357 $alt = sprintf( __( 'Profile photo of %s', 'buddypress' ), bp_core_get_user_displayname( $id ) ); … … 1378 1373 ); 1379 1374 1380 // Support new arguments as of WordPress 4.2.0 1375 // Support new arguments as of WordPress 4.2.0. 1381 1376 if ( ! empty( $args['width'] ) ) { 1382 1377 $avatar_args['width'] = $args['width']; … … 1404 1399 } 1405 1400 1406 // Let BuddyPress handle the fetching of the avatar 1401 // Let BuddyPress handle the fetching of the avatar. 1407 1402 $bp_avatar = bp_core_fetch_avatar( $avatar_args ); 1408 1403 1409 // If BuddyPress found an avatar, use it. If not, use the result of get_avatar 1404 // If BuddyPress found an avatar, use it. If not, use the result of get_avatar. 1410 1405 return ( !$bp_avatar ) ? $avatar : $bp_avatar; 1411 1406 } … … 1416 1411 * 1417 1412 * @param array $file The $_FILES array. 1418 *1419 1413 * @return bool True if no errors are found. False if there are errors. 1420 1414 */ … … 1430 1424 * 1431 1425 * @param array $file The $_FILES array. 1432 *1433 1426 * @return bool True if the avatar is under the size limit, otherwise false. 1434 1427 */ … … 1483 1476 * 1484 1477 * @param array $file The $_FILES array. 1485 *1486 1478 * @return bool True if the file extension is permitted, otherwise false. 1487 1479 */ … … 1497 1489 * @param string $type The variable we want to return from the $bp->avatars object. 1498 1490 * Only 'upload_path' and 'url' are supported. Default: 'upload_path'. 1499 *1500 1491 * @return string The avatar upload directory path. 1501 1492 */ … … 1612 1603 * 1613 1604 * @param int $user_id ID of the user whose avatar is being checked. 1614 *1615 1605 * @return bool True if the user has uploaded a local avatar. Otherwise false. 1616 1606 */ … … 1644 1634 * @param string $h_or_w Which dimension is being fetched. 'height' or 'width'. 1645 1635 * Default: 'height'. 1646 *1647 1636 * @return int|bool $dim The dimension. 1648 1637 */ … … 1785 1774 * of the mystery-person, 'gravatar' if the fallback should be 1786 1775 * Gravatar's version. Default: 'gravatar'. 1787 *1788 1776 * @return string The URL of the default avatar. 1789 1777 */ 1790 1778 function bp_core_avatar_default( $type = 'gravatar' ) { 1791 // Local override 1779 // Local override. 1792 1780 if ( defined( 'BP_AVATAR_DEFAULT' ) ) { 1793 1781 $avatar = BP_AVATAR_DEFAULT; 1794 1782 1795 // Use the local default image 1783 // Use the local default image. 1796 1784 } elseif ( 'local' === $type ) { 1797 1785 $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man.jpg'; 1798 1786 1799 // Use Gravatar's mystery person as fallback 1787 // Use Gravatar's mystery person as fallback. 1800 1788 } else { 1801 1789 $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&s=' . bp_core_avatar_full_width(); … … 1823 1811 * of the mystery-person, 'gravatar' if the fallback should be 1824 1812 * Gravatar's version. Default: 'gravatar'. 1825 *1826 1813 * @return string The URL of the default avatar thumb. 1827 1814 */ 1828 1815 function bp_core_avatar_default_thumb( $type = 'gravatar' ) { 1829 // Local override 1816 // Local override. 1830 1817 if ( defined( 'BP_AVATAR_DEFAULT_THUMB' ) ) { 1831 1818 $avatar = BP_AVATAR_DEFAULT_THUMB; 1832 1819 1833 // Use the local default image 1820 // Use the local default image. 1834 1821 } elseif ( 'local' === $type ) { 1835 1822 $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man-50.jpg'; 1836 1823 1837 // Use Gravatar's mystery person as fallback 1824 // Use Gravatar's mystery person as fallback. 1838 1825 } else { 1839 1826 $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&s=' . bp_core_avatar_thumb_width(); … … 1870 1857 $reset_w = false; 1871 1858 1872 // Group's avatar edit screen 1859 // Group's avatar edit screen. 1873 1860 if ( bp_is_group_admin_page() ) { 1874 1861 $reset_w = bp_is_group_admin_screen( 'group-avatar' ); 1875 1862 1876 // Group's avatar create screen 1863 // Group's avatar create screen. 1877 1864 } elseif ( bp_is_group_create() ) { 1878 1865 /** 1879 * we can't use bp_get_groups_current_create_step()1866 * We can't use bp_get_groups_current_create_step(). 1880 1867 * as it's not set yet 1881 1868 */ 1882 1869 $reset_w = 'group-avatar' === bp_action_variable( 1 ); 1883 1870 1884 // User's change avatar screen 1871 // User's change avatar screen. 1885 1872 } else { 1886 1873 $reset_w = bp_is_user_change_avatar(); 1887 1874 } 1888 1875 1889 // A user or a group is cropping an avatar 1876 // A user or a group is cropping an avatar. 1890 1877 if ( true === $reset_w && isset( $_POST['avatar-crop-submit'] ) ) { 1891 1878 $posts_query->set( 'w', 0 ); … … 1914 1901 1915 1902 if ( bp_is_active( 'groups' ) ) { 1916 // Group creation 1903 // Group creation. 1917 1904 if ( bp_is_group_create() && bp_is_group_creation_step( 'group-avatar' ) && 'crop-image' !== bp_get_avatar_admin_step() ) { 1918 1905 $retval = ! bp_disable_group_avatar_uploads(); 1919 1906 1920 // Group Manage 1907 // Group Manage. 1921 1908 } elseif ( bp_is_group_admin_page() && bp_is_group_admin_screen( 'group-avatar' ) && 'crop-image' !== bp_get_avatar_admin_step() ) { 1922 1909 $retval = ! bp_disable_group_avatar_uploads(); … … 1931 1918 * @since 2.3.0 1932 1919 * 1933 * @param bool whetherto load the Avatar UI.1920 * @param bool $retval Whether or not to load the Avatar UI. 1934 1921 */ 1935 1922 return apply_filters( 'bp_avatar_is_front_edit', $retval ); … … 1971 1958 * @since 2.3.0 1972 1959 * 1973 * @param bool whetherto load Webcam Avatar UI part.1960 * @param bool $value Whether or not to load Webcam Avatar UI part. 1974 1961 */ 1975 1962 return apply_filters( 'bp_avatar_use_webcam', true ); -
trunk/src/bp-core/bp-core-buddybar.php
r10326 r10356 34 34 35 35 $defaults = array( 36 'name' => false, // Display name for the nav item 37 'slug' => false, // URL slug for the nav item 38 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 36 'name' => false, // Display name for the nav item. 37 'slug' => false, // URL slug for the nav item. 38 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 39 39 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 40 40 'site_admin_only' => false, // Can only site admins see this nav item? 41 'position' => 99, // Index of where this nav item should be positioned 42 'screen_function' => false, // The name of the function to run when clicked 43 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 41 'position' => 99, // Index of where this nav item should be positioned. 42 'screen_function' => false, // The name of the function to run when clicked. 43 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 44 44 ); 45 45 … … 103 103 104 104 $defaults = array( 105 'name' => false, // Display name for the nav item 106 'slug' => false, // URL slug for the nav item 107 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 105 'name' => false, // Display name for the nav item. 106 'slug' => false, // URL slug for the nav item. 107 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 108 108 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 109 109 'site_admin_only' => false, // Can only site admins see this nav item? 110 'position' => 99, // Index of where this nav item should be positioned 111 'screen_function' => false, // The name of the function to run when clicked 112 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 110 'position' => 99, // Index of where this nav item should be positioned. 111 'screen_function' => false, // The name of the function to run when clicked. 112 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 113 113 ); 114 114 … … 178 178 179 179 $defaults = array( 180 'name' => false, // Display name for the nav item 181 'slug' => false, // URL slug for the nav item 182 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 180 'name' => false, // Display name for the nav item. 181 'slug' => false, // URL slug for the nav item. 182 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 183 183 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 184 184 'site_admin_only' => false, // Can only site admins see this nav item? 185 'position' => 99, // Index of where this nav item should be positioned 186 'screen_function' => false, // The name of the function to run when clicked 187 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 185 'position' => 99, // Index of where this nav item should be positioned. 186 'screen_function' => false, // The name of the function to run when clicked. 187 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 188 188 ); 189 189 … … 221 221 } 222 222 223 // Look for current component 223 // Look for current component. 224 224 if ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) { 225 225 … … 231 231 } elseif ( ! bp_current_action() ) { 232 232 233 // Add our screen hook if screen function is callable 233 // Add our screen hook if screen function is callable. 234 234 if ( is_callable( $r['screen_function'] ) ) { 235 235 add_action( 'bp_screens', $r['screen_function'], 3 ); … … 278 278 279 279 $defaults = array( 280 'parent_slug' => false, // Slug of the parent 281 'screen_function' => false, // The name of the function to run when clicked 282 'subnav_slug' => false // The slug of the subnav item to select when clicked 280 'parent_slug' => false, // Slug of the parent. 281 'screen_function' => false, // The name of the function to run when clicked. 282 'subnav_slug' => false // The slug of the subnav item to select when clicked. 283 283 ); 284 284 … … 286 286 287 287 if ( $function = $bp->bp_nav[$r['parent_slug']]['screen_function'] ) { 288 // Remove our screen hook if screen function is callable 288 // Remove our screen hook if screen function is callable. 289 289 if ( is_callable( $function ) ) { 290 290 remove_action( 'bp_screens', $function, 3 ); … … 297 297 298 298 // The only way to tell whether to set the subnav is to peek at the unfiltered_uri 299 // Find the component 299 // Find the component. 300 300 $component_uri_key = array_search( $r['parent_slug'], $bp->unfiltered_uri ); 301 301 … … 306 306 } 307 307 308 // No subnav item has been requested in the URL, so set a new nav default 308 // No subnav item has been requested in the URL, so set a new nav default. 309 309 if ( empty( $unfiltered_action ) ) { 310 310 if ( ! bp_is_current_action( $r['subnav_slug'] ) ) { … … 318 318 319 319 // The URL is explicitly requesting the new subnav item, but should be 320 // directed to the canonical URL 320 // directed to the canonical URL. 321 321 } elseif ( $unfiltered_action == $r['subnav_slug'] ) { 322 322 unset( $bp->canonical_stack['action'] ); … … 324 324 // In all other cases (including the case where the original subnav item 325 325 // is explicitly called in the URL), the canonical URL will contain the 326 // subnav slug 326 // subnav slug. 327 327 } else { 328 328 $bp->canonical_stack['action'] = bp_current_action(); … … 354 354 $temp[$nav_item['position']] = $nav_item; 355 355 } else { 356 // increase numbers here to fit new items in.356 // Increase numbers here to fit new items in. 357 357 do { 358 358 $nav_item['position']++; … … 444 444 * Default: false. 445 445 * } 446 *447 446 * @return bool|null Returns false on failure. 448 447 */ … … 451 450 452 451 $r = wp_parse_args( $args, array( 453 'name' => false, // Display name for the nav item 454 'slug' => false, // URL slug for the nav item 455 'parent_slug' => false, // URL slug of the parent nav item 456 'parent_url' => false, // URL of the parent item 457 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 452 'name' => false, // Display name for the nav item. 453 'slug' => false, // URL slug for the nav item. 454 'parent_slug' => false, // URL slug of the parent nav item. 455 'parent_url' => false, // URL of the parent item. 456 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 458 457 'user_has_access' => true, // Can the logged in user see this nav item? 459 458 'no_access_url' => '', 460 459 'site_admin_only' => false, // Can only site admins see this nav item? 461 'position' => 90, // Index of where this nav item should be positioned 462 'screen_function' => false, // The name of the function to run when clicked 460 'position' => 90, // Index of where this nav item should be positioned. 461 'screen_function' => false, // The name of the function to run when clicked. 463 462 'link' => '', // The link for the subnav item; optional, not usually required. 464 'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu 463 'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu. 465 464 ) ); 466 465 467 // If we don't have the required info we need, don't create this subnav item 466 // If we don't have the required info we need, don't create this subnav item. 468 467 if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) ) 469 468 return false; 470 469 471 // Link was not forced, so create one 470 // Link was not forced, so create one. 472 471 if ( empty( $r['link'] ) ) { 473 472 $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] ); 474 473 475 // If this sub item is the default for its parent, skip the slug 474 // If this sub item is the default for its parent, skip the slug. 476 475 if ( ! empty( $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) { 477 476 $r['link'] = trailingslashit( $r['parent_url'] ); … … 479 478 } 480 479 481 // If this is for site admins only and the user is not one, don't create the subnav item 480 // If this is for site admins only and the user is not one, don't create the subnav item. 482 481 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 483 482 return false; … … 529 528 * Default: false. 530 529 * } 531 *532 530 * @return bool|null Returns false on failure. 533 531 */ … … 536 534 537 535 $r = wp_parse_args( $args, array( 538 'slug' => false, // URL slug for the screen 539 'parent_slug' => false, // URL slug of the parent screen 536 'slug' => false, // URL slug for the screen. 537 'parent_slug' => false, // URL slug of the parent screen. 540 538 'user_has_access' => true, // Can the user visit this screen? 541 539 'no_access_url' => '', 542 540 'site_admin_only' => false, // Can only site admins visit this screen? 543 'screen_function' => false, // The name of the function to run when clicked 541 'screen_function' => false, // The name of the function to run when clicked. 544 542 ) ); 545 543 … … 550 548 * checking the following two conditions: 551 549 * (1) Either: 552 * 553 * 550 * (a) the parent slug matches the current_component, or 551 * (b) the parent slug matches the current_item 554 552 * (2) And either: 555 * 553 * (a) the current_action matches $slug, or 556 554 * (b) there is no current_action (ie, this is the default subnav for the parent nav) 557 * 558 * 559 * 560 * 555 * and this subnav item is the default for the parent item (which we check by 556 * comparing this subnav item's screen function with the screen function of the 557 * parent nav item in $bp->bp_nav). This condition only arises when viewing a 558 * user, since groups should always have an action set. 561 559 */ 562 560 563 // If we *don't* meet condition (1), return 561 // If we *don't* meet condition (1), return. 564 562 if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) { 565 563 return; 566 564 } 567 565 568 // If we *do* meet condition (2), then the added subnav item is currently being requested 566 // If we *do* meet condition (2), then the added subnav item is currently being requested. 569 567 if ( ( bp_current_action() && bp_is_current_action( $r['slug'] ) ) || ( bp_is_user() && ! bp_current_action() && ( $r['screen_function'] == $bp->bp_nav[$r['parent_slug']]['screen_function'] ) ) ) { 570 568 571 // If this is for site admins only and the user is not one, don't create the subnav item 569 // If this is for site admins only and the user is not one, don't create the subnav item. 572 570 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 573 571 return false; … … 576 574 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $r ); 577 575 578 // If redirect args have been returned, perform the redirect now 576 // If redirect args have been returned, perform the redirect now. 579 577 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { 580 578 bp_core_no_access( $hooked['redirect_args'] ); … … 589 587 * 590 588 * @param array $subnav_item The subnav array added to bp_options_nav in `bp_core_new_subnav_item()`. 591 *592 589 * @return array 593 590 */ … … 603 600 } 604 601 605 // User has access, so let's try to hook the display callback 602 // User has access, so let's try to hook the display callback. 606 603 if ( ! empty( $subnav_item['user_has_access'] ) && ! $site_admin_restricted ) { 607 604 608 // Screen function is invalid 605 // Screen function is invalid. 609 606 if ( ! is_callable( $subnav_item['screen_function'] ) ) { 610 607 $retval['status'] = 'failure'; 611 608 612 // Success - hook to bp_screens 609 // Success - hook to bp_screens. 613 610 } else { 614 611 add_action( 'bp_screens', $subnav_item['screen_function'], 3 ); … … 617 614 618 615 // User doesn't have access. Determine redirect arguments based on 619 // user status 616 // user status. 620 617 } else { 621 618 $retval['status'] = 'failure'; … … 626 623 627 624 // If a redirect URL has been passed to the subnav 628 // item, respect it 625 // item, respect it. 629 626 if ( ! empty( $subnav_item['no_access_url'] ) ) { 630 627 $message = __( 'You do not have access to this page.', 'buddypress' ); … … 632 629 633 630 // In the case of a user page, we try to assume a 634 // redirect URL 631 // redirect URL. 635 632 } elseif ( bp_is_user() ) { 636 633 … … 646 643 // know will be accessible. 647 644 } else { 648 // Try 'activity' first 645 // Try 'activity' first. 649 646 if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 650 647 $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ); 651 // Then try 'profile' 648 // Then try 'profile'. 652 649 } else { 653 650 $redirect_to = trailingslashit( bp_displayed_user_domain() . ( 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id ) ); … … 657 654 } 658 655 659 // Fall back to the home page 656 // Fall back to the home page. 660 657 } else { 661 658 $message = __( 'You do not have access to this page.', 'buddypress' ); … … 672 669 // When the user is logged out, pass an empty array 673 670 // This indicates that the default arguments should be 674 // used in bp_core_no_access() 671 // used in bp_core_no_access(). 675 672 $retval['redirect_args'] = array(); 676 673 } … … 699 696 $temp[$subnav_item['position']] = $subnav_item; 700 697 else { 701 // increase numbers here to fit new items in.698 // Increase numbers here to fit new items in. 702 699 do { 703 700 $subnav_item['position']++; … … 722 719 * @param string $nav_item The slug of the top-level nav item whose subnav items you're checking. 723 720 * Default: the current component slug. 724 *725 721 * @return bool $has_subnav True if the nav item is found and has subnav items; false otherwise. 726 722 */ … … 748 744 * 749 745 * @param int $parent_id The slug of the parent navigation item. 750 *751 746 * @return bool Returns false on failure, ie if the nav item can't be found. 752 747 */ … … 754 749 $bp = buddypress(); 755 750 756 // Unset subnav items for this nav item 751 // Unset subnav items for this nav item. 757 752 if ( isset( $bp->bp_options_nav[$parent_id] ) && is_array( $bp->bp_options_nav[$parent_id] ) ) { 758 753 foreach( (array) $bp->bp_options_nav[$parent_id] as $subnav_item ) { … … 765 760 766 761 if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) { 767 // Remove our screen hook if screen function is callable 762 // Remove our screen hook if screen function is callable. 768 763 if ( is_callable( $function ) ) { 769 764 remove_action( 'bp_screens', $function, 3 ); … … 788 783 789 784 if ( ! empty( $screen_function ) ) { 790 // Remove our screen hook if screen function is callable 785 // Remove our screen hook if screen function is callable. 791 786 if ( is_callable( $screen_function ) ) { 792 787 remove_action( 'bp_screens', $screen_function, 3 ); … … 823 818 * @param string $context Context of this preference check. 'admin' or 'front'. 824 819 * @param int $user Optional. ID of the user to check. Default: 0 (which falls back to the logged-in user's ID). 825 *826 820 * @return bool True if the toolbar should be showing for this user. 827 821 */ -
trunk/src/bp-core/bp-core-cache.php
r10108 r10356 134 134 * @param array $item_ids ID list. 135 135 * @param string $cache_group The cache group to check against. 136 *137 136 * @return array 138 137 */ … … 175 174 * cache key names. Default: the value of $meta_table. 176 175 * } 177 *178 176 * @return array|bool Metadata cache for the specified objects, or false on failure. 179 177 */ … … 182 180 183 181 $defaults = array( 184 'object_ids' => array(), // Comma-separated list or array of item ids 185 'object_type' => '', // Canonical component id: groups, members, etc 186 'cache_group' => '', // Cache group 187 'meta_table' => '', // Name of the table containing the metadata 188 'object_column' => '', // DB column for the object ids (group_id, etc) 189 'cache_key_prefix' => '' // Prefix to use when creating cache key names. Eg 'bp_groups_groupmeta' 182 'object_ids' => array(), // Comma-separated list or array of item ids. 183 'object_type' => '', // Canonical component id: groups, members, etc. 184 'cache_group' => '', // Cache group. 185 'meta_table' => '', // Name of the table containing the metadata. 186 'object_column' => '', // DB column for the object ids (group_id, etc). 187 'cache_key_prefix' => '' // Prefix to use when creating cache key names. Eg 'bp_groups_groupmeta'. 190 188 ); 191 189 $r = wp_parse_args( $args, $defaults ); … … 213 211 $cache = array(); 214 212 215 // Get meta info 213 // Get meta info. 216 214 if ( ! empty( $uncached_ids ) ) { 217 215 $id_list = join( ',', wp_parse_id_list( $uncached_ids ) ); … … 224 222 $mval = $metarow['meta_value']; 225 223 226 // Force subkeys to be array type :224 // Force subkeys to be array type. 227 225 if ( !isset( $cache[$mpid] ) || !is_array( $cache[$mpid] ) ) 228 226 $cache[$mpid] = array(); … … 230 228 $cache[$mpid][$mkey] = array(); 231 229 232 // Add a value to the current pid/key :230 // Add a value to the current pid/key. 233 231 $cache[$mpid][$mkey][] = $mval; 234 232 } … … 236 234 237 235 foreach ( $uncached_ids as $uncached_id ) { 238 // Cache empty values as well 236 // Cache empty values as well. 239 237 if ( ! isset( $cache[ $uncached_id ] ) ) { 240 238 $cache[ $uncached_id ] = array(); -
trunk/src/bp-core/bp-core-caps.php
r10108 r10356 25 25 global $wp_roles; 26 26 27 // Sanity check on roles global variable 27 // Sanity check on roles global variable. 28 28 $roles = isset( $wp_roles->roles ) 29 29 ? $wp_roles->roles … … 64 64 global $wp_roles; 65 65 66 // Load roles if not set 66 // Load roles if not set. 67 67 if ( ! isset( $wp_roles ) ) { 68 68 $wp_roles = new WP_Roles(); 69 69 } 70 70 71 // Loop through available roles and add them 71 // Loop through available roles and add them. 72 72 foreach( $wp_roles->role_objects as $role ) { 73 73 foreach ( bp_get_caps_for_role( $role->name ) as $cap ) { … … 100 100 global $wp_roles; 101 101 102 // Load roles if not set 102 // Load roles if not set. 103 103 if ( ! isset( $wp_roles ) ) { 104 104 $wp_roles = new WP_Roles(); 105 105 } 106 106 107 // Loop through available roles and remove them 107 // Loop through available roles and remove them. 108 108 foreach( $wp_roles->role_objects as $role ) { 109 109 foreach ( bp_get_caps_for_role( $role->name ) as $cap ) { … … 136 136 * @param int $user_id See {@link WP_User::has_cap()}. 137 137 * @param mixed $args See {@link WP_User::has_cap()}. 138 *139 138 * @return array Actual capabilities for meta capability. See {@link WP_User::has_cap()}. 140 139 */ … … 165 164 function bp_get_community_caps() { 166 165 167 // Forum meta caps 166 // Forum meta caps. 168 167 $caps = array(); 169 168 … … 186 185 * 187 186 * @param string $role The role for which you're loading caps. 188 *189 187 * @return array Capabilities for $role. 190 188 */ … … 194 192 switch ( $role ) { 195 193 196 // Administrator 194 // Administrator. 197 195 case 'administrator' : 198 196 $caps = array( 199 // Misc 197 // Misc. 200 198 'bp_moderate', 201 199 ); … … 203 201 break; 204 202 205 // All other default WordPress blog roles 203 // All other default WordPress blog roles. 206 204 case 'editor' : 207 205 case 'author' : … … 243 241 function bp_set_current_user_default_role() { 244 242 245 // Bail if not multisite or not root blog 243 // Bail if not multisite or not root blog. 246 244 if ( ! is_multisite() || ! bp_is_root_blog() ) { 247 245 return; 248 246 } 249 247 250 // Bail if user is not logged in or already a member 248 // Bail if user is not logged in or already a member. 251 249 if ( ! is_user_logged_in() || is_user_member_of_blog() ) { 252 250 return; 253 251 } 254 252 255 // Bail if user is not active 253 // Bail if user is not active. 256 254 if ( bp_is_user_inactive() ) { 257 255 return; 258 256 } 259 257 260 // Set the current users default role 258 // Set the current users default role. 261 259 buddypress()->current_user->set_role( bp_get_option( 'default_role', 'subscriber' ) ); 262 260 } … … 274 272 * @type mixed $a,... Optional. Extra arguments applicable to the capability check. 275 273 * } 276 *277 274 * @return bool True if the user has the cap for the given parameters. 278 275 */ … … 292 289 } 293 290 294 // Use root blog if no ID passed 291 // Use root blog if no ID passed. 295 292 if ( empty( $blog_id ) ) { 296 293 $blog_id = bp_get_root_blog_id(); … … 341 338 * @param int $user_id ID of the user being checked against. 342 339 * @param array $args Miscellaneous arguments passed to the user_has_cap filter. 343 *344 340 * @return array $allcaps The user's cap list, with 'bp_moderate' appended, if relevant. 345 341 */ 346 342 function _bp_enforce_bp_moderate_cap_for_admins( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 347 343 348 // Bail if not checking the 'bp_moderate' cap 344 // Bail if not checking the 'bp_moderate' cap. 349 345 if ( 'bp_moderate' !== $cap ) { 350 346 return $caps; 351 347 } 352 348 353 // Bail if BuddyPress is not network activated 349 // Bail if BuddyPress is not network activated. 354 350 if ( bp_is_network_activated() ) { 355 351 return $caps; 356 352 } 357 353 358 // Never trust inactive users 354 // Never trust inactive users. 359 355 if ( bp_is_user_inactive( $user_id ) ) { 360 356 return $caps; 361 357 } 362 358 363 // Only users that can 'manage_options' on this site can 'bp_moderate' 359 // Only users that can 'manage_options' on this site can 'bp_moderate'. 364 360 return array( 'manage_options' ); 365 361 } -
trunk/src/bp-core/bp-core-catchuri.php
r10212 r10356 35 35 global $current_blog, $wp_rewrite; 36 36 37 // Don't catch URIs on non-root blogs unless multiblog mode is on 37 // Don't catch URIs on non-root blogs unless multiblog mode is on. 38 38 if ( !bp_is_root_blog() && !bp_is_multiblog_mode() ) 39 39 return false; … … 41 41 $bp = buddypress(); 42 42 43 // Define local variables 43 // Define local variables. 44 44 $root_profile = $match = false; 45 45 $key_slugs = $matches = $uri_chunks = array(); 46 46 47 // Fetch all the WP page names for each component 47 // Fetch all the WP page names for each component. 48 48 if ( empty( $bp->pages ) ) 49 49 $bp->pages = bp_core_get_directory_pages(); … … 64 64 $path = apply_filters( 'bp_uri', $path ); 65 65 66 // Take GET variables off the URL to avoid problems 66 // Take GET variables off the URL to avoid problems. 67 67 $path = strtok( $path, '?' ); 68 68 69 // Fetch current URI and explode each part separated by '/' into an array 69 // Fetch current URI and explode each part separated by '/' into an array. 70 70 $bp_uri = explode( '/', $path ); 71 71 72 // Loop and remove empties 72 // Loop and remove empties. 73 73 foreach ( (array) $bp_uri as $key => $uri_chunk ) { 74 74 if ( empty( $bp_uri[$key] ) ) { … … 80 80 // removed from $bp_uri. This includes two cases: 81 81 // 82 // 83 // 84 // 82 // 1. when WP is installed in a subdirectory, 83 // 2. when BP is running on secondary blog of a subdirectory 84 // multisite installation. Phew! 85 85 if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) { 86 86 87 // Blow chunks 87 // Blow chunks. 88 88 $chunks = explode( '/', $current_blog->path ); 89 89 … … 105 105 } 106 106 107 // Get site path items 107 // Get site path items. 108 108 $paths = explode( '/', bp_core_get_site_path() ); 109 109 110 // Take empties off the end of path 110 // Take empties off the end of path. 111 111 if ( empty( $paths[count( $paths ) - 1] ) ) 112 112 array_pop( $paths ); 113 113 114 // Take empties off the start of path 114 // Take empties off the start of path. 115 115 if ( empty( $paths[0] ) ) 116 116 array_shift( $paths ); 117 117 118 // Reset indexes 118 // Reset indexes. 119 119 $bp_uri = array_values( $bp_uri ); 120 120 $paths = array_values( $paths ); 121 121 122 // Unset URI indices if they intersect with the paths 122 // Unset URI indices if they intersect with the paths. 123 123 foreach ( (array) $bp_uri as $key => $uri_chunk ) { 124 124 if ( isset( $paths[$key] ) && $uri_chunk == $paths[$key] ) { … … 127 127 } 128 128 129 // Reset the keys by merging with an empty array 129 // Reset the keys by merging with an empty array. 130 130 $bp_uri = array_merge( array(), $bp_uri ); 131 131 132 132 // If a component is set to the front page, force its name into $bp_uri 133 133 // so that $current_component is populated (unless a specific WP post is being requested 134 // via a URL parameter, usually signifying Preview mode) 134 // via a URL parameter, usually signifying Preview mode). 135 135 if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) && empty( $_GET['p'] ) && empty( $_GET['page_id'] ) ) { 136 136 $post = get_post( get_option( 'page_on_front' ) ); … … 140 140 } 141 141 142 // Keep the unfiltered URI safe 142 // Keep the unfiltered URI safe. 143 143 $bp->unfiltered_uri = $bp_uri; 144 144 … … 146 146 $GLOBALS['bp_unfiltered_uri'] = &$bp->unfiltered_uri; 147 147 148 // Get slugs of pages into array 148 // Get slugs of pages into array. 149 149 foreach ( (array) $bp->pages as $page_key => $bp_page ) 150 150 $key_slugs[$page_key] = trailingslashit( '/' . $bp_page->slug ); 151 151 152 // Bail if keyslugs are empty, as BP is not setup correct 152 // Bail if keyslugs are empty, as BP is not setup correct. 153 153 if ( empty( $key_slugs ) ) 154 154 return; 155 155 156 // Loop through page slugs and look for exact match to path 156 // Loop through page slugs and look for exact match to path. 157 157 foreach ( $key_slugs as $key => $slug ) { 158 158 if ( $slug == $path ) { … … 164 164 } 165 165 166 // No exact match, so look for partials 166 // No exact match, so look for partials. 167 167 if ( empty( $match ) ) { 168 168 169 // Loop through each page in the $bp->pages global 169 // Loop through each page in the $bp->pages global. 170 170 foreach ( (array) $bp->pages as $page_key => $bp_page ) { 171 171 172 // Look for a match (check members first) 172 // Look for a match (check members first). 173 173 if ( in_array( $bp_page->name, (array) $bp_uri ) ) { 174 174 … … 176 176 $uri_chunks = explode( '/', $bp_page->slug ); 177 177 178 // Loop through uri_chunks 178 // Loop through uri_chunks. 179 179 foreach ( (array) $uri_chunks as $key => $uri_chunk ) { 180 180 181 // Make sure chunk is in the correct position 181 // Make sure chunk is in the correct position. 182 182 if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) { 183 183 $matches[] = 1; 184 184 185 // No match 185 // No match. 186 186 } else { 187 187 $matches[] = 0; … … 189 189 } 190 190 191 // Have a match 191 // Have a match. 192 192 if ( !in_array( 0, (array) $matches ) ) { 193 193 $match = $bp_page; … … 196 196 }; 197 197 198 // Unset matches 198 // Unset matches. 199 199 unset( $matches ); 200 200 } 201 201 202 // Unset uri chunks 202 // Unset uri chunks. 203 203 unset( $uri_chunks ); 204 204 } 205 205 } 206 206 207 // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above 207 // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above. 208 208 if ( empty( $matches ) && bp_core_enable_root_profiles() ) { 209 209 210 // Switch field based on compat 210 // Switch field based on compat. 211 211 $field = bp_is_username_compatibility_mode() ? 'login' : 'slug'; 212 212 213 // Make sure there's a user corresponding to $bp_uri[0] 213 // Make sure there's a user corresponding to $bp_uri[0]. 214 214 if ( !empty( $bp->pages->members ) && !empty( $bp_uri[0] ) && $root_profile = get_user_by( $field, $bp_uri[0] ) ) { 215 215 216 // Force BP to recognize that this is a members page 216 // Force BP to recognize that this is a members page. 217 217 $matches[] = 1; 218 218 $match = $bp->pages->members; … … 221 221 } 222 222 223 // Search doesn't have an associated page, so we check for it separately 223 // Search doesn't have an associated page, so we check for it separately. 224 224 if ( !empty( $bp_uri[0] ) && ( bp_get_search_slug() == $bp_uri[0] ) ) { 225 225 $matches[] = 1; … … 235 235 $wp_rewrite->use_verbose_page_rules = false; 236 236 237 // Find the offset. With $root_profile set, we fudge the offset down so later parsing works 237 // Find the offset. With $root_profile set, we fudge the offset down so later parsing works. 238 238 $slug = !empty ( $match ) ? explode( '/', $match->slug ) : ''; 239 239 $uri_offset = empty( $root_profile ) ? 0 : -1; 240 240 241 // Rejig the offset 241 // Rejig the offset. 242 242 if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) { 243 243 // Only offset if not on a root profile. Fixes issue when Members page is nested. … … 249 249 250 250 // Global the unfiltered offset to use in bp_core_load_template(). 251 // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0 251 // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0. 252 252 $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0; 253 253 254 // We have an exact match 254 // We have an exact match. 255 255 if ( isset( $match->key ) ) { 256 256 257 // Set current component to matched key 257 // Set current component to matched key. 258 258 $bp->current_component = $match->key; 259 259 260 // If members component, do more work to find the actual component 260 // If members component, do more work to find the actual component. 261 261 if ( 'members' == $match->key ) { 262 262 … … 268 268 // Are we viewing a specific user? 269 269 if ( $after_member_slug ) { 270 // If root profile, we've already queried for the user 270 // If root profile, we've already queried for the user. 271 271 if ( $root_profile instanceof WP_User ) { 272 272 $bp->displayed_user->id = $root_profile->ID; 273 273 274 // Switch the displayed_user based on compatibility mode 274 // Switch the displayed_user based on compatibility mode. 275 275 } elseif ( bp_is_username_compatibility_mode() ) { 276 276 $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) ); … … 302 302 } 303 303 304 // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin) 304 // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin). 305 305 if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) { 306 306 if ( bp_current_user_can( 'bp_moderate' ) ) { … … 318 318 $bp->current_component = $bp_uri[0]; 319 319 320 // No component, so default will be picked later 320 // No component, so default will be picked later. 321 321 } else { 322 322 $bp_uri = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) ); … … 324 324 } 325 325 326 // Reset the offset 326 // Reset the offset. 327 327 $uri_offset = 0; 328 328 } … … 347 347 $bp->current_action = $current_action; 348 348 349 // Slice the rest of the $bp_uri array and reset offset 349 // Slice the rest of the $bp_uri array and reset offset. 350 350 $bp_uri = array_slice( $bp_uri, $uri_offset + 2 ); 351 351 $uri_offset = 0; 352 352 353 // Set the entire URI as the action variables, we will unset the current_component and action in a second 353 // Set the entire URI as the action variables, we will unset the current_component and action in a second. 354 354 $bp->action_variables = $bp_uri; 355 355 356 // Reset the keys by merging with an empty array 356 // Reset the keys by merging with an empty array. 357 357 $bp->action_variables = array_merge( array(), $bp->action_variables ); 358 358 } … … 391 391 * 392 392 * @param array $templates Array of templates to attempt to load. 393 *394 * @return bool|null Returns false on failure.395 393 */ 396 394 function bp_core_load_template( $templates ) { 397 395 global $wp_query; 398 396 399 // Reset the post 397 // Reset the post. 400 398 bp_theme_compat_reset_post( array( 401 399 'ID' => 0, … … 405 403 406 404 // Set theme compat to false since the reset post function automatically sets 407 // theme compat to true 405 // theme compat to true. 408 406 bp_set_theme_compat_active( false ); 409 407 410 // Fetch each template and add the php suffix 408 // Fetch each template and add the php suffix. 411 409 $filtered_templates = array(); 412 410 foreach ( (array) $templates as $template ) { … … 414 412 } 415 413 416 // Only perform template lookup for bp-default themes 414 // Only perform template lookup for bp-default themes. 417 415 if ( ! bp_use_theme_compat_with_current_theme() ) { 418 416 $template = locate_template( (array) $filtered_templates, false ); 419 417 420 // Theme compat doesn't require a template lookup 418 // Theme compat doesn't require a template lookup. 421 419 } else { 422 420 $template = ''; … … 471 469 exit(); 472 470 473 // No template found, so setup theme compatibility 474 // @todo Some other 404 handling if theme compat doesn't kick in 471 // No template found, so setup theme compatibility. 472 // @todo Some other 404 handling if theme compat doesn't kick in. 475 473 } else { 476 474 … … 554 552 function bp_core_no_access( $args = '' ) { 555 553 556 // Build the redirect URL 554 // Build the redirect URL. 557 555 $redirect_url = is_ssl() ? 'https://' : 'http://'; 558 556 $redirect_url .= $_SERVER['HTTP_HOST']; … … 578 576 extract( $r, EXTR_SKIP ); 579 577 580 /* *578 /* 581 579 * @ignore Ignore these filters and use 'bp_core_no_access' above 582 580 */ … … 590 588 591 589 // Option to redirect to wp-login.php 592 // Error message is displayed with bp_core_no_access_wp_login_error() 590 // Error message is displayed with bp_core_no_access_wp_login_error(). 593 591 case 2 : 594 592 if ( !empty( $redirect ) ) { … … 601 599 602 600 // Redirect to root with "redirect_to" parameter 603 // Error message is displayed with bp_core_add_message() 601 // Error message is displayed with bp_core_add_message(). 604 602 case 1 : 605 603 default : … … 642 640 $error = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] ); 643 641 644 // shake shake shake!642 // Shake shake shake!. 645 643 add_action( 'login_head', 'wp_shake_js', 12 ); 646 644 } … … 682 680 } 683 681 684 // build the URL in the address bar682 // Build the URL in the address bar. 685 683 $requested_url = bp_get_requested_url(); 686 684 687 // Stash query args 685 // Stash query args. 688 686 $url_stack = explode( '?', $requested_url ); 689 687 $req_url_clean = $url_stack[0]; … … 692 690 $canonical_url = bp_get_canonical_url(); 693 691 694 // Only redirect if we've assembled a URL different from the request 692 // Only redirect if we've assembled a URL different from the request. 695 693 if ( $canonical_url !== $req_url_clean ) { 696 694 … … 698 696 699 697 // Template messages have been deleted from the cookie by this point, so 700 // they must be readded before redirecting 698 // they must be readded before redirecting. 701 699 if ( isset( $bp->template_message ) ) { 702 700 $message = stripslashes( $bp->template_message ); … … 723 721 $canonical_url = bp_get_canonical_url(); 724 722 725 // Output rel=canonical tag 723 // Output rel=canonical tag. 726 724 echo "<link rel='canonical' href='" . esc_attr( $canonical_url ) . "' />\n"; 727 725 } … … 739 737 * in the canonical URL returned from the function. 740 738 * } 741 *742 739 * @return string Canonical URL for the current page. 743 740 */ 744 741 function bp_get_canonical_url( $args = array() ) { 745 742 746 // For non-BP content, return the requested url, and let WP do the work 743 // For non-BP content, return the requested url, and let WP do the work. 747 744 if ( bp_is_blog_page() ) { 748 745 return bp_get_requested_url(); … … 752 749 753 750 $defaults = array( 754 'include_query_args' => false // Include URL arguments, eg ?foo=bar&foo2=bar2 751 'include_query_args' => false // Include URL arguments, eg ?foo=bar&foo2=bar2. 755 752 ); 756 753 $r = wp_parse_args( $args, $defaults ); … … 766 763 // URL is the front page. We detect whether we're detecting a 767 764 // component *directory* by checking that bp_current_action() 768 // is empty - ie, this not a single item or a feed 765 // is empty - ie, this not a single item or a feed. 769 766 if ( false !== $front_page_component && bp_is_current_component( $front_page_component ) && ! bp_current_action() ) { 770 767 $bp->canonical_stack['canonical_url'] = trailingslashit( bp_get_root_domain() ); … … 772 769 // Except when the front page is set to the registration page 773 770 // and the current user is logged in. In this case we send to 774 // the members directory to avoid redirect loops 771 // the members directory to avoid redirect loops. 775 772 } elseif ( bp_is_register_page() && 'register' == $front_page_component && is_user_logged_in() ) { 776 773 … … 787 784 788 785 if ( empty( $bp->canonical_stack['canonical_url'] ) ) { 789 // Build the URL in the address bar 786 // Build the URL in the address bar. 790 787 $requested_url = bp_get_requested_url(); 791 788 792 // Stash query args 789 // Stash query args. 793 790 $url_stack = explode( '?', $requested_url ); 794 791 795 // Build the canonical URL out of the redirect stack 792 // Build the canonical URL out of the redirect stack. 796 793 if ( isset( $bp->canonical_stack['base_url'] ) ) 797 794 $url_stack[0] = $bp->canonical_stack['base_url']; … … 809 806 } 810 807 811 // Add trailing slash 808 // Add trailing slash. 812 809 $url_stack[0] = trailingslashit( $url_stack[0] ); 813 810 814 // Stash in the $bp global 811 // Stash in the $bp global. 815 812 $bp->canonical_stack['canonical_url'] = implode( '?', $url_stack ); 816 813 } -
trunk/src/bp-core/bp-core-component.php
r10110 r10356 19 19 * internally by BuddyPress to create the bundled components, but can be 20 20 * extended to create other really neat things. 21 *22 * @package BuddyPress23 * @subpackage Component24 21 * 25 22 * @since 1.5.0 … … 161 158 public function start( $id = '', $name = '', $path = '', $params = array() ) { 162 159 163 // Internal identifier of component 160 // Internal identifier of component. 164 161 $this->id = $id; 165 162 166 // Internal component name 163 // Internal component name. 167 164 $this->name = $name; 168 165 169 // Path for includes 166 // Path for includes. 170 167 $this->path = $path; 171 168 172 // Miscellaneous component parameters that need to be set early on 169 // Miscellaneous component parameters that need to be set early on. 173 170 if ( ! empty( $params ) ) { 174 // Sets the position for our menu under the WP Toolbar's "My Account" menu 171 // Sets the position for our menu under the WP Toolbar's "My Account" menu. 175 172 if ( ! empty( $params['adminbar_myaccount_order'] ) ) { 176 173 $this->adminbar_myaccount_order = (int) $params['adminbar_myaccount_order']; 177 174 } 178 175 179 // Register features 176 // Register features. 180 177 if ( ! empty( $params['features'] ) ) { 181 178 $this->features = array_map( 'sanitize_title', (array) $params['features'] ); … … 186 183 } 187 184 188 // Set defaults if not passed 185 // Set defaults if not passed. 189 186 } else { 190 // new component menus are added before the settings menu if not set187 // New component menus are added before the settings menu if not set. 191 188 $this->adminbar_myaccount_order = 90; 192 189 } 193 190 194 // Move on to the next step 191 // Move on to the next step. 195 192 $this->setup_actions(); 196 193 } … … 222 219 public function setup_globals( $args = array() ) { 223 220 224 /** Slugs *************************************************************/ 221 /** Slugs ************************************************************ 222 */ 225 223 226 224 // If a WP directory page exists for the component, it should … … 293 291 $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] ); 294 292 295 // Set the global table names, if applicable 293 // Set the global table names, if applicable. 296 294 if ( ! empty( $r['global_tables'] ) ) { 297 295 $this->register_global_tables( $r['global_tables'] ); 298 296 } 299 297 300 // Set the metadata table, if applicable 298 // Set the metadata table, if applicable. 301 299 if ( ! empty( $r['meta_tables'] ) ) { 302 300 $this->register_meta_tables( $r['meta_tables'] ); 303 301 } 304 302 305 /** BuddyPress ********************************************************/ 306 307 // Register this component in the loaded components array 303 /** BuddyPress ******************************************************* 304 */ 305 306 // Register this component in the loaded components array. 308 307 buddypress()->loaded_components[$this->slug] = $this->id; 309 308 … … 350 349 public function includes( $includes = array() ) { 351 350 352 // Bail if no files to include 351 // Bail if no files to include. 353 352 if ( ! empty( $includes ) ) { 354 353 $slashed_path = trailingslashit( $this->path ); 355 354 356 // Loop through files to be included 355 // Loop through files to be included. 357 356 foreach ( (array) $includes as $file ) { 358 357 359 358 $paths = array( 360 359 361 // Passed with no extension 360 // Passed with no extension. 362 361 'bp-' . $this->id . '/bp-' . $this->id . '-' . $file . '.php', 363 362 'bp-' . $this->id . '-' . $file . '.php', 364 363 'bp-' . $this->id . '/' . $file . '.php', 365 364 366 // Passed with extension 365 // Passed with extension. 367 366 $file, 368 367 'bp-' . $this->id . '-' . $file, … … 399 398 public function setup_actions() { 400 399 401 // Setup globals 400 // Setup globals. 402 401 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 ); 403 402 404 // Set up canonical stack 403 // Set up canonical stack. 405 404 add_action( 'bp_setup_canonical_stack', array( $this, 'setup_canonical_stack' ), 10 ); 406 405 … … 412 411 add_action( 'bp_include', array( $this, 'includes' ), 8 ); 413 412 414 // Setup navigation 413 // Setup navigation. 415 414 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 416 415 417 // Setup WP Toolbar menus 416 // Setup WP Toolbar menus. 418 417 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), $this->adminbar_myaccount_order ); 419 418 420 // Setup component title 419 // Setup component title. 421 420 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 ); 422 421 423 // Setup cache groups 422 // Setup cache groups. 424 423 add_action( 'bp_setup_cache_groups', array( $this, 'setup_cache_groups' ), 10 ); 425 424 426 // Register post types 425 // Register post types. 427 426 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 ); 428 427 429 // Register taxonomies 428 // Register taxonomies. 430 429 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 ); 431 430 432 // Add the rewrite tags 431 // Add the rewrite tags. 433 432 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 ); 434 433 435 // Add the rewrite rules 434 // Add the rewrite rules. 436 435 add_action( 'bp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ), 10 ); 437 436 438 // Add the permalink structure 437 // Add the permalink structure. 439 438 add_action( 'bp_add_permastructs', array( $this, 'add_permastructs' ), 10 ); 440 439 441 // Allow components to parse the main query 440 // Allow components to parse the main query. 442 441 add_action( 'bp_parse_query', array( $this, 'parse_query' ), 10 ); 443 442 444 // Generate rewrite rules 443 // Generate rewrite rules. 445 444 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 446 445 … … 478 477 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 479 478 480 // No sub nav items without a main nav item 479 // No sub nav items without a main nav item. 481 480 if ( !empty( $main_nav ) ) { 482 481 bp_core_new_nav_item( $main_nav ); 483 482 484 // Sub nav items are not required 483 // Sub nav items are not required. 485 484 if ( !empty( $sub_nav ) ) { 486 485 foreach( (array) $sub_nav as $nav ) { … … 514 513 public function setup_admin_bar( $wp_admin_nav = array() ) { 515 514 516 // Bail if this is an ajax request 515 // Bail if this is an ajax request. 517 516 if ( defined( 'DOING_AJAX' ) ) { 518 517 return; 519 518 } 520 519 521 // Do not proceed if BP_USE_WP_ADMIN_BAR constant is not set or is false 520 // Do not proceed if BP_USE_WP_ADMIN_BAR constant is not set or is false. 522 521 if ( ! bp_use_wp_admin_bar() ) { 523 522 return; … … 538 537 if ( !empty( $wp_admin_nav ) ) { 539 538 540 // Set this objects menus 539 // Set this objects menus. 541 540 $this->admin_menu = $wp_admin_nav; 542 541 543 // Define the WordPress global 542 // Define the WordPress global. 544 543 global $wp_admin_bar; 545 544 546 // Add each admin menu 545 // Add each admin menu. 547 546 foreach( $this->admin_menu as $admin_menu ) { 548 547 $wp_admin_bar->add_menu( $admin_menu ); … … 618 617 $tables = apply_filters( 'bp_' . $this->id . '_global_tables', $tables ); 619 618 620 // Add to the BuddyPress global object 619 // Add to the BuddyPress global object. 621 620 if ( !empty( $tables ) && is_array( $tables ) ) { 622 621 foreach ( $tables as $global_name => $table_name ) { … … 624 623 } 625 624 626 // Keep a record of the metadata tables in the component 625 // Keep a record of the metadata tables in the component. 627 626 $this->global_tables = $tables; 628 627 } … … 671 670 } 672 671 673 // Keep a record of the metadata tables in the component 672 // Keep a record of the metadata tables in the component. 674 673 $this->meta_tables = $tables; 675 674 } -
trunk/src/bp-core/bp-core-cssjs.php
r10155 r10356 28 28 $scripts = apply_filters( 'bp_core_register_common_scripts', array( 29 29 30 // Legacy 30 // Legacy. 31 31 'bp-confirm' => array( 'file' => "{$url}confirm{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ), 32 32 'bp-widget-members' => array( 'file' => "{$url}widget-members{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ), … … 133 133 } 134 134 135 // Enqueue the Attachments scripts for the Avatar UI 135 // Enqueue the Attachments scripts for the Avatar UI. 136 136 bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' ); 137 137 138 // Add Some actions for Theme backcompat 138 // Add Some actions for Theme backcompat. 139 139 add_action( 'bp_after_profile_avatar_upload_content', 'bp_avatar_template_check' ); 140 140 add_action( 'bp_after_group_admin_content', 'bp_avatar_template_check' ); … … 153 153 } 154 154 155 // Enqueue the Attachments scripts for the Cover Image UI 155 // Enqueue the Attachments scripts for the Cover Image UI. 156 156 bp_attachments_enqueue_scripts( 'BP_Attachment_Cover_Image' ); 157 157 } … … 185 185 } 186 186 187 // Get avatar full width and height 187 // Get avatar full width and height. 188 188 $full_height = bp_core_avatar_full_height(); 189 189 $full_width = bp_core_avatar_full_width(); 190 190 191 // Calculate Aspect Ratio 191 // Calculate Aspect Ratio. 192 192 if ( !empty( $full_height ) && ( $full_width != $full_height ) ) { 193 193 $aspect_ratio = $full_width / $full_height; … … 196 196 } 197 197 198 // Default cropper coordinates 199 200 // Smaller than full-width: cropper defaults to entire image 198 // Default cropper coordinates. 199 // Smaller than full-width: cropper defaults to entire image. 201 200 if ( $image[0] < $full_width ) { 202 201 $crop_left = 0; 203 202 $crop_right = $image[0]; 204 203 205 // Less than 2x full-width: cropper defaults to full-width 204 // Less than 2x full-width: cropper defaults to full-width. 206 205 } elseif ( $image[0] < ( $full_width * 2 ) ) { 207 206 $padding_w = round( ( $image[0] - $full_width ) / 2 ); … … 209 208 $crop_right = $image[0] - $padding_w; 210 209 211 // Larger than 2x full-width: cropper defaults to 1/2 image width 210 // Larger than 2x full-width: cropper defaults to 1/2 image width. 212 211 } else { 213 212 $crop_left = round( $image[0] / 4 ); … … 215 214 } 216 215 217 // Smaller than full-height: cropper defaults to entire image 216 // Smaller than full-height: cropper defaults to entire image. 218 217 if ( $image[1] < $full_height ) { 219 218 $crop_top = 0; 220 219 $crop_bottom = $image[1]; 221 220 222 // Less than double full-height: cropper defaults to full-height 221 // Less than double full-height: cropper defaults to full-height. 223 222 } elseif ( $image[1] < ( $full_height * 2 ) ) { 224 223 $padding_h = round( ( $image[1] - $full_height ) / 2 ); … … 226 225 $crop_bottom = $image[1] - $padding_h; 227 226 228 // Larger than 2x full-height: cropper defaults to 1/2 image height 227 // Larger than 2x full-height: cropper defaults to 1/2 image height. 229 228 } else { 230 229 $crop_top = round( $image[1] / 4 ); … … 273 272 /** 274 273 * Output the inline CSS for the BP image cropper. 275 *276 * @package BuddyPress Core277 274 */ 278 275 function bp_core_add_cropper_inline_css() { … … 362 359 * @since 2.4.0 363 360 * 364 * @param bool $return true to get the inline css361 * @param bool $return True to get the inline css. 365 362 * @return string|array the inline css or an associative array containing 366 363 * the css rules and the style handle … … 369 366 $bp = buddypress(); 370 367 371 // Find the component of the current item 368 // Find the component of the current item. 372 369 if ( bp_is_user() ) { 373 370 374 371 // User is not allowed to upload cover images 375 // no need to carry on 372 // no need to carry on. 376 373 if ( bp_disable_cover_image_uploads() ) { 377 374 return; … … 385 382 386 383 // Users are not allowed to upload cover images for their groups 387 // no need to carry on 384 // no need to carry on. 388 385 if ( bp_disable_group_cover_image_uploads() ) { 389 386 return; … … 403 400 } 404 401 405 // Get the settings of the cover image feature for the current component 402 // Get the settings of the cover image feature for the current component. 406 403 $params = bp_attachments_get_cover_image_settings( $cover_image_object['component'] ); 407 404 … … 411 408 } 412 409 413 // Try to call the callback 410 // Try to call the callback. 414 411 if ( is_callable( $params['callback'] ) ) { 415 412 … … 439 436 ) ) ); 440 437 441 // Finally add the inline css to the handle 438 // Finally add the inline css to the handle. 442 439 if ( ! empty( $inline_css ) ) { 443 440 444 // Used to get the css when Ajax setting the cover image 441 // Used to get the css when Ajax setting the cover image. 445 442 if ( true === $return ) { 446 443 return array( -
trunk/src/bp-core/bp-core-dependency.php
r10108 r10356 490 490 * 491 491 * @param array $query_vars See {@link WP::parse_request()}. 492 *493 492 * @return array $query_vars See {@link WP::parse_request()}. 494 493 */ … … 512 511 * @param string $redirect_to See 'login_redirect'. 513 512 * @param string $redirect_to_raw See 'login_redirect'. 514 * 515 * @param bool $user See 'login_redirect'. 516 * 513 * @param bool $user See 'login_redirect'. 517 514 * @return string 518 515 */ … … 541 538 * 542 539 * @param string $template See 'template_include'. 543 *544 540 * @return string Template file to use. 545 541 */ … … 586 582 * @uses apply_filters() Calls 'bp_allowed_themes' with the allowed themes list. 587 583 * 588 * @param array $themes 589 * 584 * @param array $themes The path of the template to include. 590 585 * @return array 591 586 */ … … 608 603 * 609 604 * @since 1.9.0 605 * 610 606 * @uses do_action() 611 607 */ 612 608 function bp_post_request() { 613 609 614 // Bail if not a POST action 610 // Bail if not a POST action. 615 611 if ( ! bp_is_post_request() ) { 616 612 return; 617 613 } 618 614 619 // Bail if no action 615 // Bail if no action. 620 616 if ( empty( $_POST['action'] ) ) { 621 617 return; 622 618 } 623 619 624 // Sanitize the POST action 620 // Sanitize the POST action. 625 621 $action = sanitize_key( $_POST['action'] ); 626 622 … … 651 647 * 652 648 * @since 1.9.0 649 * 653 650 * @uses do_action() 654 651 */ 655 652 function bp_get_request() { 656 653 657 // Bail if not a POST action 654 // Bail if not a POST action. 658 655 if ( ! bp_is_get_request() ) { 659 656 return; 660 657 } 661 658 662 // Bail if no action 659 // Bail if no action. 663 660 if ( empty( $_GET['action'] ) ) { 664 661 return; 665 662 } 666 663 667 // Sanitize the GET action 664 // Sanitize the GET action. 668 665 $action = sanitize_key( $_GET['action'] ); 669 666 -
trunk/src/bp-core/bp-core-filters.php
r10276 r10356 44 44 add_filter( 'map_meta_cap', 'bp_map_meta_caps', 10, 4 ); 45 45 46 // Add some filters to feedback messages 46 // Add some filters to feedback messages. 47 47 add_filter( 'bp_core_render_message_content', 'wptexturize' ); 48 48 add_filter( 'bp_core_render_message_content', 'convert_smilies' ); … … 62 62 add_filter( 'bp_template_include', 'bp_template_include_theme_compat', 4, 2 ); 63 63 64 // Filter BuddyPress template locations 64 // Filter BuddyPress template locations. 65 65 add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations' ); 66 66 67 // Turn comments off for BuddyPress pages 67 // Turn comments off for BuddyPress pages. 68 68 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 69 69 … … 75 75 * @param array $pages List of excluded page IDs, as passed to the 76 76 * 'wp_list_pages_excludes' filter. 77 *78 77 * @return array The exclude list, with BP's pages added. 79 78 */ 80 79 function bp_core_exclude_pages( $pages = array() ) { 81 80 82 // Bail if not the root blog 81 // Bail if not the root blog. 83 82 if ( ! bp_is_root_blog() ) 84 83 return $pages; … … 115 114 * 116 115 * @param object|null $object The post type object used in the meta box. 117 *118 116 * @return object|null The $object, with a query argument to remove register and activate pages id. 119 117 */ 120 118 function bp_core_exclude_pages_from_nav_menu_admin( $object = null ) { 121 119 122 // Bail if not the root blog 120 // Bail if not the root blog. 123 121 if ( ! bp_is_root_blog() ) { 124 122 return $object; … … 160 158 * @param array $retval CSS classes for the current menu page in the menu. 161 159 * @param WP_Post $page The page properties for the current menu item. 162 *163 160 * @return array 164 161 */ … … 170 167 $page_id = false; 171 168 172 // loop against all BP component pages169 // Loop against all BP component pages. 173 170 foreach ( (array) buddypress()->pages as $component => $bp_page ) { 174 // handles the majority of components171 // Handles the majority of components. 175 172 if ( bp_is_current_component( $component ) ) { 176 173 $page_id = (int) $bp_page->id; 177 174 } 178 175 179 // stop if not on a user page176 // Stop if not on a user page. 180 177 if ( ! bp_is_user() && ! empty( $page_id ) ) { 181 178 break; 182 179 } 183 180 184 // members component requires an explicit check due to overlapping components181 // Members component requires an explicit check due to overlapping components. 185 182 if ( bp_is_user() && 'members' === $component ) { 186 183 $page_id = (int) $bp_page->id; … … 189 186 } 190 187 191 // duplicate some logic from Walker_Page::start_el() to highlight menu items188 // Duplicate some logic from Walker_Page::start_el() to highlight menu items. 192 189 if ( ! empty( $page_id ) ) { 193 190 $_bp_page = get_post( $page_id ); … … 218 215 * @param array $retval CSS classes for the current nav menu item in the menu. 219 216 * @param WP_Post $item The properties for the current nav menu item. 220 *221 217 * @return array 222 218 */ … … 227 223 } 228 224 229 // get the WP page225 // Get the WP page. 230 226 $page = get_post( $item->object_id ); 231 227 232 // see if we should add our highlight CSS classes for the page228 // See if we should add our highlight CSS classes for the page. 233 229 $retval = bp_core_menu_highlight_parent_page( $retval, $page ); 234 230 … … 262 258 * @param array $comments The array of comments supplied to the comments template. 263 259 * @param int $post_id The post ID. 264 *265 260 * @return array $comments The modified comment array. 266 261 */ … … 305 300 * @param WP_User $user The WP_User object corresponding to a successfully 306 301 * logged-in user. Otherwise a WP_Error object. 307 *308 302 * @return string The redirect URL. 309 303 */ 310 304 function bp_core_login_redirect( $redirect_to, $redirect_to_raw, $user ) { 311 305 312 // Only modify the redirect if we're on the main BP blog 306 // Only modify the redirect if we're on the main BP blog. 313 307 if ( !bp_is_root_blog() ) { 314 308 return $redirect_to; 315 309 } 316 310 317 // Only modify the redirect once the user is logged in 311 // Only modify the redirect once the user is logged in. 318 312 if ( !is_a( $user, 'WP_User' ) ) { 319 313 return $redirect_to; … … 340 334 // If a 'redirect_to' parameter has been passed that contains 'wp-admin', verify that the 341 335 // logged-in user has any business to conduct in the Dashboard before allowing the 342 // redirect to go through 336 // redirect to go through. 343 337 if ( !empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) { 344 338 return $redirect_to; … … 370 364 * 371 365 * @param string $welcome_email Complete email passed through WordPress. 372 *373 366 * @return string Filtered $welcome_email with the password replaced 374 367 * by '[User Set]'. … … 376 369 function bp_core_filter_user_welcome_email( $welcome_email ) { 377 370 378 // Don't touch the email when a user is registered by the site admin 371 // Don't touch the email when a user is registered by the site admin. 379 372 if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page != get_current_screen()->id ) { 380 373 return $welcome_email; … … 385 378 } 386 379 387 // Don't touch the email if we don't have a custom registration template 380 // Don't touch the email if we don't have a custom registration template. 388 381 if ( ! bp_has_custom_signup_page() ) { 389 382 return $welcome_email; … … 408 401 * @param int $user_id ID of the user joining. 409 402 * @param string $password Password of user. 410 *411 403 * @return string Filtered $welcome_email with $password replaced by '[User Set]'. 412 404 */ 413 405 function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) { 414 406 415 // Don't touch the email when a user is registered by the site admin 407 // Don't touch the email when a user is registered by the site admin. 416 408 if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page != get_current_screen()->id ) { 417 409 return $welcome_email; 418 410 } 419 411 420 // Don't touch the email if we don't have a custom registration template 412 // Don't touch the email if we don't have a custom registration template. 421 413 if ( ! bp_has_custom_signup_page() ) 422 414 return $welcome_email; … … 440 432 * @param string $user The user's login name. 441 433 * @param string $user_email The user's email address. 442 * @param string $key The activation key created in wpmu_signup_blog() 434 * @param string $key The activation key created in wpmu_signup_blog(). 443 435 * @param array $meta By default, contains the requested privacy setting and 444 436 * lang_id. 445 *446 437 * @return bool True on success, false on failure. 447 438 */ 448 439 function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) { 449 440 450 // Set up activation link 441 // Set up activation link. 451 442 $activate_url = bp_get_activation_page() ."?key=$key"; 452 443 $activate_url = esc_url( $activate_url ); 453 444 454 // Email contents 445 // Email contents. 455 446 $message = sprintf( __( "%1\$s,\n\n\n\nThanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%2\$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%3\$s", 'buddypress' ), $user, $activate_url, esc_url( "http://{$domain}{$path}" ) ); 456 447 $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'Activate %s', 'buddypress' ), 'http://' . $domain . $path ) ) ); … … 504 495 $message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message, $domain, $path, $title, $user, $user_email, $key, $meta ); 505 496 506 // Send the email 497 // Send the email. 507 498 wp_mail( $to, $subject, $message ); 508 499 509 // Set up the $admin_email to pass to the filter 500 // Set up the $admin_email to pass to the filter. 510 501 $admin_email = bp_get_option( 'admin_email' ); 511 502 … … 528 519 do_action( 'bp_core_sent_blog_signup_email', $admin_email, $subject, $message, $domain, $path, $title, $user, $user_email, $key, $meta ); 529 520 530 // Return false to stop the original WPMU function from continuing 521 // Return false to stop the original WPMU function from continuing. 531 522 return false; 532 523 } … … 540 531 * @param string $user The user's login name. 541 532 * @param string $user_email The user's email address. 542 * @param string $key The activation key created in wpmu_signup_user() 533 * @param string $key The activation key created in wpmu_signup_user(). 543 534 * @param array $meta By default, an empty array. 544 *545 535 * @return bool|string True on success, false on failure. 546 536 */ … … 548 538 549 539 if ( is_admin() ) { 550 // If the user is created from the WordPress Add User screen, don't send BuddyPress signup notifications 540 // If the user is created from the WordPress Add User screen, don't send BuddyPress signup notifications. 551 541 if( in_array( get_current_screen()->id, array( 'user', 'user-network' ) ) ) { 552 // If the Super Admin want to skip confirmation email 542 // If the Super Admin want to skip confirmation email. 553 543 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 554 544 return false; 555 545 556 // WordPress will manage the signup process 546 // WordPress will manage the signup process. 557 547 } else { 558 548 return $user; … … 562 552 * There can be a case where the user was created without the skip confirmation 563 553 * And the super admin goes in pending accounts to resend it. In this case, as the 564 * meta['password'] is not set, the activation url must be WordPress one 554 * meta['password'] is not set, the activation url must be WordPress one. 565 555 */ 566 556 } elseif ( buddypress()->members->admin->signups_page == get_current_screen()->id ) { … … 573 563 } 574 564 575 // Set up activation link 565 // Set up activation link. 576 566 $activate_url = bp_get_activation_page() . "?key=$key"; 577 567 $activate_url = esc_url( $activate_url ); 578 568 579 // Email contents 569 // Email contents. 580 570 $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%1\$s\n\n", 'buddypress' ), $activate_url ); 581 571 $subject = bp_get_email_subject( array( 'text' => __( 'Activate Your Account', 'buddypress' ) ) ); … … 620 610 $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message, $user, $user_email, $key, $meta ); 621 611 622 // Send the email 612 // Send the email. 623 613 wp_mail( $to, $subject, $message ); 624 614 625 // Set up the $admin_email to pass to the filter 615 // Set up the $admin_email to pass to the filter. 626 616 $admin_email = bp_get_option( 'admin_email' ); 627 617 … … 641 631 do_action( 'bp_core_sent_user_signup_email', $admin_email, $subject, $message, $user, $user_email, $key, $meta ); 642 632 643 // Return false to stop the original WPMU function from continuing 633 // Return false to stop the original WPMU function from continuing. 644 634 return false; 645 635 } … … 657 647 * @param string $sep How to separate the various items within the page title. 658 648 * @param string $seplocation Direction to display title. 659 *660 649 * @return string New page title. 661 650 */ … … 663 652 global $bp, $paged, $page, $_wp_theme_features; 664 653 665 // If this is not a BP page, just return the title produced by WP 654 // If this is not a BP page, just return the title produced by WP. 666 655 if ( bp_is_blog_page() ) { 667 656 return $title; 668 657 } 669 658 670 // If this is a 404, let WordPress handle it 659 // If this is a 404, let WordPress handle it. 671 660 if ( is_404() ) { 672 661 return $title; 673 662 } 674 663 675 // If this is the front page of the site, return WP's title 664 // If this is the front page of the site, return WP's title. 676 665 if ( is_front_page() || is_home() ) { 677 666 return $title; 678 667 } 679 668 680 // Return WP's title if not a BuddyPress page 669 // Return WP's title if not a BuddyPress page. 681 670 if ( ! is_buddypress() ) { 682 671 return $title; 683 672 } 684 673 685 // Setup an empty title parts array 674 // Setup an empty title parts array. 686 675 $title_parts = array(); 687 676 … … 689 678 $displayed_user_name = bp_get_displayed_user_fullname(); 690 679 691 // Displayed user 680 // Displayed user. 692 681 if ( ! empty( $displayed_user_name ) && ! is_404() ) { 693 682 694 // Get the component's ID to try and get its name 683 // Get the component's ID to try and get its name. 695 684 $component_id = $component_name = bp_current_component(); 696 685 697 // Set empty subnav name 686 // Set empty subnav name. 698 687 $component_subnav_name = ''; 699 688 700 // Use the component nav name 689 // Use the component nav name. 701 690 if ( ! empty( $bp->bp_nav[$component_id] ) ) { 702 691 $component_name = _bp_strip_spans_from_title( $bp->bp_nav[ $component_id ]['name'] ); 703 692 704 // Fall back on the component ID 693 // Fall back on the component ID. 705 694 } elseif ( ! empty( $bp->{$component_id}->id ) ) { 706 695 $component_name = ucwords( $bp->{$component_id}->id ); 707 696 } 708 697 709 // Append action name if we're on a member component sub-page 698 // Append action name if we're on a member component sub-page. 710 699 if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) { 711 700 $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' ); … … 716 705 } 717 706 718 // If on the user profile's landing page, just use the fullname 707 // If on the user profile's landing page, just use the fullname. 719 708 if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) { 720 709 $title_parts[] = $displayed_user_name; 721 710 722 // Use component name on member pages 711 // Use component name on member pages. 723 712 } else { 724 713 $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array( … … 727 716 ) ) ); 728 717 729 // If we have a subnav name, add it separately for localization 718 // If we have a subnav name, add it separately for localization. 730 719 if ( ! empty( $component_subnav_name ) ) { 731 720 $title_parts[] = strip_tags( $component_subnav_name ); … … 733 722 } 734 723 735 // A single group 724 // A single group. 736 725 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) { 737 726 $subnav = isset( $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] ) ? $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] : ''; 738 727 $title_parts = array( $bp->bp_options_title, $subnav ); 739 728 740 // A single item from a component other than groups 729 // A single item from a component other than groups. 741 730 } elseif ( bp_is_single_item() ) { 742 731 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 743 732 744 // An index or directory 733 // An index or directory. 745 734 } elseif ( bp_is_directory() ) { 746 735 $current_component = bp_current_component(); 747 736 748 // No current component (when does this happen?) 737 // No current component (when does this happen?). 749 738 $title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) ); 750 739 … … 753 742 } 754 743 755 // Sign up page 744 // Sign up page. 756 745 } elseif ( bp_is_register_page() ) { 757 746 $title_parts = array( __( 'Create an Account', 'buddypress' ) ); 758 747 759 // Activation page 748 // Activation page. 760 749 } elseif ( bp_is_activation_page() ) { 761 750 $title_parts = array( __( 'Activate Your Account', 'buddypress' ) ); 762 751 763 // Group creation page 752 // Group creation page. 764 753 } elseif ( bp_is_group_create() ) { 765 754 $title_parts = array( __( 'Create a Group', 'buddypress' ) ); 766 755 767 // Blog creation page 756 // Blog creation page. 768 757 } elseif ( bp_is_create_blog() ) { 769 758 $title_parts = array( __( 'Create a Site', 'buddypress' ) ); 770 759 } 771 760 772 // Strip spans 761 // Strip spans. 773 762 $title_parts = array_map( '_bp_strip_spans_from_title', $title_parts ); 774 763 775 // sep on right, so reverse the order764 // Sep on right, so reverse the order. 776 765 if ( 'right' == $seplocation ) { 777 766 $title_parts = array_reverse( $title_parts ); 778 767 } 779 768 780 // Get the blog name, so we can check if the original $title included it 769 // Get the blog name, so we can check if the original $title included it. 781 770 $blogname = get_bloginfo( 'name', 'display' ); 782 771 … … 789 778 $title_tag_compatibility = (bool) ( ! empty( $_wp_theme_features['title-tag'] ) || strstr( $title, $blogname ) ); 790 779 791 // Append the site title to title parts if theme supports title tag 780 // Append the site title to title parts if theme supports title tag. 792 781 if ( true === $title_tag_compatibility ) { 793 782 $title_parts[] = $blogname; … … 798 787 } 799 788 800 // Pad the separator with 1 space on each side 789 // Pad the separator with 1 space on each side. 801 790 $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH ); 802 791 803 // Join the parts together 792 // Join the parts together. 804 793 $new_title = join( $prefix, array_filter( $title_parts ) ); 805 794 806 // Append the prefix for pre `title-tag` compatibility 795 // Append the prefix for pre `title-tag` compatibility. 807 796 if ( false === $title_tag_compatibility ) { 808 797 $new_title = $new_title . $prefix; … … 832 821 * less than 4.0, and should be removed at a later date. 833 822 * 834 * @param string $title_part 835 * 823 * @param string $title_part Title part to clean up. 836 824 * @return string 837 825 */ … … 851 839 * 852 840 * @param WP_Post $menu_item The menu item. 853 *854 841 * @return WP_Post The modified WP_Post object. 855 842 */ … … 859 846 } 860 847 861 // Prevent a notice error when using the customizer 848 // Prevent a notice error when using the customizer. 862 849 $menu_classes = $menu_item->classes; 863 850 … … 867 854 868 855 // We use information stored in the CSS class to determine what kind of 869 // menu item this is, and how it should be treated 856 // menu item this is, and how it should be treated. 870 857 preg_match( '/\sbp-(.*)-nav/', $menu_classes, $matches ); 871 858 872 // If this isn't a BP menu item, we can stop here 859 // If this isn't a BP menu item, we can stop here. 873 860 if ( empty( $matches[1] ) ) { 874 861 return $menu_item; … … 894 881 break; 895 882 896 // Don't show the Register link to logged-in users 883 // Don't show the Register link to logged-in users. 897 884 case 'register' : 898 885 if ( is_user_logged_in() ) { … … 903 890 904 891 // All other BP nav items are specific to the logged-in user, 905 // and so are not relevant to logged-out users 892 // and so are not relevant to logged-out users. 906 893 default: 907 894 if ( is_user_logged_in() ) { … … 914 901 } 915 902 916 // If component is deactivated, make sure menu item doesn't render 903 // If component is deactivated, make sure menu item doesn't render. 917 904 if ( empty( $menu_item->url ) ) { 918 905 $menu_item->_invalid = true; 919 906 920 // Highlight the current page 907 // Highlight the current page. 921 908 } else { 922 909 $current = bp_get_requested_url(); … … 936 923 937 924 /** 938 * Populate BuddyPress user nav items for the customizer 925 * Populate BuddyPress user nav items for the customizer. 939 926 * 940 927 * @since 2.3.3 941 928 * 942 * @param array $items The array of menu items 943 * @param string $type The requested type 944 * @param string $object The requested object name 945 * @param integer $page The page num being requested 929 * @param array $items The array of menu items. 930 * @param string $type The requested type. 931 * @param string $object The requested object name. 932 * @param integer $page The page num being requested. 946 933 * @return array The paginated BuddyPress user nav items. 947 934 */ … … 973 960 974 961 /** 975 * Set BuddyPress item navs for the customizer 962 * Set BuddyPress item navs for the customizer. 976 963 * 977 964 * @since 2.3.3 … … 1012 999 * 1013 1000 * @param string $q SQL query. 1014 *1015 1001 * @return string 1016 1002 */ … … 1044 1030 * @param string $edit_link The edit link. 1045 1031 * @param int $post_id Post ID. 1046 *1047 1032 * @return bool|string Will be a boolean (false) if $post_id is 0. Will be a string (the unchanged edit link) 1048 1033 * otherwise … … 1064 1049 * @param bool $load_mentions True to load mentions assets, false otherwise. 1065 1050 * @param bool $mentions_enabled True if mentions are enabled. 1066 *1067 1051 * @return bool True if mentions scripts should be loaded. 1068 1052 */ -
trunk/src/bp-core/bp-core-functions.php
r10110 r10356 47 47 * 48 48 * @since 1.6.0 49 * 49 50 * @return string The BuddyPress database version. 50 51 */ … … 109 110 * @since 2.2.0 110 111 * 111 * @param 112 * @param 113 * @param 114 * @return array 112 * @param array $items The items to be sorted. Its constituent items can be either associative arrays or objects. 113 * @param string|int $key The array index or property name to sort by. 114 * @param string $type Sort type. 'alpha' for alphabetical, 'num' for numeric. Default: 'alpha'. 115 * @return array $items The sorted array. 115 116 */ 116 117 function bp_sort_by_key( $items, $key, $type = 'alpha' ) { … … 158 159 * @since 1.9.0 159 160 * 160 * @param 161 * @param 162 * @return array 161 * @param array $items The items to be sorted. Its constituent items can be either associative arrays or objects. 162 * @param string|int $key The array index or property name to sort by. 163 * @return array $items The sorted array. 163 164 */ 164 165 function bp_alpha_sort_by_key( $items, $key ) { … … 171 172 * @param int $number The number to be formatted. 172 173 * @param bool $decimals Whether to use decimals. See {@link number_format_i18n()}. 173 *174 174 * @return string The formatted number. 175 175 */ 176 176 function bp_core_number_format( $number = 0, $decimals = false ) { 177 177 178 // Force number to 0 if needed 178 // Force number to 0 if needed. 179 179 if ( ! is_numeric( $number ) ) { 180 180 $number = 0; … … 227 227 * @param array $old_args_keys Old argument indexs, keyed to their positions. 228 228 * @param array $func_args The parameters passed to the originating function. 229 *230 229 * @return array $new_args The parsed arguments. 231 230 */ … … 256 255 * @param array $defaults Array that serves as the defaults. 257 256 * @param string $filter_key String to key the filters from. 258 *259 257 * @return array Merged user defined values with defaults. 260 258 */ 261 259 function bp_parse_args( $args, $defaults = array(), $filter_key = '' ) { 262 260 263 // Setup a temporary array from $args 261 // Setup a temporary array from $args. 264 262 if ( is_object( $args ) ) { 265 263 $r = get_object_vars( $args ); … … 270 268 } 271 269 272 // Passively filter the args before the parse 270 // Passively filter the args before the parse. 273 271 if ( !empty( $filter_key ) ) { 274 272 … … 285 283 } 286 284 287 // Parse 285 // Parse. 288 286 if ( is_array( $defaults ) && !empty( $defaults ) ) { 289 287 $r = array_merge( $defaults, $r ); 290 288 } 291 289 292 // Aggressively filter the args after the parse 290 // Aggressively filter the args after the parse. 293 291 if ( !empty( $filter_key ) ) { 294 292 … … 305 303 } 306 304 307 // Return the parsed results 305 // Return the parsed results. 308 306 return $r; 309 307 } … … 316 314 * @since 2.2.0 317 315 * 318 * @param string $page_arg The $_REQUEST argument to look for. 319 * @param int $page The original page value to fall back to. 320 * 321 * @return int A sanitized integer value, good for pagination. 316 * @param string $page_arg The $_REQUEST argument to look for. 317 * @param int $page The original page value to fall back to. 318 * @return int A sanitized integer value, good for pagination. 322 319 */ 323 320 function bp_sanitize_pagination_arg( $page_arg = '', $page = 1 ) { 324 321 325 // Check if request overrides exist 322 // Check if request overrides exist. 326 323 if ( isset( $_REQUEST[ $page_arg ] ) ) { 327 324 328 // Get the absolute integer value of the override 325 // Get the absolute integer value of the override. 329 326 $int = absint( $_REQUEST[ $page_arg ] ); 330 327 331 328 // If override is 0, do not use it. This prevents unlimited result sets. 332 // @see https://buddypress.trac.wordpress.org/ticket/5796 329 // @see https://buddypress.trac.wordpress.org/ticket/5796. 333 330 if ( $int ) { 334 331 $page = $int; … … 348 345 * 349 346 * @param string $order The 'order' string, as passed to the SQL constructor. 350 *351 347 * @return string The sanitized value 'DESC' or 'ASC'. 352 348 */ … … 369 365 * 370 366 * @param string $text The raw text to be escaped. 371 *372 367 * @return string Text in the form of a LIKE phrase. Not SQL safe. Run through 373 368 * wpdb::prepare() before use. … … 420 415 function bp_use_wp_admin_bar() { 421 416 422 // Default to true (to avoid loading deprecated BuddyBar code) 417 // Default to true (to avoid loading deprecated BuddyBar code). 423 418 $use_admin_bar = true; 424 419 … … 464 459 ); 465 460 466 // only add legacy forums if it is enabled467 // prevents conflicts with bbPress, which also uses the same 'forums' id 461 // Only add legacy forums if it is enabled 462 // prevents conflicts with bbPress, which also uses the same 'forums' id. 468 463 if ( class_exists( 'BP_Forums_Component' ) ) { 469 464 $components[] = 'forums'; … … 481 476 * pages. When running save routines, use 'all' to avoid removing data related to inactive 482 477 * components. Default: 'active'. 483 *484 478 * @return array|string An array of page IDs, keyed by component names, or an 485 479 * empty string if the list is not found. … … 488 482 $page_ids = bp_get_option( 'bp-pages' ); 489 483 490 // Ensure that empty indexes are unset. Should only matter in edge cases 484 // Ensure that empty indexes are unset. Should only matter in edge cases. 491 485 if ( !empty( $page_ids ) && is_array( $page_ids ) ) { 492 486 foreach( (array) $page_ids as $component_name => $page_id ) { … … 526 520 * Store the list of BP directory pages in the appropriate meta table. 527 521 * 528 * bp-pages data is stored in site_options (falls back to options on non-MS),522 * The bp-pages data is stored in site_options (falls back to options on non-MS), 529 523 * in an array keyed by blog_id. This allows you to change your 530 524 * bp_get_root_blog_id() and go through the setup process again. … … 549 543 global $wpdb; 550 544 551 // Look in cache first 545 // Look in cache first. 552 546 $pages = wp_cache_get( 'directory_pages', 'bp' ); 553 547 554 548 if ( false === $pages ) { 555 549 556 // Set pages as standard class 550 // Set pages as standard class. 557 551 $pages = new stdClass; 558 552 559 // Get pages and IDs 553 // Get pages and IDs. 560 554 $page_ids = bp_core_get_directory_page_ids(); 561 555 if ( !empty( $page_ids ) ) { 562 556 563 557 // Always get page data from the root blog, except on multiblog mode, when it comes 564 // from the current blog 558 // from the current blog. 565 559 $posts_table_name = bp_is_multiblog_mode() ? $wpdb->posts : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts'; 566 560 $page_ids_sql = implode( ',', wp_parse_id_list( $page_ids ) ); … … 579 573 $slug[] = $page_name->post_name; 580 574 581 // Get the slug 575 // Get the slug. 582 576 while ( $page_name->post_parent != 0 ) { 583 577 $parent = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) ); … … 635 629 $pages = bp_core_get_directory_page_ids( 'all' ); 636 630 637 // Delete any existing pages 631 // Delete any existing pages. 638 632 if ( 'delete' === $existing ) { 639 633 foreach ( (array) $pages as $page_id ) { … … 661 655 662 656 // Register and Activate are not components, but need pages when 663 // registration is enabled 657 // registration is enabled. 664 658 if ( bp_get_signup_allowed() ) { 665 659 foreach ( array( 'register', 'activate' ) as $slug ) { … … 670 664 } 671 665 672 // No need for a Sites directory unless we're on multisite 666 // No need for a Sites directory unless we're on multisite. 673 667 if ( ! is_multisite() && isset( $pages_to_create['sites'] ) ) { 674 668 unset( $pages_to_create['sites'] ); 675 669 } 676 670 677 // Members must always have a page, no matter what 671 // Members must always have a page, no matter what. 678 672 if ( ! isset( $pages['members'] ) && ! isset( $pages_to_create['members'] ) ) { 679 673 $pages_to_create['members'] = $page_titles['members']; 680 674 } 681 675 682 // Create the pages 676 // Create the pages. 683 677 foreach ( $pages_to_create as $component_name => $page_name ) { 684 678 $exists = get_page_by_path( $component_name ); 685 679 686 // If page already exists, use it 680 // If page already exists, use it. 687 681 if ( ! empty( $exists ) ) { 688 682 $pages[ $component_name ] = $exists->ID; … … 698 692 } 699 693 700 // Save the page mapping 694 // Save the page mapping. 701 695 bp_update_option( 'bp-pages', $pages ); 702 696 … … 711 705 * 712 706 * Bails early on multisite installations when not viewing the root site. 707 * 713 708 * @link https://buddypress.trac.wordpress.org/ticket/6226 714 709 * … … 719 714 function bp_core_on_directory_page_delete( $post_id ) { 720 715 721 // Stop if we are not on the main BP root blog 716 // Stop if we are not on the main BP root blog. 722 717 if ( ! bp_is_root_blog() ) { 723 718 return; … … 756 751 * 757 752 * @param string $root_slug The root slug, which comes from $bp->pages->[component]->slug. 758 *759 753 * @return string The short slug for use in the middle of URLs. 760 754 */ … … 793 787 $match = false; 794 788 795 // Check if the slug is registered in the $bp->pages global 789 // Check if the slug is registered in the $bp->pages global. 796 790 foreach ( (array) $bp->pages as $key => $page ) { 797 791 if ( $key == $slug || $page->slug == $slug ) { … … 800 794 } 801 795 802 // Maybe create the add_root array 796 // Maybe create the add_root array. 803 797 if ( empty( $bp->add_root ) ) { 804 798 $bp->add_root = array(); 805 799 } 806 800 807 // If there was no match, add a page for this root component 801 // If there was no match, add a page for this root component. 808 802 if ( empty( $match ) ) { 809 803 $add_root_items = $bp->add_root(); … … 812 806 } 813 807 814 // Make sure that this component is registered as requiring a top-level directory 808 // Make sure that this component is registered as requiring a top-level directory. 815 809 if ( isset( $bp->{$slug} ) ) { 816 810 $bp->loaded_components[$bp->{$slug}->slug] = $bp->{$slug}->id; … … 824 818 function bp_core_create_root_component_page() { 825 819 826 // Get BuddyPress 820 // Get BuddyPress. 827 821 $bp = buddypress(); 828 822 … … 890 884 // This ensures that the version of bp-default in the regular themes 891 885 // directory will always take precedence, as part of a migration away 892 // from the version packaged with BuddyPress 886 // from the version packaged with BuddyPress. 893 887 foreach ( array_values( (array) $GLOBALS['wp_theme_directories'] ) as $directory ) { 894 888 if ( is_dir( $directory . '/bp-default' ) ) { … … 898 892 899 893 // If the current theme is bp-default (or a bp-default child), BP 900 // should register its directory 894 // should register its directory. 901 895 $register = 'bp-default' === get_stylesheet() || 'bp-default' === get_template(); 902 896 903 // Legacy sites continue to have the theme registered 897 // Legacy sites continue to have the theme registered. 904 898 if ( empty( $register ) && ( 1 == get_site_option( '_bp_retain_bp_default' ) ) ) { 905 899 $register = true; … … 921 915 * Return the domain for the root blog. 922 916 * 923 * eg: http://example.com OR https://example.com917 * Eg: http://example.com OR https://example.com 924 918 * 925 919 * @uses get_blog_option() WordPress function to fetch blog meta. … … 1009 1003 $site_path = '/'; 1010 1004 } else { 1011 // Unset the first three segments (http(s)://example.com part) 1005 // Unset the first three segments (http(s)://example.com part). 1012 1006 unset( $site_path[0] ); 1013 1007 unset( $site_path[1] ); … … 1042 1036 * @param string $type See the 'type' parameter in {@link current_time()}. 1043 1037 * Default: 'mysql'. 1044 *1045 1038 * @return string Current time in 'Y-m-d h:i:s' format. 1046 1039 */ … … 1080 1073 * @param int|bool $newer_date Optional. Unix timestamp of date to compare older 1081 1074 * date to. Default: false (current time). 1082 *1083 1075 * @return string String representing the time since the older date, eg 1084 1076 * "2 hours and 50 minutes". … … 1127 1119 $ago_text = apply_filters( 'bp_core_time_since_ago_text', __( '%s ago', 'buddypress' ) ); 1128 1120 1129 // array of time period chunks1121 // Array of time period chunks. 1130 1122 $chunks = array( 1131 1123 YEAR_IN_SECONDS, … … 1151 1143 $newer_date = ( !$newer_date ) ? bp_core_current_time( true, 'timestamp' ) : $newer_date; 1152 1144 1153 // Difference in seconds 1145 // Difference in seconds. 1154 1146 $since = $newer_date - $older_date; 1155 1147 … … 1166 1158 } else { 1167 1159 1168 // Step one: the first chunk 1160 // Step one: the first chunk. 1169 1161 for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) { 1170 1162 $seconds = $chunks[$i]; 1171 1163 1172 // Finding the biggest chunk (if the chunk fits, break) 1164 // Finding the biggest chunk (if the chunk fits, break). 1173 1165 $count = floor( $since / $seconds ); 1174 1166 if ( 0 != $count ) { … … 1177 1169 } 1178 1170 1179 // If $i iterates all the way to $j, then the event happened 0 seconds ago 1171 // If $i iterates all the way to $j, then the event happened 0 seconds ago. 1180 1172 if ( !isset( $chunks[$i] ) ) { 1181 1173 $output = $right_now_text; … … 1183 1175 } else { 1184 1176 1185 // Set output var 1177 // Set output var. 1186 1178 switch ( $seconds ) { 1187 1179 case YEAR_IN_SECONDS : … … 1212 1204 // We've left the quirk in place, since fractions of a 1213 1205 // minute are not a useful piece of information for our 1214 // purposes 1206 // purposes. 1215 1207 if ( $i + 2 < $j ) { 1216 1208 $seconds2 = $chunks[$i + 1]; 1217 1209 $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ); 1218 1210 1219 // Add to output var 1211 // Add to output var. 1220 1212 if ( 0 != $count2 ) { 1221 1213 $output .= _x( ',', 'Separator in time since', 'buddypress' ) . ' '; … … 1243 1235 } 1244 1236 1245 // No output, so happened right now 1237 // No output, so happened right now. 1246 1238 if ( ! (int) trim( $output ) ) { 1247 1239 $output = $right_now_text; … … 1250 1242 } 1251 1243 1252 // Append 'ago' to the end of time-since if not 'right now' 1244 // Append 'ago' to the end of time-since if not 'right now'. 1253 1245 if ( $output != $right_now_text ) { 1254 1246 $output = sprintf( $ago_text, $output ); … … 1278 1270 function bp_core_add_message( $message, $type = '' ) { 1279 1271 1280 // Success is the default 1272 // Success is the default. 1281 1273 if ( empty( $type ) ) { 1282 1274 $type = 'success'; 1283 1275 } 1284 1276 1285 // Send the values to the cookie for page reload display 1277 // Send the values to the cookie for page reload display. 1286 1278 @setcookie( 'bp-message', $message, time() + 60 * 60 * 24, COOKIEPATH ); 1287 1279 @setcookie( 'bp-message-type', $type, time() + 60 * 60 * 24, COOKIEPATH ); 1288 1280 1289 // Get BuddyPress 1281 // Get BuddyPress. 1290 1282 $bp = buddypress(); 1291 1283 1292 /** *1284 /** 1293 1285 * Send the values to the $bp global so we can still output messages 1294 1286 * without a page reload … … 1312 1304 function bp_core_setup_message() { 1313 1305 1314 // Get BuddyPress 1306 // Get BuddyPress. 1315 1307 $bp = buddypress(); 1316 1308 … … 1343 1335 function bp_core_render_message() { 1344 1336 1345 // Get BuddyPress 1337 // Get BuddyPress. 1346 1338 $bp = buddypress(); 1347 1339 … … 1395 1387 function bp_core_record_activity() { 1396 1388 1397 // Bail if user is not logged in 1389 // Bail if user is not logged in. 1398 1390 if ( ! is_user_logged_in() ) { 1399 1391 return false; 1400 1392 } 1401 1393 1402 // Get the user ID 1394 // Get the user ID. 1403 1395 $user_id = bp_loggedin_user_id(); 1404 1396 1405 // Bail if user is not active 1397 // Bail if user is not active. 1406 1398 if ( bp_is_user_inactive( $user_id ) ) { 1407 1399 return false; 1408 1400 } 1409 1401 1410 // Get the user's last activity 1402 // Get the user's last activity. 1411 1403 $activity = bp_get_user_last_activity( $user_id ); 1412 1404 1413 // Make sure it's numeric 1405 // Make sure it's numeric. 1414 1406 if ( ! is_numeric( $activity ) ) { 1415 1407 $activity = strtotime( $activity ); 1416 1408 } 1417 1409 1418 // Get current time 1410 // Get current time. 1419 1411 $current_time = bp_core_current_time(); 1420 1412 1421 // Use this action to detect the very first activity for a given member 1413 // Use this action to detect the very first activity for a given member. 1422 1414 if ( empty( $activity ) ) { 1423 1415 … … 1434 1426 } 1435 1427 1436 // If it's been more than 5 minutes, record a newer last-activity time 1428 // If it's been more than 5 minutes, record a newer last-activity time. 1437 1429 if ( empty( $activity ) || ( strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) ) ) { 1438 1430 bp_update_user_last_activity( $user_id, $current_time ); … … 1449 1441 * @param int|string $last_activity_date The date of last activity. 1450 1442 * @param string $string A sprintf()-able statement of the form 'active %s'. 1451 *1452 1443 * @return string $last_active A string of the form '3 years ago'. 1453 1444 */ 1454 1445 function bp_core_get_last_activity( $last_activity_date = '', $string = '' ) { 1455 1446 1456 // Setup a default string if none was passed 1447 // Setup a default string if none was passed. 1457 1448 $string = empty( $string ) 1458 ? '%s' // Gettext placeholder 1449 ? '%s' // Gettext placeholder. 1459 1450 : $string; 1460 1451 1461 // Use the string if a last activity date was passed 1452 // Use the string if a last activity date was passed. 1462 1453 $last_active = empty( $last_activity_date ) 1463 1454 ? __( 'Not recently active', 'buddypress' ) … … 1499 1490 * 1500 1491 * @param string|bool $key The usermeta meta_key. 1501 *1502 1492 * @return string $key The usermeta meta_key. 1503 1493 */ … … 1529 1519 * @param string $key The meta key to retrieve. 1530 1520 * @param bool $single Whether to return a single value. 1531 *1532 1521 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single 1533 * is true.1522 * is true. 1534 1523 */ 1535 1524 function bp_get_user_meta( $user_id, $key, $single = false ) { … … 1553 1542 * @param mixed $value Metadata value. 1554 1543 * @param mixed $prev_value Optional. Previous value to check before removing. 1555 *1556 1544 * @return bool False on failure, true on success. 1557 1545 */ … … 1575 1563 * @param string $key The meta key to delete. 1576 1564 * @param mixed $value Optional. Metadata value. 1577 *1578 1565 * @return bool False for failure. True for success. 1579 1566 */ … … 1591 1578 function bp_embed_init() { 1592 1579 1593 // Get BuddyPress 1580 // Get BuddyPress. 1594 1581 $bp = buddypress(); 1595 1582 … … 1709 1696 * obeys {@link force_ssl_admin()} and {@link is_ssl()}. 'http' 1710 1697 * or 'https' can be passed to force those schemes. 1711 *1712 1698 * @return string Admin url link with optional path appended. 1713 1699 */ 1714 1700 function bp_get_admin_url( $path = '', $scheme = 'admin' ) { 1715 1701 1716 // Links belong in network admin 1702 // Links belong in network admin. 1717 1703 if ( bp_core_do_network_admin() ) { 1718 1704 $url = network_admin_url( $path, $scheme ); 1719 1705 1720 // Links belong in site admin 1706 // Links belong in site admin. 1721 1707 } else { 1722 1708 $url = admin_url( $path, $scheme ); … … 1743 1729 function bp_core_do_network_admin() { 1744 1730 1745 // Default 1731 // Default. 1746 1732 $retval = bp_is_network_activated(); 1747 1733 … … 1793 1779 * 1794 1780 * @param int $blog_id Optional. Default: the ID of the current blog. 1795 *1796 1781 * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id(). 1797 1782 */ 1798 1783 function bp_is_root_blog( $blog_id = 0 ) { 1799 1784 1800 // Assume false 1785 // Assume false. 1801 1786 $is_root_blog = false; 1802 1787 1803 // Use current blog if no ID is passed 1788 // Use current blog if no ID is passed. 1804 1789 if ( empty( $blog_id ) || ! is_int( $blog_id ) ) { 1805 1790 $blog_id = get_current_blog_id(); 1806 1791 } 1807 1792 1808 // Compare to root blog ID 1793 // Compare to root blog ID. 1809 1794 if ( bp_get_root_blog_id() === $blog_id ) { 1810 1795 $is_root_blog = true; … … 1876 1861 function bp_is_multiblog_mode() { 1877 1862 1878 // Setup some default values 1863 // Setup some default values. 1879 1864 $retval = false; 1880 1865 $is_multisite = is_multisite(); … … 1882 1867 $is_multiblog = defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG; 1883 1868 1884 // Multisite, Network Activated, and Specifically Multiblog 1869 // Multisite, Network Activated, and Specifically Multiblog. 1885 1870 if ( $is_multisite && $network_active && $is_multiblog ) { 1886 1871 $retval = true; 1887 1872 1888 // Multisite, but not network activated 1873 // Multisite, but not network activated. 1889 1874 } elseif ( $is_multisite && ! $network_active ) { 1890 1875 $retval = true; … … 1915 1900 function bp_is_network_activated() { 1916 1901 1917 // Default to is_multisite() 1902 // Default to is_multisite(). 1918 1903 $retval = is_multisite(); 1919 1904 1920 // Check the sitewide plugins array 1905 // Check the sitewide plugins array. 1921 1906 $base = buddypress()->basename; 1922 1907 $plugins = get_site_option( 'active_sitewide_plugins' ); 1923 1908 1924 // Override is_multisite() if not network activated 1909 // Override is_multisite() if not network activated. 1925 1910 if ( ! is_array( $plugins ) || ! isset( $plugins[ $base ] ) ) { 1926 1911 $retval = false; … … 2056 2041 * @param string $action Action nonce. 2057 2042 * @param string $query_arg Where to look for nonce in $_REQUEST. 2058 *2059 2043 * @return bool True if the nonce is verified, otherwise false. 2060 2044 */ 2061 2045 function bp_verify_nonce_request( $action = '', $query_arg = '_wpnonce' ) { 2062 2046 2063 /* *Home URL **************************************************************/2047 /* Home URL **************************************************************/ 2064 2048 2065 2049 // Parse home_url() into pieces to remove query-strings, strange characters, … … 2067 2051 $parsed_home = parse_url( home_url( '/', ( is_ssl() ? 'https' : 'http' ) ) ); 2068 2052 2069 // Maybe include the port, if it's included in home_url() 2053 // Maybe include the port, if it's included in home_url(). 2070 2054 if ( isset( $parsed_home['port'] ) ) { 2071 2055 $parsed_host = $parsed_home['host'] . ':' . $parsed_home['port']; … … 2074 2058 } 2075 2059 2076 // Set the home URL for use in comparisons 2060 // Set the home URL for use in comparisons. 2077 2061 $home_url = trim( strtolower( $parsed_home['scheme'] . '://' . $parsed_host . $parsed_home['path'] ), '/' ); 2078 2062 2079 /* *Requested URL *********************************************************/2080 2081 // Maybe include the port, if it's included in home_url() 2063 /* Requested URL *********************************************************/ 2064 2065 // Maybe include the port, if it's included in home_url(). 2082 2066 if ( isset( $parsed_home['port'] ) && false === strpos( $_SERVER['HTTP_HOST'], ':' ) ) { 2083 2067 $request_host = $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT']; … … 2086 2070 } 2087 2071 2088 // Build the currently requested URL 2072 // Build the currently requested URL. 2089 2073 $scheme = is_ssl() ? 'https://' : 'http://'; 2090 2074 $requested_url = strtolower( $scheme . $request_host . $_SERVER['REQUEST_URI'] ); 2091 2075 2092 /* *Look for match ********************************************************/2076 /* Look for match ********************************************************/ 2093 2077 2094 2078 /** … … 2103 2087 $matched_url = apply_filters( 'bp_verify_nonce_request_url', $requested_url ); 2104 2088 2105 // Check the nonce 2089 // Check the nonce. 2106 2090 $result = isset( $_REQUEST[$query_arg] ) ? wp_verify_nonce( $_REQUEST[$query_arg], $action ) : false; 2107 2091 2108 // Nonce check failed 2092 // Nonce check failed. 2109 2093 if ( empty( $result ) || empty( $action ) || ( strpos( $matched_url, $home_url ) !== 0 ) ) { 2110 2094 $result = false; … … 2130 2114 * 2131 2115 * @since 1.9.0 2116 * 2132 2117 * @return bool 2133 2118 */ … …