Changeset 10163
- Timestamp:
- 10/01/2015 04:18:13 AM (9 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-actions.php
r10140 r10163 20 20 * The function will delete the active avatar for a user. 21 21 * 22 * @package BuddyPress Xprofile23 22 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user. 24 23 * @uses add_action() Runs a specific function for an action when it fires. … … 30 29 } 31 30 32 // Check the nonce 31 // Check the nonce. 33 32 check_admin_referer( 'bp_delete_avatar_link' ); 34 33 … … 48 47 49 48 /** 50 * Handles the saving of xprofile field visibilities 49 * Handles the saving of xprofile field visibilities. 51 50 * 52 51 * @since 1.9.0 … … 54 53 function bp_xprofile_action_settings() { 55 54 56 // Bail if not a POST action 55 // Bail if not a POST action. 57 56 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 58 57 return; 59 58 } 60 59 61 // Bail if no submit action 60 // Bail if no submit action. 62 61 if ( ! isset( $_POST['xprofile-settings-submit'] ) ) { 63 62 return; 64 63 } 65 64 66 // Bail if not in settings 65 // Bail if not in settings. 67 66 if ( ! bp_is_user_settings_profile() ) { 68 67 return; … … 75 74 } 76 75 77 // Nonce check 76 // Nonce check. 78 77 check_admin_referer( 'bp_xprofile_settings' ); 79 78 … … 87 86 /** Save ******************************************************************/ 88 87 89 // Only save if there are field ID's being posted 88 // Only save if there are field ID's being posted. 90 89 if ( ! empty( $_POST['field_ids'] ) ) { 91 90 92 // Get the POST'ed field ID's 91 // Get the POST'ed field ID's. 93 92 $posted_field_ids = explode( ',', $_POST['field_ids'] ); 94 93 … … 104 103 } 105 104 106 // Save the visibility settings 105 // Save the visibility settings. 107 106 foreach ( $posted_field_ids as $field_id ) { 108 107 … … 126 125 do_action( 'bp_xprofile_settings_after_save' ); 127 126 128 // Redirect to the root domain 127 // Redirect to the root domain. 129 128 bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/profile' ); 130 129 } -
trunk/src/bp-xprofile/bp-xprofile-activity.php
r10140 r10163 14 14 15 15 /** 16 * Register the activity actions for the Extended Profile component 17 * 18 * @since 1.0.0 19 * 20 * @uses bp_activity_set_action() To setup the individual actions 16 * Register the activity actions for the Extended Profile component. 17 * 18 * @since 1.0.0 19 * 20 * @uses bp_activity_set_action() To setup the individual actions. 21 21 */ 22 22 function xprofile_register_activity_actions() { 23 23 24 // Register the activity stream actions for this component 24 // Register the activity stream actions for this component. 25 25 bp_activity_set_action( 26 // older avatar activity items use 'profile' for component 27 // see r4273 26 // Older avatar activity items use 'profile' for component. See r4273. 28 27 'profile', 29 28 'new_avatar', … … 56 55 * @since 2.0.0 57 56 * 58 * @param string $action Static activity action.57 * @param string $action Static activity action. 59 58 * @param object $activity Activity object. 59 * 60 60 * @return string 61 61 */ … … 64 64 $action = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink ); 65 65 66 // Legacy filter - pass $user_id instead of $activity 66 // Legacy filter - pass $user_id instead of $activity. 67 67 if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) { 68 68 $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id ); … … 85 85 * @since 2.0.0 86 86 * 87 * @param string $action Static activity action.87 * @param string $action Static activity action. 88 88 * @param object $activity Activity object. 89 * 89 90 * @return string 90 91 */ … … 111 112 /** 112 113 * Records activity for the logged in user within the profile component so that 113 * it will show in the users activity stream (if installed) 114 * 115 * @since 1.0.0 116 * 117 * @package BuddyPress 118 * @subpackage XProfileActivity 119 * @param string $args String containing all variables used after extract() call 120 * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity 114 * it will show in the users activity stream (if installed). 115 * 116 * @since 1.0.0 117 * 118 * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity. 119 * 120 * @param array|string $args String containing all variables used after bp_parse_args() call. 121 * 122 * @return array 121 123 */ 122 124 function xprofile_record_activity( $args = '' ) { 123 125 124 // Bail if activity component is not active 125 if ( ! bp_is_active( 'activity' ) ) { 126 return false; 127 } 128 129 // Parse the arguments 126 // Bail if activity component is not active. 127 if ( ! bp_is_active( 'activity' ) ) { 128 return false; 129 } 130 131 // Parse the arguments. 130 132 $r = bp_parse_args( $args, array( 131 133 'user_id' => bp_loggedin_user_id(), … … 146 148 /** 147 149 * Deletes activity for a user within the profile component so that it will be 148 * removed from the users activity stream and sitewide stream (if installed) 149 * 150 * @since 1.0.0 151 * 152 * @package BuddyPress XProfile 153 * @param string $args Containing all variables used after extract() call 150 * removed from the users activity stream and sitewide stream (if installed). 151 * 152 * @since 1.0.0 153 * 154 154 * @uses bp_activity_delete() Deletes an entry to the activity component tables 155 * for a specific activity 155 * for a specific activity. 156 * 157 * @param array|string $args Containing all variables used after bp_parse_args() call. 158 * 159 * @return bool 156 160 */ 157 161 function xprofile_delete_activity( $args = '' ) { 158 162 159 // Bail if activity component is not active 160 if ( ! bp_is_active( 'activity' ) ) { 161 return false; 162 } 163 164 // Parse the arguments 163 // Bail if activity component is not active. 164 if ( ! bp_is_active( 'activity' ) ) { 165 return false; 166 } 167 168 // Parse the arguments. 165 169 $r = bp_parse_args( $args, array( 166 170 'component' => buddypress()->profile->id 167 171 ), 'xprofile_delete_activity' ); 168 172 169 // Delete the activity item 173 // Delete the activity item. 170 174 bp_activity_delete_by_item_id( $r ); 171 175 } 172 176 173 177 /** 174 * Register an activity action for the Extended Profiles component 175 * 176 * @since 1.0.0 177 * 178 * @param string $key 179 * @param string $value 180 * @return bool True if success, false on failure 178 * Register an activity action for the Extended Profiles component. 179 * 180 * @since 1.0.0 181 * 182 * @param string $key Key. 183 * @param string $value Value. 184 * 185 * @return bool True if success, false on failure. 181 186 */ 182 187 function xprofile_register_activity_action( $key, $value ) { 183 188 184 // Bail if activity component is not active 189 // Bail if activity component is not active. 185 190 if ( ! bp_is_active( 'activity' ) ) { 186 191 return false; … … 203 208 * 204 209 * @since 1.0.0 205 * @since 2.3.4 Add new parameter to get the user id the avatar was set for 206 * 207 * @package BuddyPress XProfile 210 * @since 2.3.4 Add new parameter to get the user id the avatar was set for. 211 * 208 212 * @uses bp_activity_add() Adds an entry to the activity component tables for a 209 213 * specific activity 210 214 * 211 * @param int $user_id The user id the avatar was set for 215 * @param int $user_id The user id the avatar was set for. 216 * 217 * @return bool 212 218 */ 213 219 function bp_xprofile_new_avatar_activity( $user_id = 0 ) { 214 220 215 // Bail if activity component is not active 221 // Bail if activity component is not active. 216 222 if ( ! bp_is_active( 'activity' ) ) { 217 223 return false; … … 231 237 $user_id = apply_filters( 'bp_xprofile_new_avatar_user_id', $user_id ); 232 238 233 // Add the activity 239 // Add the activity. 234 240 bp_activity_add( array( 235 241 'user_id' => $user_id, … … 245 251 * @since 2.0.0 246 252 * 247 * @param int $user_id ID of the user who has updated his profile. 248 * @param array $field_ids IDs of the fields submitted. 249 * @param bool $errors True if validation or saving errors occurred, otherwise 250 * false. 251 * @param array $old_values Pre-save xprofile field values and visibility 252 * levels. 253 * @param array $new_values Post-save xprofile field values and visibility 254 * levels. 253 * @param int $user_id ID of the user who has updated his profile. 254 * @param array $field_ids IDs of the fields submitted. 255 * @param bool $errors True if validation or saving errors occurred, otherwise false. 256 * @param array $old_values Pre-save xprofile field values and visibility levels. 257 * @param array $new_values Post-save xprofile field values and visibility levels. 258 * 255 259 * @return bool True on success, false on failure. 256 260 */ 257 261 function bp_xprofile_updated_profile_activity( $user_id, $field_ids = array(), $errors = false, $old_values = array(), $new_values = array() ) { 258 262 259 // If there were errors, don't post 263 // If there were errors, don't post. 260 264 if ( ! empty( $errors ) ) { 261 265 return false; 262 266 } 263 267 264 // Bail if activity component is not active 268 // Bail if activity component is not active. 265 269 if ( ! bp_is_active( 'activity' ) ) { 266 270 return false; … … 268 272 269 273 // Don't post if there have been no changes, or if the changes are 270 // related solely to non-public fields 274 // related solely to non-public fields. 271 275 $public_changes = false; 272 276 foreach ( $new_values as $field_id => $new_value ) { 273 277 $old_value = isset( $old_values[ $field_id ] ) ? $old_values[ $field_id ] : ''; 274 278 275 // Don't register changes to private fields 279 // Don't register changes to private fields. 276 280 if ( empty( $new_value['visibility'] ) || ( 'public' !== $new_value['visibility'] ) ) { 277 281 continue; 278 282 } 279 283 280 // Don't register if there have been no changes 284 // Don't register if there have been no changes. 281 285 if ( $new_value === $old_value ) { 282 286 continue; 283 287 } 284 288 285 // Looks like we have public changes - no need to keep checking 289 // Looks like we have public changes - no need to keep checking. 286 290 $public_changes = true; 287 291 break; 288 292 } 289 293 290 // Bail if no public changes 294 // Bail if no public changes. 291 295 if ( empty( $public_changes ) ) { 292 296 return false; 293 297 } 294 298 295 // Throttle to one activity of this type per 2 hours 299 // Throttle to one activity of this type per 2 hours. 296 300 $existing = bp_activity_get( array( 297 301 'max' => 1, … … 303 307 ) ); 304 308 305 // Default throttle time is 2 hours. Filter to change (in seconds) 309 // Default throttle time is 2 hours. Filter to change (in seconds). 306 310 if ( ! empty( $existing['activities'] ) ) { 307 311 … … 317 321 $now = strtotime( bp_core_current_time() ); 318 322 319 // Bail if throttled 323 // Bail if throttled. 320 324 if ( ( $now - $then ) < $throttle_period ) { 321 325 return false; … … 323 327 } 324 328 325 // If we've reached this point, assemble and post the activity item 329 // If we've reached this point, assemble and post the activity item. 326 330 $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() ); 327 331 -
trunk/src/bp-xprofile/bp-xprofile-admin.php
r10140 r10163 14 14 * tables are set up. 15 15 * 16 * @ package BuddyPress XProfile17 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not18 * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area19 * @return 16 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not. 17 * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area. 18 * 19 * @return bool 20 20 */ 21 21 function xprofile_add_admin_menu() { 22 22 23 // Bail if current user cannot moderate community 23 // Bail if current user cannot moderate community. 24 24 if ( ! bp_current_user_can( 'bp_moderate' ) ) { 25 25 return false; … … 33 33 * Handles all actions for the admin area for creating, editing and deleting 34 34 * profile groups and fields. 35 * 36 * @param string $message Message to display. 37 * @param string $type Type of action to be displayed. 35 38 */ 36 39 function xprofile_admin( $message = '', $type = 'error' ) { … … 67 70 * @since 2.3.0 68 71 * 69 * @param string $message Feedback message 70 * @param string $type Feedback type 72 * @param string $message Feedback message. 73 * @param string $type Feedback type. 71 74 * 72 75 * @todo Improve error message output … … 74 77 function xprofile_admin_screen( $message = '', $type = 'error' ) { 75 78 76 // Validate type 79 // Validate type. 77 80 $type = preg_replace( '|[^a-z]|i', '', $type ); 78 81 79 // Get all of the profile groups & fields 82 // Get all of the profile groups & fields. 80 83 $groups = bp_xprofile_get_groups( array( 81 84 'fetch_fields' => true … … 176 179 foreach ( $group->fields as $field ) { 177 180 178 // Load the field 181 // Load the field. 179 182 $field = new BP_XProfile_Field( $field->id ); 180 183 … … 186 189 /** 187 190 * This function handles the WYSIWYG profile field 188 * display for the xprofile admin setup screen 191 * display for the xprofile admin setup screen. 189 192 */ 190 193 xprofile_admin_field( $field, $group, $class ); … … 196 199 <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p> 197 200 198 <?php endif; // end $group->fields?>201 <?php endif; // End $group->fields. ?> 199 202 200 203 </fieldset> … … 224 227 /** 225 228 * Handles the adding or editing of groups. 229 * 230 * @param int|null $group_id Group ID to manage. 226 231 */ 227 232 function xprofile_admin_manage_group( $group_id = null ) { 228 233 global $message, $type; 229 234 230 // Get the field group 235 // Get the field group. 231 236 $group = new BP_XProfile_Group( $group_id ); 232 237 233 // Updating 238 // Updating. 234 239 if ( isset( $_POST['save_group'] ) ) { 235 240 236 // Validate $_POSTed data 241 // Validate $_POSTed data. 237 242 if ( BP_XProfile_Group::admin_validate() ) { 238 243 239 // Set the group name 244 // Set the group name. 240 245 $group->name = $_POST['group_name']; 241 246 242 // Set the group description 247 // Set the group description. 243 248 if ( ! empty( $_POST['group_description'] ) ) { 244 249 $group->description = $_POST['group_description']; … … 247 252 } 248 253 249 // Attempt to save the field group 254 // Attempt to save the field group. 250 255 if ( false === $group->save() ) { 251 256 $message = __( 'There was an error saving the group. Please try again.', 'buddypress' ); 252 257 $type = 'error'; 253 258 254 // Save successful 259 // Save successful. 255 260 } else { 256 261 $message = __( 'The group was saved successfully.', 'buddypress' ); … … 285 290 /** 286 291 * Handles the deletion of profile data groups. 292 * 293 * @param int $group_id ID of the group to delete. 287 294 */ 288 295 function xprofile_admin_delete_group( $group_id ) { … … 314 321 /** 315 322 * Handles the adding or editing of profile field data for a user. 323 * 324 * @param int $group_id ID of the group. 325 * @param int|null $field_id ID of the field being managed. 316 326 */ 317 327 function xprofile_admin_manage_field( $group_id, $field_id = null ) { … … 371 381 } 372 382 373 // Validate default visibility 383 // Validate default visibility. 374 384 if ( ! empty( $_POST['default-visibility'] ) && in_array( $_POST['default-visibility'], wp_list_pluck( bp_xprofile_get_visibility_levels(), 'id' ) ) ) { 375 385 bp_xprofile_update_field_meta( $field_id, 'default_visibility', $_POST['default-visibility'] ); 376 386 } 377 387 378 // Validate custom visibility 388 // Validate custom visibility. 379 389 if ( ! empty( $_POST['allow-custom-visibility'] ) && in_array( $_POST['allow-custom-visibility'], array( 'allowed', 'disabled' ) ) ) { 380 390 bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility'] ); 381 391 } 382 392 383 // Validate signup 393 // Validate signup. 384 394 if ( ! empty( $_POST['signup-position'] ) ) { 385 395 bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] ); … … 413 423 414 424 /** 415 * Handles the deletion of a profile field (or field option) 425 * Handles the deletion of a profile field (or field option). 416 426 * 417 427 * @since 1.0.0 418 * @global string $message The feedback message to show 419 * @global $type The type of feedback message to show 420 * @param int $field_id The field to delete 421 * @param string $field_type The type of field being deleted 422 * @param bool $delete_data Should the field data be deleted too? 428 * @global string $message The feedback message to show. 429 * @global $type The type of feedback message to show. 430 * 431 * @param int $field_id The field to delete. 432 * @param string $field_type The type of field being deleted. 433 * @param bool $delete_data Should the field data be deleted too. 423 434 */ 424 435 function xprofile_admin_delete_field( $field_id, $field_type = 'field', $delete_data = false ) { 425 436 global $message, $type; 426 437 427 // Switch type to 'option' if type is not 'field' 428 // @todo trust this param 438 // Switch type to 'option' if type is not 'field'. 439 // @todo trust this param. 429 440 $field_type = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' ); 430 441 $field = new BP_XProfile_Field( $field_id ); … … 452 463 453 464 /** 454 * Handles the ajax reordering of fields within a group 465 * Handles the ajax reordering of fields within a group. 455 466 */ 456 467 function xprofile_ajax_reorder_fields() { 457 468 458 // Check the nonce 469 // Check the nonce. 459 470 check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); 460 471 … … 474 485 475 486 /** 476 * Handles the reordering of field groups 487 * Handles the reordering of field groups. 477 488 */ 478 489 function xprofile_ajax_reorder_field_groups() { 479 490 480 // Check the nonce 491 // Check the nonce. 481 492 check_admin_referer( 'bp_reorder_groups', '_wpnonce_reorder_groups' ); 482 493 … … 494 505 495 506 /** 496 * Handles the WYSIWYG display of each profile field on the edit screen 507 * Handles the WYSIWYG display of each profile field on the edit screen. 508 * 509 * @param object $admin_field Admin field. 510 * @param object $admin_group Admin group object. 511 * @param string $class Classes to append to output. 497 512 */ 498 513 function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { … … 584 599 * Print <option> elements containing the xprofile field types. 585 600 * 586 * @param string $select_field_type The name of the field type that should be selected. Will defaults to "textbox" if NULL is passed.587 601 * @since 2.0.0 602 * 603 * @param string $select_field_type The name of the field type that should be selected. 604 * Will defaults to "textbox" if NULL is passed. 588 605 */ 589 606 function bp_xprofile_admin_form_field_types( $select_field_type ) { … … 594 611 } 595 612 596 // Sort each field type into its category 613 // Sort each field type into its category. 597 614 foreach ( bp_xprofile_get_field_types() as $field_name => $field_class ) { 598 615 $field_type_obj = new $field_class; 599 616 $the_category = $field_type_obj->category; 600 617 601 // Fallback to a catch-all if category not set 618 // Fallback to a catch-all if category not set. 602 619 if ( ! $the_category ) { 603 620 $the_category = _x( 'Other', 'xprofile field type category', 'buddypress' ); … … 611 628 } 612 629 613 // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :(( 630 // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :((. 614 631 uksort( $categories, 'strnatcmp' ); 615 632 616 // Loop through each category and output form <options> 633 // Loop through each category and output form <options>. 617 634 foreach ( $categories as $category => $fields ) { 618 printf( '<optgroup label="%1$s">', esc_attr( $category ) ); // Already i18n'd in each profile type class 619 620 // Sort these fields types alphabetically 635 printf( '<optgroup label="%1$s">', esc_attr( $category ) ); // Already i18n'd in each profile type class. 636 637 // Sort these fields types alphabetically. 621 638 uasort( $fields, create_function( '$a, $b', 'return strnatcmp( $a[1]->name, $b[1]->name );' ) ); 622 639 … … 633 650 634 651 if ( ! class_exists( 'BP_XProfile_User_Admin' ) ) : 652 635 653 /** 636 654 * Load xProfile Profile admin area. 637 *638 * @package BuddyPress639 * @subpackage xProfileAdministration640 655 * 641 656 * @since 2.0.0 … … 649 664 * @since 2.0.0 650 665 * 651 * @uses buddypress() to get BuddyPress main instance 666 * @uses buddypress() to get BuddyPress main instance. 652 667 */ 653 668 public static function register_xprofile_user_admin() { 654 669 655 // Bail if not in admin 670 // Bail if not in admin. 656 671 if ( ! is_admin() ) { 657 672 return; … … 684 699 */ 685 700 private function setup_actions() { 686 // Enqueue scripts 701 // Enqueue scripts. 687 702 add_action( 'bp_members_admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 1 ); 688 703 689 // Register the metabox in Member's community admin profile 704 // Register the metabox in Member's community admin profile. 690 705 add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 ); 691 706 692 // Saves the profile actions for user ( avatar, profile fields ) 707 // Saves the profile actions for user ( avatar, profile fields ). 693 708 add_action( 'bp_members_admin_update_user', array( $this, 'user_admin_load' ), 10, 4 ); 694 709 } … … 699 714 * @access public 700 715 * @since 2.3.0 716 * 717 * @param int $screen_id Screen ID being displayed. 701 718 */ 702 719 public function enqueue_scripts( $screen_id ) { … … 710 727 711 728 /** 712 * Get Thickbox 729 * Get Thickbox. 713 730 * 714 731 * We cannot simply use add_thickbox() here as WordPress is not playing … … 720 737 wp_enqueue_script( 'media-upload' ); 721 738 722 // Get Avatar Uploader 739 // Get Avatar Uploader. 723 740 bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' ); 724 741 } … … 730 747 * @since 2.0.0 731 748 * 732 * @param int $user_idID of the user being edited.733 * @param string $screen_id Screen ID to load the metabox in.749 * @param int $user_id ID of the user being edited. 750 * @param string $screen_id Screen ID to load the metabox in. 734 751 * @param object $stats_metabox Context and priority for the stats metabox. 735 752 */ 736 753 public function register_metaboxes( $user_id = 0, $screen_id = '', $stats_metabox = null ) { 737 754 738 // Set the screen ID if none was passed 755 // Set the screen ID if none was passed. 739 756 if ( empty( $screen_id ) ) { 740 757 $screen_id = buddypress()->members->admin->user_page; 741 758 } 742 759 743 // Setup a new metabox class if none was passed 760 // Setup a new metabox class if none was passed. 744 761 if ( empty( $stats_metabox ) ) { 745 762 $stats_metabox = new StdClass(); 746 763 } 747 764 748 // Moving the Stats Metabox 765 // Moving the Stats Metabox. 749 766 $stats_metabox->context = 'side'; 750 767 $stats_metabox->priority = 'low'; 751 768 752 // Each Group of fields will have his own metabox 769 // Each Group of fields will have his own metabox. 753 770 $profile_args = array( 754 771 'fetch_fields' => false, … … 758 775 if ( ! bp_is_user_spammer( $user_id ) && bp_has_profile( $profile_args ) ) { 759 776 760 // Loop through field groups and add a metabox for each one 777 // Loop through field groups and add a metabox for each one. 761 778 while ( bp_profile_groups() ) : bp_the_profile_group(); 762 779 add_meta_box( … … 771 788 endwhile; 772 789 773 // If member is already a spammer, show a generic metabox 790 // If member is already a spammer, show a generic metabox. 774 791 } else { 775 792 add_meta_box( … … 784 801 785 802 if ( buddypress()->avatar->show_avatars ) { 786 // Avatar Metabox 803 // Avatar Metabox. 787 804 add_meta_box( 788 805 'bp_xprofile_user_admin_avatar', … … 804 821 * @access public 805 822 * @since 2.0.0 823 * 824 * @param string $doaction Action being run. 825 * @param int $user_id ID for the user whose profile is being saved. 826 * @param array $request Request being made. 827 * @param string $redirect_to Where to redirect user to. 806 828 */ 807 829 public function user_admin_load( $doaction = '', $user_id = 0, $request = array(), $redirect_to = '' ) { 808 830 809 // Eventually delete avatar 831 // Eventually delete avatar. 810 832 if ( 'delete_avatar' === $doaction ) { 811 833 … … 822 844 bp_core_redirect( $redirect_to ); 823 845 824 // Update profile fields 846 // Update profile fields. 825 847 } elseif ( isset( $_POST['field_ids'] ) ) { 826 848 827 // Check the nonce 849 // Check the nonce. 828 850 check_admin_referer( 'edit-bp-profile_' . $user_id ); 829 851 830 // Check we have field ID's 852 // Check we have field ID's. 831 853 if ( empty( $_POST['field_ids'] ) ) { 832 854 $redirect_to = add_query_arg( 'error', '1', $redirect_to ); … … 846 868 $merge_ids = join( ',', $_POST['field_ids'] ); 847 869 848 // Explode the posted field IDs into an array so we know which fields have been submitted 870 // Explode the posted field IDs into an array so we know which fields have been submitted. 849 871 $posted_field_ids = wp_parse_id_list( $merge_ids ); 850 872 $is_required = array(); 851 873 852 // Loop through the posted fields formatting any datebox values then validate the field 874 // Loop through the posted fields formatting any datebox values then validate the field. 853 875 foreach ( (array) $posted_field_ids as $field_id ) { 854 876 if ( ! isset( $_POST['field_' . $field_id ] ) ) { 855 877 if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) { 856 878 857 // Concatenate the values 879 // Concatenate the values. 858 880 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; 859 881 860 // Turn the concatenated value into a timestamp 882 // Turn the concatenated value into a timestamp. 861 883 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); 862 884 } … … 870 892 } 871 893 872 // Set the errors var 894 // Set the errors var. 873 895 $errors = false; 874 896 … … 896 918 } 897 919 898 // Save the visibility level 920 // Save the visibility level. 899 921 $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public'; 900 922 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); … … 912 934 do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors ); 913 935 914 // Set the feedback messages 936 // Set the feedback messages. 915 937 if ( ! empty( $errors ) ) { 916 938 $redirect_to = add_query_arg( 'error', '3', $redirect_to ); … … 930 952 * 931 953 * @param WP_User $user The WP_User object for the user being edited. 954 * @param array $args Aray of arguments for metaboxes. 932 955 */ 933 956 public function user_admin_profile_metaboxes( $user = null, $args = array() ) { 934 957 935 // Bail if no user ID 958 // Bail if no user ID. 936 959 if ( empty( $user->ID ) ) { 937 960 return; … … 943 966 ), 'bp_xprofile_user_admin_profile_loop_args' ); 944 967 945 // We really need these args 968 // We really need these args. 946 969 if ( empty( $r['profile_group_id'] ) || empty( $r['user_id'] ) ) { 947 970 return; 948 971 } 949 972 950 // Bail if no profile fields are available 973 // Bail if no profile fields are available. 951 974 if ( ! bp_has_profile( $r ) ) { 952 975 return; 953 976 } 954 977 955 // Loop through profile groups & fields 978 // Loop through profile groups & fields. 956 979 while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 957 980 … … 1024 1047 </div> 1025 1048 1026 <?php endwhile; // bp_profile_fields()?>1027 1028 <?php endwhile; // bp_profile_groups1049 <?php endwhile; // End bp_profile_fields(). ?> 1050 1051 <?php endwhile; // End bp_profile_groups. 1029 1052 } 1030 1053 … … 1084 1107 <?php endif; 1085 1108 1086 // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported 1109 // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported. 1087 1110 if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && bp_attachments_is_wp_version_supported() ) : ?> 1088 1111 <a href="#TB_inline?width=800px&height=400px&inlineId=bp-xprofile-avatar-editor" title="<?php esc_attr_e( 'Edit Profile Photo', 'buddypress' );?>" class="thickbox bp-xprofile-avatar-user-edit"><?php esc_html_e( 'Edit Profile Photo', 'buddypress' ); ?></a> … … 1097 1120 1098 1121 } 1099 endif; // class_exists check1100 1101 // Load the xprofile user admin 1122 endif; // End class_exists check. 1123 1124 // Load the xprofile user admin. 1102 1125 add_action( 'bp_init', array( 'BP_XProfile_User_Admin', 'register_xprofile_user_admin' ), 11 ); -
trunk/src/bp-xprofile/bp-xprofile-cache.php
r10140 r10163 18 18 * @since 2.2.0 19 19 * 20 * @param int $user_id User ID to check 20 * @param int $user_id User ID to check. 21 21 * @param array $field_ids XProfile field IDs. 22 * 22 23 * @return array 23 24 */ … … 51 52 * 52 53 * @param array $object_ids Multi-dimensional array of object_ids, keyed by 53 * object type ('group', 'field', 'data') 54 * object type ('group', 'field', 'data'). 55 * 56 * @return bool 54 57 */ 55 58 function bp_xprofile_update_meta_cache( $object_ids = array() ) { 56 59 global $wpdb; 57 60 58 // Bail if no objects 61 // Bail if no objects. 59 62 if ( empty( $object_ids ) ) { 60 63 return false; … … 63 66 $bp = buddypress(); 64 67 65 // Define the array where uncached object IDs will be stored 68 // Define the array where uncached object IDs will be stored. 66 69 $uncached_object_ids = array( 67 70 'group', … … 70 73 ); 71 74 72 // Define the cache groups for the 3 types of XProfile metadata 75 // Define the cache groups for the 3 types of XProfile metadata. 73 76 $cache_groups = array( 74 77 'group' => 'xprofile_group_meta', … … 77 80 ); 78 81 79 // No reason to query yet 82 // No reason to query yet. 80 83 $do_query = false; 81 84 82 // Loop through object types and look for uncached data 85 // Loop through object types and look for uncached data. 83 86 foreach ( $uncached_object_ids as $object_type ) { 84 87 85 // Skip if empty object type 88 // Skip if empty object type. 86 89 if ( empty( $object_ids[ $object_type ] ) ) { 87 90 continue; 88 91 } 89 92 90 // Sanitize $object_ids passed to the function 93 // Sanitize $object_ids passed to the function. 91 94 $object_type_ids = wp_parse_id_list( $object_ids[ $object_type ] ); 92 95 93 // Get non-cached IDs for each object type 96 // Get non-cached IDs for each object type. 94 97 $uncached_object_ids[ $object_type ] = bp_get_non_cached_ids( $object_type_ids, $cache_groups[ $object_type ] ); 95 98 96 // Set the flag to do the meta query 99 // Set the flag to do the meta query. 97 100 if ( ! empty( $uncached_object_ids[ $object_type ] ) && ( false === $do_query ) ) { 98 101 $do_query = true; … … 100 103 } 101 104 102 // Bail if no uncached items 105 // Bail if no uncached items. 103 106 if ( false === $do_query ) { 104 107 return; 105 108 } 106 109 107 // Setup where conditions for query 110 // Setup where conditions for query. 108 111 $where_sql = ''; 109 112 $where_conditions = array(); 110 113 111 // Loop through uncached objects and prepare to query for them 114 // Loop through uncached objects and prepare to query for them. 112 115 foreach ( $uncached_object_ids as $otype => $oids ) { 113 116 114 // Skip empty object IDs 117 // Skip empty object IDs. 115 118 if ( empty( $oids ) ) { 116 119 continue; 117 120 } 118 121 119 // Compile WHERE query conditions for uncached metadata 122 // Compile WHERE query conditions for uncached metadata. 120 123 $oids_sql = implode( ',', wp_parse_id_list( $oids ) ); 121 124 $where_conditions[] = $wpdb->prepare( "( object_type = %s AND object_id IN ({$oids_sql}) )", $otype ); 122 125 } 123 126 124 // Bail if no where conditions 127 // Bail if no where conditions. 125 128 if ( empty( $where_conditions ) ) { 126 129 return; 127 130 } 128 131 129 // Setup the WHERE query part 132 // Setup the WHERE query part. 130 133 $where_sql = implode( " OR ", $where_conditions ); 131 134 132 // Attempt to query meta values 135 // Attempt to query meta values. 133 136 $meta_list = $wpdb->get_results( "SELECT object_id, object_type, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE {$where_sql}" ); 134 137 135 // Bail if no results found 138 // Bail if no results found. 136 139 if ( empty( $meta_list ) || is_wp_error( $meta_list ) ) { 137 140 return; 138 141 } 139 142 140 // Setup empty cache array 143 // Setup empty cache array. 141 144 $cache = array(); 142 145 143 // Loop through metas 146 // Loop through metas. 144 147 foreach ( $meta_list as $meta ) { 145 148 $oid = $meta->object_id; … … 148 151 $ovalue = $meta->meta_value; 149 152 150 // Force subkeys to be array type 153 // Force subkeys to be array type. 151 154 if ( ! isset( $cache[ $otype ][ $oid ] ) || ! is_array( $cache[ $otype ][ $oid ] ) ) { 152 155 $cache[ $otype ][ $oid ] = array(); … … 157 160 } 158 161 159 // Add to the cache array 162 // Add to the cache array. 160 163 $cache[ $otype ][ $oid ][ $okey ][] = maybe_unserialize( $ovalue ); 161 164 } 162 165 163 // Loop through data and cache to the appropriate object 166 // Loop through data and cache to the appropriate object. 164 167 foreach ( $cache as $object_type => $object_caches ) { 165 168 166 // Determine the cache group for this data 169 // Determine the cache group for this data. 167 170 $cache_group = $cache_groups[ $object_type ]; 168 171 169 // Loop through objects and cache appropriately 172 // Loop through objects and cache appropriately. 170 173 foreach ( $object_caches as $object_id => $object_cache ) { 171 174 wp_cache_set( $object_id, $object_cache, $cache_group ); … … 175 178 176 179 /** 177 * Clear cached XProfile field group data 180 * Clear cached XProfile field group data. 178 181 * 179 182 * @since 2.1.0 180 183 * 181 * @param object $group_obj 184 * @param object $group_obj Groub object to clear. 182 185 */ 183 186 function xprofile_clear_profile_groups_object_cache( $group_obj ) { … … 189 192 190 193 /** 191 * Clear cached XProfile fullname data for user 194 * Clear cached XProfile fullname data for user. 192 195 * 193 196 * @since 2.1.0 194 197 * 195 * @param int $user_id ID of user whose fullname cache to delete 198 * @param int $user_id ID of user whose fullname cache to delete. 196 199 */ 197 200 function xprofile_clear_profile_data_object_cache( $user_id = 0 ) { … … 203 206 * Clear the fullname cache when field 1 is updated. 204 207 * 205 * xprofile_clear_profile_data_object_cache() will make this redundant in most 206 * cases, except where the field is updated directly with xprofile_set_field_data() 207 * 208 * @since 2.0.0 208 * The xprofile_clear_profile_data_object_cache() will make this redundant in most 209 * cases, except where the field is updated directly with xprofile_set_field_data(). 210 * 211 * @since 2.0.0 212 * 213 * @param object $data Data object to clear. 209 214 */ 210 215 function xprofile_clear_fullname_cache_on_profile_field_edit( $data ) { … … 220 225 * @since 2.0.0 221 226 * 222 * @param BP_XProfile_Field 227 * @param BP_XProfile_Field $field_obj Field object cache to delete. 223 228 */ 224 229 function xprofile_clear_profile_field_object_cache( $field_obj ) { 225 230 226 // Clear default visibility level cache 231 // Clear default visibility level cache. 227 232 wp_cache_delete( 'default_visibility_levels', 'bp_xprofile' ); 228 233 229 234 // Modified fields can alter parent group status, in particular when 230 235 // the group goes from empty to non-empty. Bust its cache, as well as 231 // the global 'all' cache 236 // the global 'all' cache. 232 237 wp_cache_delete( 'all', 'bp_xprofile_groups' ); 233 238 wp_cache_delete( $field_obj->group_id, 'bp_xprofile_groups' ); … … 251 256 * @since 2.0.0 252 257 * 253 * @param BP_XProfile_ProfileData $data_obj 258 * @param BP_XProfile_ProfileData $data_obj Field data object to delete. 254 259 */ 255 260 function xprofile_clear_profiledata_object_cache( $data_obj ) { … … 279 284 add_action( 'update_option_bp-xprofile-fullname-field-name', 'xprofile_clear_fullname_field_id_cache' ); 280 285 281 // List actions to clear super cached pages on, if super cache is installed 286 // List actions to clear super cached pages on, if super cache is installed. 282 287 add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' ); -
trunk/src/bp-xprofile/bp-xprofile-caps.php
r10140 r10163 12 12 13 13 /** 14 * Maps XProfile caps to built in WordPress caps 14 * Maps XProfile caps to built in WordPress caps. 15 15 * 16 16 * @since 1.6.0 17 17 * 18 * @param array $caps Capabilities for meta capability 19 * @param string $cap Capability name 20 * @param int $user_id User id 21 * @param mixed $args Arguments 22 * @uses get_post() To get the post 23 * @uses get_post_type_object() To get the post type object 24 * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and 25 * args 26 * @return array Actual capabilities for meta capability 18 * @param array $caps Capabilities for meta capability. 19 * @param string $cap Capability name. 20 * @param int $user_id User id. 21 * @param mixed $args Arguments. 22 * 23 * @uses get_post() To get the post. 24 * @uses get_post_type_object() To get the post type object. 25 * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and args. 26 * 27 * @return array Actual capabilities for meta capability. 27 28 */ 28 29 function bp_xprofile_map_meta_caps( $caps, $cap, $user_id, $args ) { 29 30 switch ( $cap ) { 30 31 case 'bp_xprofile_change_field_visibility' : 31 $caps = array( 'exist' ); // Must allow for logged-out users during registration 32 $caps = array( 'exist' ); // Must allow for logged-out users during registration. 32 33 33 // You may pass args manually: $field_id, $profile_user_id 34 // You may pass args manually: $field_id, $profile_user_id. 34 35 $field_id = isset( $args[0] ) ? (int)$args[0] : bp_get_the_profile_field_id(); 35 36 $profile_user_id = isset( $args[1] ) ? (int)$args[1] : bp_displayed_user_id(); 36 37 37 // Visibility on the fullname field is not editable 38 // Visibility on the fullname field is not editable. 38 39 if ( 1 == $field_id ) { 39 40 $caps[] = 'do_not_allow'; … … 47 48 } 48 49 49 // Friends don't let friends edit each other's visibility 50 // Friends don't let friends edit each other's visibility. 50 51 if ( $profile_user_id != bp_displayed_user_id() && !bp_current_user_can( 'bp_moderate' ) ) { 51 52 $caps[] = 'do_not_allow'; -
trunk/src/bp-xprofile/bp-xprofile-cssjs.php
r10140 r10163 11 11 12 12 /** 13 * Enqueue the CSS for XProfile admin styling 13 * Enqueue the CSS for XProfile admin styling. 14 14 * 15 15 * @since 1.1.0 … … 30 30 31 31 /** 32 * Enqueue the jQuery libraries for handling drag/drop/sort 32 * Enqueue the jQuery libraries for handling drag/drop/sort. 33 33 * 34 34 * @since 1.5.0 … … 49 49 // supports_options_field_types is a dynamic list of field 50 50 // types that support options, for use in showing/hiding the 51 // "please enter options for this field" section 51 // "please enter options for this field" section. 52 52 $strings = array( 53 53 'supports_options_field_types' => array(), -
trunk/src/bp-xprofile/bp-xprofile-filters.php
r10140 r10163 55 55 add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 ); 56 56 57 // Save field groups 57 // Save field groups. 58 58 add_filter( 'xprofile_group_name_before_save', 'wp_filter_kses' ); 59 59 add_filter( 'xprofile_group_description_before_save', 'wp_filter_kses' ); 60 60 61 // Save fields 61 // Save fields. 62 62 add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses' ); 63 63 add_filter( 'xprofile_field_type_before_save', 'wp_filter_kses' ); … … 69 69 add_filter( 'xprofile_field_can_delete_before_save', 'absint' ); 70 70 71 // Save field options 71 // Save field options. 72 72 add_filter( 'xprofile_field_options_before_save', 'bp_xprofile_sanitize_field_options' ); 73 73 add_filter( 'xprofile_field_default_before_save', 'bp_xprofile_sanitize_field_default' ); 74 74 75 75 /** 76 * Sanitize each field option name for saving to the database 76 * Sanitize each field option name for saving to the database. 77 77 * 78 78 * @since 2.3.0 79 79 * 80 * @param mixed $field_options 80 * @param mixed $field_options Options to sanitize. 81 * 81 82 * @return mixed 82 83 */ … … 90 91 91 92 /** 92 * Sanitize each field option default for saving to the database 93 * Sanitize each field option default for saving to the database. 93 94 * 94 95 * @since 2.3.0 95 96 * 96 * @param mixed $field_default 97 * @param mixed $field_default Field defaults to sanitize. 98 * 97 99 * @return mixed 98 100 */ … … 106 108 107 109 /** 108 * xprofile_filter_kses ( $content )109 *110 110 * Run profile field values through kses with filterable allowed tags. 111 111 * 112 * @param string $content 113 * @param object $data_obj The BP_XProfile_ProfileData object 112 * @param string $content Content to filter. 113 * @param object $data_obj The BP_XProfile_ProfileData object. 114 * 114 115 * @return string $content 115 116 */ … … 135 136 * Safely runs profile field data through kses and force_balance_tags. 136 137 * 137 * @param string $field_value 138 * @param int $field_id 139 * @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true 140 * @param object $data_obj The BP_XProfile_ProfileData object 138 * @param string $field_value Field value being santized. 139 * @param int $field_id Field ID being sanitized. 140 * @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true. 141 * @param object $data_obj The BP_XProfile_ProfileData object. 142 * 141 143 * @return string 142 144 */ 143 145 function xprofile_sanitize_data_value_before_save( $field_value, $field_id = 0, $reserialize = true, $data_obj = null ) { 144 146 145 // Return if empty 147 // Return if empty. 146 148 if ( empty( $field_value ) ) { 147 149 return $field_value; 148 150 } 149 151 150 // Value might be serialized 152 // Value might be serialized. 151 153 $field_value = maybe_unserialize( $field_value ); 152 154 153 // Filter single value 155 // Filter single value. 154 156 if ( !is_array( $field_value ) ) { 155 157 $kses_field_value = xprofile_filter_kses( $field_value, $data_obj ); … … 167 169 $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj ); 168 170 169 // Filter each array item independently 171 // Filter each array item independently. 170 172 } else { 171 173 $filtered_values = array(); … … 195 197 * 196 198 * @param string $field_value XProfile field_value to be filtered. 197 * @param string $field_type XProfile field_type to be filtered. 199 * @param string $field_type XProfile field_type to be filtered. 200 * 198 201 * @return string $field_value Filtered XProfile field_value. False on failure. 199 202 */ 200 203 function xprofile_filter_format_field_value( $field_value, $field_type = '' ) { 201 204 202 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731 205 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. 203 206 if ( ! isset( $field_value ) || empty( $field_value ) && ( '0' !== $field_value ) ) { 204 207 return false; … … 213 216 214 217 /** 215 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside a bp_has_profile() loop. 218 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside 219 * a bp_has_profile() loop. 216 220 * 217 221 * @since 2.1.0 218 222 * 219 * @param mixed $field_value Field value. 220 * @param string $field_type Field type. 223 * @param mixed $field_value Field value. 224 * @param string $field_type Field type. 225 * 221 226 * @return mixed 222 227 */ … … 236 241 237 242 /** 238 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched by xprofile_get_field_data(). 243 * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched 244 * by xprofile_get_field_data(). 239 245 * 240 246 * @since 2.1.0 241 247 * 242 248 * @param mixed $field_value Field value. 243 * @param int $field_id Field type. 249 * @param int $field_id Field type. 250 * 251 * @return string 244 252 */ 245 253 function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) { … … 253 261 * @since 2.1.0 254 262 * 255 * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate256 * filter.257 * @param BP_XProfile_Field $field Fieldobject.258 * @param BP_XProfile_Field_Type Field type object.263 * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate filter. 264 * @param BP_XProfile_Field $field Field object. 265 * @param BP_XProfile_Field_Type $field_type_obj Field type object. 266 * 259 267 * @return mixed 260 268 */ … … 271 279 * to members search results out of them. 272 280 * 273 * - Not run on datebox field types 274 * - Not run on values without commas with less than 5 words 275 * - URL's are made clickable 281 * - Not run on datebox field types. 282 * - Not run on values without commas with less than 5 words. 283 * - URL's are made clickable. 276 284 * - To disable: remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 ); 277 285 * 278 286 * @since 1.1.0 279 287 * 280 * @param string $field_value 281 * @param string $field_type 288 * @param string $field_value Profile field data value. 289 * @param string $field_type Profile field type. 290 * 282 291 * @return string 283 292 */ … … 302 311 $new_values[] = make_clickable( $value ); 303 312 304 // Is not clickable 313 // Is not clickable. 305 314 } else { 306 315 307 // More than 5 spaces 316 // More than 5 spaces. 308 317 if ( count( explode( ' ', $value ) ) > 5 ) { 309 318 $new_values[] = $value; 310 319 311 // Less than 5 spaces 320 // Less than 5 spaces. 312 321 } else { 313 322 $search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() ); … … 324 333 325 334 /** 326 * Ensures that BP data appears in comments array 335 * Ensures that BP data appears in comments array. 327 336 * 328 337 * This filter loops through the comments return by a normal WordPress request 329 * and swaps out user data with BP xprofile data, where available 330 * 331 * @param array $comments 332 * @param int $post_id 338 * and swaps out user data with BP xprofile data, where available. 339 * 340 * @param array $comments Comments to filter in. 341 * @param int $post_id Post ID the comments are for. 342 * 333 343 * @return array $comments 334 344 */ 335 345 function xprofile_filter_comments( $comments, $post_id = 0 ) { 336 346 337 // Locate comment authors with WP accounts 347 // Locate comment authors with WP accounts. 338 348 foreach( (array) $comments as $comment ) { 339 349 if ( $comment->user_id ) { … … 342 352 } 343 353 344 // If none are found, just return the comments array 354 // If none are found, just return the comments array. 345 355 if ( empty( $user_ids ) ) { 346 356 return $comments; 347 357 } 348 358 349 // Pull up the xprofile fullname of each commenter 359 // Pull up the xprofile fullname of each commenter. 350 360 if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) { 351 361 foreach( (array) $fullnames as $user_id => $user_fullname ) { … … 354 364 } 355 365 356 // Loop through and match xprofile fullname with commenters 366 // Loop through and match xprofile fullname with commenters. 357 367 foreach( (array) $comments as $i => $comment ) { 358 368 if ( ! empty( $comment->user_id ) ) { … … 368 378 369 379 /** 370 * Filter BP_User_Query::populate_extras to override each queries users fullname 380 * Filter BP_User_Query::populate_extras to override each queries users fullname. 371 381 * 372 382 * @since 1.7.0 373 383 * 374 * @param BP_User_Query $user_query 375 * @param string $user_ids_sql384 * @param BP_User_Query $user_query User query to filter. 385 * @param string $user_ids_sql SQL statement to use. 376 386 */ 377 387 function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql = '' ) { … … 383 393 $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids ); 384 394 385 // Loop through names and override each user's fullname 395 // Loop through names and override each user's fullname. 386 396 foreach ( $user_id_names as $user_id => $user_fullname ) { 387 397 if ( isset( $user_query->results[ $user_id ] ) ) { … … 397 407 * @since 2.2.0 398 408 * 399 * @param BP_User_Query User query object.409 * @param BP_User_Query $q User query object. 400 410 */ 401 411 function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query $q ) { 402 412 403 // Bail if no `xprofile_query` clause 413 // Bail if no `xprofile_query` clause. 404 414 if ( empty( $q->query_vars['xprofile_query'] ) ) { 405 415 return; … … 424 434 * 425 435 * @param string $q SQL query. 436 * 426 437 * @return string 427 438 */ … … 439 450 $q = preg_replace( $quoted_regex, '__QUOTE__', $q ); 440 451 441 // Get the first word of the command 452 // Get the first word of the command. 442 453 preg_match( '/^(\S+)/', $q, $first_word_matches ); 443 454 … … 446 457 } 447 458 448 // Get the field type 459 // Get the field type. 449 460 preg_match( '/xprofile_(group|field|data)_id/', $q, $matches ); 450 461 -
trunk/src/bp-xprofile/bp-xprofile-functions.php
r10140 r10163 25 25 * 26 26 * @param array $args See {@link BP_XProfile_Group::get()} for description of 27 * arguments. 27 * arguments. 28 * 28 29 * @return array $groups 29 30 */ … … 44 45 45 46 /** 46 * Insert a new profile field group 47 * Insert a new profile field group. 47 48 * 48 49 * @since 1.0.0 49 50 * 50 * @param type $args 51 * @param array|string $args Array of arguments for field group insertion. 52 * 51 53 * @return boolean 52 54 */ 53 55 function xprofile_insert_field_group( $args = '' ) { 54 56 55 // Parse the arguments 57 // Parse the arguments. 56 58 $r = bp_parse_args( $args, array( 57 59 'field_group_id' => false, … … 61 63 ), 'xprofile_insert_field_group' ); 62 64 63 // Bail if no group name 65 // Bail if no group name. 64 66 if ( empty( $r['name'] ) ) { 65 67 return false; 66 68 } 67 69 68 // Create new field group object, maybe using an existing ID 70 // Create new field group object, maybe using an existing ID. 69 71 $field_group = new BP_XProfile_Group( $r['field_group_id'] ); 70 72 $field_group->name = $r['name']; … … 76 78 77 79 /** 78 * Get a specific profile field group 80 * Get a specific profile field group. 79 81 * 80 82 * @since 1.0.0 81 83 * 82 * @param int $field_group_id 84 * @param int $field_group_id Field group ID to fetch. 85 * 83 86 * @return boolean|BP_XProfile_Group 84 87 */ 85 88 function xprofile_get_field_group( $field_group_id = 0 ) { 86 89 87 // Try to get a specific field group by ID 90 // Try to get a specific field group by ID. 88 91 $field_group = new BP_XProfile_Group( $field_group_id ); 89 92 90 // Bail if group was not found 93 // Bail if group was not found. 91 94 if ( empty( $field_group->id ) ) { 92 95 return false; 93 96 } 94 97 95 // Return field group 98 // Return field group. 96 99 return $field_group; 97 100 } 98 101 99 102 /** 100 * Delete a specific profile field group 103 * Delete a specific profile field group. 101 104 * 102 105 * @since 1.0.0 103 106 * 104 * @param int $field_group_id 107 * @param int $field_group_id Field group ID to delete. 108 * 105 109 * @return boolean 106 110 */ 107 111 function xprofile_delete_field_group( $field_group_id = 0 ) { 108 112 109 // Try to get a specific field group by ID 113 // Try to get a specific field group by ID. 110 114 $field_group = xprofile_get_field_group( $field_group_id ); 111 115 112 // Bail if group was not found 116 // Bail if group was not found. 113 117 if ( false === $field_group ) { 114 118 return false; 115 119 } 116 120 117 // Return the results of trying to delete the field group 121 // Return the results of trying to delete the field group. 118 122 return $field_group->delete(); 119 123 } 120 124 121 125 /** 122 * Update the position of a specific profile field group 126 * Update the position of a specific profile field group. 123 127 * 124 128 * @since 1.0.0 125 129 * 126 * @param int $field_group_id 127 * @param int $position 128 * @return bool 130 * @param int $field_group_id Field group ID to update. 131 * @param int $position Field group position to update to. 132 * 133 * @return boolean 129 134 */ 130 135 function xprofile_update_field_group_position( $field_group_id = 0, $position = 0 ) { … … 132 137 } 133 138 134 135 139 /*** Field Management *********************************************************/ 136 140 … … 138 142 * Get details of all xprofile field types. 139 143 * 144 * @since 2.0.0 145 * 140 146 * @return array Key/value pairs (field type => class name). 141 * @since 2.0.0142 147 */ 143 148 function bp_xprofile_get_field_types() { … … 169 174 * Creates the specified field type object; used for validation and templating. 170 175 * 176 * @since 2.0.0 177 * 171 178 * @param string $type Type of profile field to create. See {@link bp_xprofile_get_field_types()} for default core values. 172 * @return object If field type unknown, returns BP_XProfile_Field_Type_Textarea. Otherwise returns an instance of the relevant child class of BP_XProfile_Field_Type. 173 * @since 2.0.0 179 * 180 * @return object $value If field type unknown, returns BP_XProfile_Field_Type_Textarea. 181 * Otherwise returns an instance of the relevant child class of BP_XProfile_Field_Type. 174 182 */ 175 183 function bp_xprofile_create_field_type( $type ) { … … 191 199 * Insert or update an xprofile field. 192 200 * 193 * @param array $args {201 * @param array|string $args { 194 202 * Array of arguments. 195 203 * @type int $field_id Optional. Pass the ID of an existing field to edit that field. … … 231 239 ) ); 232 240 233 // field_group_id is required241 // Field_group_id is required. 234 242 if ( empty( $r['field_group_id'] ) ) { 235 243 return false; … … 241 249 } 242 250 243 // Instantiate a new field object 251 // Instantiate a new field object. 244 252 if ( ! empty( $r['field_id'] ) ) { 245 253 $field = new BP_XProfile_Field( $r['field_id'] ); … … 277 285 } 278 286 279 280 287 /*** Field Data Management *****************************************************/ 288 281 289 282 290 /** … … 286 294 * each item in the array. 287 295 * 288 * @package BuddyPress Core 289 * @param mixed $field The ID of the field, or the $name of the field. 290 * @param int $user_id The ID of the user 296 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed. 297 * 298 * @param mixed $field The ID of the field, or the $name of the field. 299 * @param int $user_id The ID of the user. 291 300 * @param string $multi_format How should array data be returned? 'comma' if you want a 292 * comma-separated string; 'array' if you want an array 293 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.301 * comma-separated string; 'array' if you want an array. 302 * 294 303 * @return mixed The profile field data. 295 304 */ … … 342 351 return $data; 343 352 } 344 345 353 /** 346 354 * A simple function to set profile data for a specific field for a specific user. 347 355 * 348 * @package BuddyPress Core 349 * @param int|string $field The ID of the field, or the $name of the field. 350 * @param int|$user_id The ID of the user 351 * @param mixed $value The value for the field you want to set for the user. 352 * @param $is_required Whether or not the field is required 353 * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name. 356 * @uses xprofile_get_field_id_from_name() Gets the ID from the field based on the name. 357 * 358 * @param int|string $field The ID of the field, or the $name of the field. 359 * @param int $user_id The ID of the user. 360 * @param mixed $value The value for the field you want to set for the user. 361 * @param bool $is_required Whether or not the field is required. 362 * 354 363 * @return bool True on success, false on failure. 355 364 */ … … 378 387 * @since 2.1.0 379 388 * 380 * @param mixed $value Value passed to xprofile_set_field_data()381 * @param BP_XProfile_Field $fieldField object.389 * @param mixed $value Value passed to xprofile_set_field_data(). 390 * @param BP_XProfile_Field $field Field object. 382 391 * @param BP_XProfile_Field_Type $field_type_obj Field type object. 383 392 */ 384 393 $value = apply_filters( 'bp_xprofile_set_field_data_pre_validate', $value, $field, $field_type_obj ); 385 394 386 // Special-case support for integer 0 for the number field type 395 // Special-case support for integer 0 for the number field type. 387 396 if ( $is_required && ! is_integer( $value ) && $value !== '0' && ( empty( $value ) || ! is_array( $value ) && ! strlen( trim( $value ) ) ) ) { 388 397 return false; … … 399 408 } 400 409 401 // If the value is empty, then delete any field data that exists, unless the field is of a type where null values are semantically meaningful 410 // If the value is empty, then delete any field data that exists, unless the field is of a type 411 // where null values are semantically meaningful. 402 412 if ( empty( $value ) && ! is_integer( $value ) && $value !== '0' && ! $field_type_obj->accepts_null_value ) { 403 413 xprofile_delete_field_data( $field_id, $user_id ); … … 424 434 425 435 /** 426 * Set the visibility level for this field 427 * 428 * @param int $field_id The ID of the xprofile field 429 * @param int $user_id The ID of the user to whom the data belongs 430 * @param string $visibility_level 436 * Set the visibility level for this field. 437 * 438 * @param int $field_id The ID of the xprofile field. 439 * @param int $user_id The ID of the user to whom the data belongs. 440 * @param string $visibility_level What the visibity setting should be. 441 * 431 442 * @return bool True on success 432 443 */ … … 436 447 } 437 448 438 // Check against a whitelist 449 // Check against a whitelist. 439 450 $allowed_values = bp_xprofile_get_visibility_levels(); 440 451 if ( !array_key_exists( $visibility_level, $allowed_values ) ) { … … 442 453 } 443 454 444 // Stored in an array in usermeta 455 // Stored in an array in usermeta. 445 456 $current_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); 446 457 … … 461 472 * @param int $field_id The ID of the xprofile field. 462 473 * @param int $user_id The ID of the user to whom the data belongs. 474 * 463 475 * @return string 464 476 */ … … 473 485 $current_level = isset( $current_levels[ $field_id ] ) ? $current_levels[ $field_id ] : ''; 474 486 475 // Use the user's stored level, unless custom visibility is disabled 487 // Use the user's stored level, unless custom visibility is disabled. 476 488 $field = new BP_XProfile_Field( $field_id ); 477 489 if ( isset( $field->allow_custom_visibility ) && 'disabled' === $field->allow_custom_visibility ) { … … 490 502 function xprofile_delete_field_data( $field = '', $user_id = 0 ) { 491 503 492 // Get the field ID 504 // Get the field ID. 493 505 if ( is_numeric( $field ) ) { 494 506 $field_id = (int) $field; … … 497 509 } 498 510 499 // Bail if field or user ID are empty 511 // Bail if field or user ID are empty. 500 512 if ( empty( $field_id ) || empty( $user_id ) ) { 501 513 return false; 502 514 } 503 515 504 // Get the profile field data to delete 516 // Get the profile field data to delete. 505 517 $field = new BP_XProfile_ProfileData( $field_id, $user_id ); 506 518 507 // Delete the field data 519 // Delete the field data. 508 520 return $field->delete(); 509 521 } … … 512 524 $field = new BP_Xprofile_Field( $field_id ); 513 525 514 // Define locale variable(s) 526 // Define locale variable(s). 515 527 $retval = false; 516 528 517 // Super admins can skip required check 529 // Super admins can skip required check. 518 530 if ( bp_current_user_can( 'bp_moderate' ) && ! is_admin() ) { 519 531 $retval = false; 520 532 521 // All other users will use the field's setting 533 // All other users will use the field's setting. 522 534 } elseif ( isset( $field->is_required ) ) { 523 535 $retval = $field->is_required; … … 541 553 * Fetches a random piece of profile data for the user. 542 554 * 543 * @package BuddyPress Core 544 * @param int $user_id User ID of the user to get random data for 545 * @param bool $exclude_fullname Optional; whether or not to exclude the full name field as random data. Defaults to true. 546 * @global BuddyPress $bp The one true BuddyPress instance 547 * @global $wpdb WordPress DB access object. 548 * @global $current_user WordPress global variable containing current logged in user information 555 * @global BuddyPress $bp The one true BuddyPress instance. 556 * @global object $wpdb WordPress DB access object. 557 * @global object $current_user WordPress global variable containing current logged in user information. 549 558 * @uses xprofile_format_profile_field() Formats profile field data so it is suitable for display. 559 * 560 * @param int $user_id User ID of the user to get random data for. 561 * @param bool $exclude_fullname Optional; whether or not to exclude the full name field as random data. 562 * Defaults to true. 563 * 550 564 * @return string|bool The fetched random data for the user, or false if no data or no match. 551 565 */ … … 576 590 * Formats a profile field according to its type. [ TODO: Should really be moved to filters ] 577 591 * 578 * @pa ckage BuddyPress Core579 * @param string $field_ type The type of field: datebox, selectbox, textbox etc580 * @param string $field_value The actual value581 * @return string|bool The formatted value, or false if value is empty 592 * @param string $field_type The type of field: datebox, selectbox, textbox etc. 593 * @param string $field_value The actual value. 594 * 595 * @return string|bool The formatted value, or false if value is empty. 582 596 */ 583 597 function xprofile_format_profile_field( $field_type, $field_value ) { … … 644 658 function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) { 645 659 646 // Use displayed user if no user ID was passed 660 // Use displayed user if no user ID was passed. 647 661 if ( empty( $user_id ) ) { 648 662 $user_id = bp_displayed_user_id(); 649 663 } 650 664 651 // Failsafe against accidentally nooped $directory parameter 665 // Failsafe against accidentally nooped $directory parameter. 652 666 if ( empty( $directory ) ) { 653 667 $directory = 'avatars'; … … 682 696 * @since 2.0.0 683 697 * 684 * @param array $sql Clauses in the user_id SQL query. 685 * @param BP_User_Query User query object. 698 * @param array $sql Clauses in the user_id SQL query. 699 * @param BP_User_Query $query User query object. 700 * 701 * @return array 686 702 */ 687 703 function bp_xprofile_bp_user_query_search( $sql, BP_User_Query $query ) { … … 708 724 709 725 // Combine the core search (against wp_users) into a single OR clause 710 // with the xprofile_data search 726 // with the xprofile_data search. 711 727 $search_xprofile = $wpdb->prepare( 712 728 "u.{$query->uid_name} IN ( SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s OR value LIKE %s )", … … 726 742 * Syncs Xprofile data to the standard built in WordPress profile data. 727 743 * 728 * @package BuddyPress Core 744 * @param int $user_id ID of the user to sync. 745 * 746 * @return bool 729 747 */ 730 748 function xprofile_sync_wp_profile( $user_id = 0 ) { 731 749 732 // Bail if profile syncing is disabled 750 // Bail if profile syncing is disabled. 733 751 if ( bp_disable_profile_sync() ) { 734 752 return true; … … 771 789 * 772 790 * @since 1.2.4 773 * @package BuddyPress Core 791 * 792 * @param object $errors Array of errors. Passed by reference. 793 * @param bool $update Whether or not being upated. 794 * @param object $user User object whose profile is being synced. Passed by reference. 774 795 */ 775 796 function xprofile_sync_bp_profile( &$errors, $update, &$user ) { 776 797 777 // Bail if profile syncing is disabled 798 // Bail if profile syncing is disabled. 778 799 if ( bp_disable_profile_sync() || ! $update || $errors->get_error_codes() ) { 779 800 return; … … 790 811 * usermeta table that this component uses. 791 812 * 792 * @package BuddyPress XProfile 793 * @param int $user_id The ID of the deleted user 813 * @param int $user_id The ID of the deleted user. 794 814 */ 795 815 function xprofile_remove_data( $user_id ) { … … 805 825 * Delete a piece of xprofile metadata. 806 826 * 807 * @param int $object_id ID of the object the metadata belongs to. 808 * @param string $object_type Type of object. 'group', 'field', or 'data'. 809 * @param string $meta_key Key of the metadata being deleted. If omitted, all 810 * metadata for the object will be deleted. 811 * @param mixed $meta_value Optional. If provided, only metadata that matches 812 * the value will be permitted. 813 * @param bool $delete_all Optional. If true, delete matching metadata entries 814 * for all objects, ignoring the specified object_id. Otherwise, only 815 * delete matching metadata entries for the specified object. 816 * Default: false. 827 * @param int $object_id ID of the object the metadata belongs to. 828 * @param string $object_type Type of object. 'group', 'field', or 'data'. 829 * @param string|bool $meta_key Key of the metadata being deleted. If omitted, all 830 * metadata for the object will be deleted. 831 * @param mixed $meta_value Optional. If provided, only metadata that matches 832 * the value will be permitted. 833 * @param bool $delete_all Optional. If true, delete matching metadata entries 834 * for all objects, ignoring the specified object_id. Otherwise, only 835 * delete matching metadata entries for the specified object. 836 * Default: false. 837 * 817 838 * @return bool True on success, false on failure. 818 839 */ … … 820 841 global $wpdb; 821 842 822 // Sanitize object type 843 // Sanitize object type. 823 844 if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) { 824 845 return false; 825 846 } 826 847 827 // Legacy - if no meta_key is passed, delete all for the item 848 // Legacy - if no meta_key is passed, delete all for the item. 828 849 if ( empty( $meta_key ) ) { 829 850 $table_key = 'xprofile_' . $object_type . 'meta'; … … 831 852 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$table_name} WHERE object_type = %s AND object_id = %d", $object_type, $object_id ) ); 832 853 833 // Force delete_all to false if deleting all for object 854 // Force delete_all to false if deleting all for object. 834 855 $delete_all = false; 835 856 } else { … … 857 878 * underlying get_metadata() function. This is for backward compatibility. 858 879 * 859 * @param int $object_idID of the object the metadata belongs to.880 * @param int $object_id ID of the object the metadata belongs to. 860 881 * @param string $object_type Type of object. 'group', 'field', or 'data'. 861 * @param string $meta_key Key of the metadata being fetched. If omitted, all 862 * metadata for the object will be retrieved. 863 * @param bool $single Optional. If true, return only the first value of the 864 * specified meta_key. This parameter has no effect if meta_key is not 865 * specified. Default: true. 882 * @param string $meta_key Key of the metadata being fetched. If omitted, all 883 * metadata for the object will be retrieved. 884 * @param bool $single Optional. If true, return only the first value of the 885 * specified meta_key. This parameter has no effect if meta_key is not 886 * specified. Default: true. 887 * 866 888 * @return mixed Meta value if found. False on failure. 867 889 */ 868 890 function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '', $single = true ) { 869 // Sanitize object type 891 // Sanitize object type. 870 892 if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) { 871 893 return false; … … 884 906 * Update a piece of xprofile metadata. 885 907 * 886 * @param int $object_idID of the object the metadata belongs to.908 * @param int $object_id ID of the object the metadata belongs to. 887 909 * @param string $object_type Type of object. 'group', 'field', or 'data'. 888 * @param string $meta_key Key of the metadata being updated. 889 * @param mixed $meta_value Value of the metadata being updated. 890 * @param mixed $prev_value Optional. If specified, only update existing 891 * metadata entries with the specified value. Otherwise, update all 892 * entries. 910 * @param string $meta_key Key of the metadata being updated. 911 * @param mixed $meta_value Value of the metadata being updated. 912 * @param mixed $prev_value Optional. If specified, only update existing 913 * metadata entries with the specified value. 914 * Otherwise update all entries. 915 * 893 916 * @return bool|int Returns false on failure. On successful update of existing 894 * metadata, returns true. On successful creation of new metadata,895 * returns the integer ID of the new metadata row.917 * metadata, returns true. On successful creation of new metadata, 918 * returns the integer ID of the new metadata row. 896 919 */ 897 920 function bp_xprofile_update_meta( $object_id, $object_type, $meta_key, $meta_value, $prev_value = '' ) { … … 910 933 * @since 2.0.0 911 934 * 912 * @param int $object_idID of the object the metadata belongs to.935 * @param int $object_id ID of the object the metadata belongs to. 913 936 * @param string $object_type Type of object. 'group', 'field', or 'data'. 914 * @param string $meta_key Metadata key. 915 * @param mixed $meta_value Metadata value. 916 * @param bool $unique Optional. Whether to enforce a single metadata value 917 * for the given key. If true, and the object already has a value for 918 * the key, no change will be made. Default: false. 937 * @param string $meta_key Metadata key. 938 * @param mixed $meta_value Metadata value. 939 * @param bool $unique Optional. Whether to enforce a single metadata value 940 * for the given key. If true, and the object already 941 * has a value for the key, no change will be made. 942 * Default false. 943 * 919 944 * @return int|bool The meta ID on successful update, false on failure. 920 945 */ … … 964 989 965 990 /** 966 * Return the field name for the Full Name xprofile field 991 * Return the field name for the Full Name xprofile field. 967 992 * 968 993 * @package BuddyPress 969 994 * @since 1.5.0 970 995 * 971 * @return string The field name 996 * @return string The field name. 972 997 */ 973 998 function bp_xprofile_fullname_field_name() { … … 984 1009 985 1010 /** 986 * Get visibility levels out of the $bp global 1011 * Get visibility levels out of the $bp global. 987 1012 * 988 1013 * @return array … … 1001 1026 1002 1027 /** 1003 * Get the ids of fields that are hidden for this displayed/loggedin user pair 1028 * Get the ids of fields that are hidden for this displayed/loggedin user pair. 1004 1029 * 1005 1030 * This is the function primarily responsible for profile field visibility. It works by determining … … 1011 1036 * @see BP_XProfile_Group::get() 1012 1037 * @uses apply_filters() Filter bp_xprofile_get_hidden_fields_for_user to modify visibility levels, 1013 * or if you have added your own custom levels 1014 * 1015 * @param int $displayed_user_id The id of the user the profile fields belong to 1016 * @param int $current_user_id The id of the user viewing the profile 1038 * or if you have added your own custom levels. 1039 * 1040 * @param int $displayed_user_id The id of the user the profile fields belong to. 1041 * @param int $current_user_id The id of the user viewing the profile. 1042 * 1017 1043 * @return array An array of field ids that should be excluded from the profile query 1018 1044 */ … … 1047 1073 1048 1074 /** 1049 * Get the visibility levels that should be hidden for this user pair 1075 * Get the visibility levels that should be hidden for this user pair. 1050 1076 * 1051 1077 * Field visibility is determined based on the relationship between the … … 1058 1084 * @see bp_xprofile_get_hidden_fields_for_user() 1059 1085 * 1060 * @param int $displayed_user_id The id of the user the profile fields belong to 1061 * @param int $current_user_id The id of the user viewing the profile 1062 * @return array An array of visibility levels hidden to the current user 1086 * @param int $displayed_user_id The id of the user the profile fields belong to. 1087 * @param int $current_user_id The id of the user viewing the profile. 1088 * 1089 * @return array An array of visibility levels hidden to the current user. 1063 1090 */ 1064 1091 function bp_xprofile_get_hidden_field_types_for_user( $displayed_user_id = 0, $current_user_id = 0 ) { 1065 1092 1066 // Current user is logged in 1093 // Current user is logged in. 1067 1094 if ( ! empty( $current_user_id ) ) { 1068 1095 1069 1096 // Nothing's private when viewing your own profile, or when the 1070 // current user is an admin 1097 // current user is an admin. 1071 1098 if ( $displayed_user_id == $current_user_id || bp_current_user_can( 'bp_moderate' ) ) { 1072 1099 $hidden_levels = array(); 1073 1100 1074 // If the current user and displayed user are friends, show all 1101 // If the current user and displayed user are friends, show all. 1075 1102 } elseif ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) { 1076 1103 $hidden_levels = array( 'adminsonly', ); 1077 1104 1078 // current user is logged in but not friends, so exclude friends-only1105 // Current user is logged in but not friends, so exclude friends-only. 1079 1106 } else { 1080 1107 $hidden_levels = array( 'friends', 'adminsonly', ); … … 1099 1126 1100 1127 /** 1101 * Fetch an array of the xprofile fields that a given user has marked with certain visibility levels 1128 * Fetch an array of the xprofile fields that a given user has marked with certain visibility levels. 1102 1129 * 1103 1130 * @since 1.6.0 1104 1131 * @see bp_xprofile_get_hidden_fields_for_user() 1105 1132 * 1106 * @param int $user_id The id of the profile owner 1107 * @param array $levels An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be 1108 * checked against 1109 * @return array $field_ids The fields that match the requested visibility levels for the given user 1133 * @param int $user_id The id of the profile owner. 1134 * @param array $levels An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be 1135 * checked against. 1136 * 1137 * @return array $field_ids The fields that match the requested visibility levels for the given user. 1110 1138 */ 1111 1139 function bp_xprofile_get_fields_by_visibility_levels( $user_id, $levels = array() ) { … … 1117 1145 1118 1146 // Parse the user-provided visibility levels with the default levels, which may take 1119 // precedence 1147 // precedence. 1120 1148 $default_visibility_levels = BP_XProfile_Group::fetch_default_visibility_levels(); 1121 1149 1122 1150 foreach( (array) $default_visibility_levels as $d_field_id => $defaults ) { 1123 1151 // If the admin has forbidden custom visibility levels for this field, replace 1124 // the user-provided setting with the default specified by the admin 1152 // the user-provided setting with the default specified by the admin. 1125 1153 if ( isset( $defaults['allow_custom'] ) && isset( $defaults['default'] ) && 'disabled' == $defaults['allow_custom'] ) { 1126 1154 $user_visibility_levels[$d_field_id] = $defaults['default']; … … 1135 1163 } 1136 1164 1137 // Never allow the fullname field to be excluded 1165 // Never allow the fullname field to be excluded. 1138 1166 if ( in_array( 1, $field_ids ) ) { 1139 1167 $key = array_search( 1, $field_ids ); -
trunk/src/bp-xprofile/bp-xprofile-loader.php
r10157 r10163 16 16 17 17 /** 18 * Profile field types 18 * Profile field types. 19 19 * 20 20 * @since 1.5.0 … … 33 33 34 34 /** 35 * Start the xprofile component creation process 35 * Start the xprofile component creation process. 36 36 * 37 37 * @since 1.5.0 … … 51 51 52 52 /** 53 * Include files 53 * Include files. 54 * 55 * @param array $includes 54 56 */ 55 57 public function includes( $includes = array() ) { … … 76 78 77 79 /** 78 * Setup globals 80 * Setup globals. 79 81 * 80 82 * The BP_XPROFILE_SLUG constant is deprecated, and only used here for … … 82 84 * 83 85 * @since 1.5.0 86 * 87 * @param array $args Array of globals to set up. 84 88 */ 85 89 public function setup_globals( $args = array() ) { 86 90 $bp = buddypress(); 87 91 88 // Define a slug, if necessary 92 // Define a slug, if necessary. 89 93 if ( !defined( 'BP_XPROFILE_SLUG' ) ) { 90 94 define( 'BP_XPROFILE_SLUG', 'profile' ); … … 93 97 // Assign the base group and fullname field names to constants 94 98 // to use in SQL statements. 95 // Defined conditionally to accommodate unit tests 99 // Defined conditionally to accommodate unit tests. 96 100 if ( ! defined( 'BP_XPROFILE_BASE_GROUP_NAME' ) ) { 97 101 define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( bp_core_get_root_option( 'avatar_default' ) ) ); … … 113 117 // 'option' is a special case. It is not a top-level field, so 114 118 // does not have an associated BP_XProfile_Field_Type class, 115 // but it must be whitelisted 119 // but it must be whitelisted. 116 120 $this->field_types[] = 'option'; 117 121 118 // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter 122 // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter. 119 123 $this->visibility_levels = array( 120 124 'public' => array( … … 139 143 } 140 144 141 // Tables 145 // Tables. 142 146 $global_tables = array( 143 147 'table_name_data' => $bp->table_prefix . 'bp_xprofile_data', … … 168 172 * 169 173 * @global BuddyPress $bp The one true BuddyPress instance 174 * 175 * @param array $main_nav Array of main nav items to set up. 176 * @param array $sub_nav Array of sub nav items to set up. 170 177 */ 171 178 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 172 179 173 // Determine user to use 180 // Determine user to use. 174 181 if ( bp_displayed_user_domain() ) { 175 182 $user_domain = bp_displayed_user_domain(); … … 184 191 $profile_link = trailingslashit( $user_domain . $slug ); 185 192 186 // Add 'Profile' to the main navigation 193 // Add 'Profile' to the main navigation. 187 194 $main_nav = array( 188 195 'name' => _x( 'Profile', 'Profile header menu', 'buddypress' ), … … 194 201 ); 195 202 196 // Add the subnav items to the profile 203 // Add the subnav items to the profile. 197 204 $sub_nav[] = array( 198 205 'name' => _x( 'View', 'Profile header sub menu', 'buddypress' ), … … 204 211 ); 205 212 206 // Edit Profile 213 // Edit Profile. 207 214 $sub_nav[] = array( 208 215 'name' => _x( 'Edit','Profile header sub menu', 'buddypress' ), … … 215 222 ); 216 223 217 // Change Avatar 224 // Change Avatar. 218 225 if ( buddypress()->avatar->show_avatars ) { 219 226 $sub_nav[] = array( … … 242 249 243 250 // The Settings > Profile nav item can only be set up after 244 // the Settings component has run its own nav routine 251 // the Settings component has run its own nav routine. 245 252 add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) ); 246 253 … … 261 268 } 262 269 263 // Determine user to use 270 // Determine user to use. 264 271 if ( bp_displayed_user_domain() ) { 265 272 $user_domain = bp_displayed_user_domain(); … … 270 277 } 271 278 272 // Get the settings slug 279 // Get the settings slug. 273 280 $settings_slug = bp_get_settings_slug(); 274 281 … … 285 292 286 293 /** 287 * Set up the Toolbar 294 * Set up the Admin Bar. 295 * 296 * @param array $wp_admin_nav Admin Bar items. 288 297 */ 289 298 public function setup_admin_bar( $wp_admin_nav = array() ) { 290 299 291 // Menus for logged in user 300 // Menus for logged in user. 292 301 if ( is_user_logged_in() ) { 293 302 294 // Profile link 303 // Profile link. 295 304 $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() ); 296 305 297 // Add the "Profile" sub menu 306 // Add the "Profile" sub menu. 298 307 $wp_admin_nav[] = array( 299 308 'parent' => buddypress()->my_account_menu_id, … … 303 312 ); 304 313 305 // View Profile 314 // View Profile. 306 315 $wp_admin_nav[] = array( 307 316 'parent' => 'my-account-' . $this->id, … … 311 320 ); 312 321 313 // Edit Profile 322 // Edit Profile. 314 323 $wp_admin_nav[] = array( 315 324 'parent' => 'my-account-' . $this->id, … … 319 328 ); 320 329 321 // Edit Avatar 330 // Edit Avatar. 322 331 if ( buddypress()->avatar->show_avatars ) { 323 332 $wp_admin_nav[] = array( … … 352 361 353 362 /** 354 * Sets up the title for pages and <title> 363 * Sets up the title for pages and <title>. 355 364 */ 356 365 public function setup_title() { … … 375 384 376 385 /** 377 * Setup cache groups 386 * Setup cache groups. 378 387 * 379 388 * @since 2.2.0 … … 381 390 public function setup_cache_groups() { 382 391 383 // Global groups 392 // Global groups. 384 393 wp_cache_add_global_groups( array( 385 394 'bp_xprofile', … … 398 407 * 399 408 * @param array $wp_admin_nav The settings adminbar nav array. 409 * 400 410 * @return array 401 411 */ 402 412 public function setup_settings_admin_nav( $wp_admin_nav ) { 403 413 404 // Setup the logged in user variables 414 // Setup the logged in user variables. 405 415 $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); 406 416 407 // Add the "Profile" subnav item 417 // Add the "Profile" subnav item. 408 418 $wp_admin_nav[] = array( 409 419 'parent' => 'my-account-' . buddypress()->settings->id, -
trunk/src/bp-xprofile/bp-xprofile-screens.php
r10157 r10163 17 17 * Handles the display of the profile page by loading the correct template file. 18 18 * 19 * @package BuddyPress XProfile 20 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 19 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename). 21 20 */ 22 21 function xprofile_screen_display_profile() { … … 46 45 * Also checks to make sure this can only be accessed for the logged in users profile. 47 46 * 48 * @package BuddyPress XProfile 49 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user 50 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 47 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user. 48 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename). 51 49 */ 52 50 function xprofile_screen_edit_profile() { … … 61 59 } 62 60 63 // Check the field group exists 61 // Check the field group exists. 64 62 if ( ! bp_is_action_variable( 'group' ) || ! xprofile_get_field_group( bp_action_variable( 1 ) ) ) { 65 63 bp_do_404(); … … 67 65 } 68 66 69 // No errors 67 // No errors. 70 68 $errors = false; 71 69 72 // Check to see if any new information has been submitted 70 // Check to see if any new information has been submitted. 73 71 if ( isset( $_POST['field_ids'] ) ) { 74 72 75 // Check the nonce 73 // Check the nonce. 76 74 check_admin_referer( 'bp_xprofile_edit' ); 77 75 78 // Check we have field ID's 76 // Check we have field ID's. 79 77 if ( empty( $_POST['field_ids'] ) ) { 80 78 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) ); … … 82 80 83 81 // Explode the posted field IDs into an array so we know which 84 // fields have been submitted 82 // fields have been submitted. 85 83 $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] ); 86 84 $is_required = array(); 87 85 88 86 // Loop through the posted fields formatting any datebox values 89 // then validate the field 87 // then validate the field. 90 88 foreach ( (array) $posted_field_ids as $field_id ) { 91 89 if ( !isset( $_POST['field_' . $field_id] ) ) { 92 90 93 91 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) { 94 // Concatenate the values 92 // Concatenate the values. 95 93 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; 96 94 97 // Turn the concatenated value into a timestamp 95 // Turn the concatenated value into a timestamp. 98 96 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); 99 97 } … … 107 105 } 108 106 109 // There are errors 107 // There are errors. 110 108 if ( !empty( $errors ) ) { 111 109 bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' ); 112 110 113 // No errors 111 // No errors. 114 112 } else { 115 113 116 // Reset the errors var 114 // Reset the errors var. 117 115 $errors = false; 118 116 … … 128 126 // Save the old and new values. They will be 129 127 // passed to the filter and used to determine 130 // whether an activity item should be posted 128 // whether an activity item should be posted. 131 129 $old_values[ $field_id ] = array( 132 130 'value' => xprofile_get_field_data( $field_id, bp_displayed_user_id() ), … … 134 132 ); 135 133 136 // Update the field data and visibility level 134 // Update the field data and visibility level. 137 135 xprofile_set_field_visibility_level( $field_id, bp_displayed_user_id(), $visibility_level ); 138 136 $field_updated = xprofile_set_field_data( $field_id, bp_displayed_user_id(), $value, $is_required[ $field_id ] ); … … 173 171 do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values ); 174 172 175 // Set the feedback messages 173 // Set the feedback messages. 176 174 if ( !empty( $errors ) ) { 177 175 bp_core_add_message( __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' ), 'error' ); … … 180 178 } 181 179 182 // Redirect back to the edit screen to display the updates and message 180 // Redirect back to the edit screen to display the updates and message. 183 181 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) ); 184 182 } … … 205 203 * Handles the uploading and cropping of a user avatar. Displays the change avatar page. 206 204 * 207 * @package BuddyPress XProfile 208 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user 209 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 205 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user. 206 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename). 210 207 */ 211 208 function xprofile_screen_change_avatar() { 212 209 213 // Bail if not the correct screen 210 // Bail if not the correct screen. 214 211 if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) { 215 212 return false; 216 213 } 217 214 218 // Bail if there are action variables 215 // Bail if there are action variables. 219 216 if ( bp_action_variables() ) { 220 217 bp_do_404(); … … 232 229 if ( !empty( $_FILES ) ) { 233 230 234 // Check the nonce 231 // Check the nonce. 235 232 check_admin_referer( 'bp_avatar_upload' ); 236 233 237 // Pass the file to the avatar upload handler 234 // Pass the file to the avatar upload handler. 238 235 if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) { 239 236 $bp->avatar_admin->step = 'crop-image'; 240 237 241 // Make sure we include the jQuery jCrop file for image cropping 238 // Make sure we include the jQuery jCrop file for image cropping. 242 239 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 243 240 } 244 241 } 245 242 246 // If the image cropping is done, crop the image and save a full/thumb version 243 // If the image cropping is done, crop the image and save a full/thumb version. 247 244 if ( isset( $_POST['avatar-crop-submit'] ) ) { 248 245 249 // Check the nonce 246 // Check the nonce. 250 247 check_admin_referer( 'bp_avatar_cropstore' ); 251 248 … … 268 265 * @since 1.1.0 269 266 * @since 2.3.4 Add two new parameters to inform about the user id and 270 * about the way the avatar was set (eg: 'crop' or 'camera') 267 * about the way the avatar was set (eg: 'crop' or 'camera'). 271 268 * 272 * @param string $item_id Inform about the user id the avatar was set for 273 * @param string $value Inform about the way the avatar was set ('crop')269 * @param string $item_id Inform about the user id the avatar was set for. 270 * @param string $value Inform about the way the avatar was set ('crop'). 274 271 */ 275 272 do_action( 'xprofile_avatar_uploaded', (int) $args['item_id'], 'crop' ); … … 328 325 329 326 /** 330 * Show the xprofile settings template 327 * Show the xprofile settings template. 331 328 * 332 329 * @since 2.0.0 … … 334 331 function bp_xprofile_screen_settings() { 335 332 336 // Redirect if no privacy settings page is accessible 333 // Redirect if no privacy settings page is accessible. 337 334 if ( bp_action_variables() || ! bp_is_active( 'xprofile' ) ) { 338 335 bp_do_404(); -
trunk/src/bp-xprofile/bp-xprofile-settings.php
r10140 r10163 11 11 12 12 /** 13 * Query all profile fields and their visibility data for display in settings 13 * Query all profile fields and their visibility data for display in settings. 14 14 * 15 15 * @since 2.0.0 16 16 * 17 * @param array $args17 * @param array|string $args Array of args for the settings fields. 18 18 * 19 19 * @return array … … 21 21 function bp_xprofile_get_settings_fields( $args = '' ) { 22 22 23 // Parse the possible arguments 23 // Parse the possible arguments. 24 24 $r = bp_parse_args( $args, array( 25 25 'user_id' => bp_displayed_user_id(), … … 38 38 39 39 /** 40 * Adds feedback messages when successfully saving profile field settings 40 * Adds feedback messages when successfully saving profile field settings. 41 41 * 42 42 * @since 2.0.0 … … 47 47 function bp_xprofile_settings_add_feedback_message() { 48 48 49 // Default message type is success 49 // Default message type is success. 50 50 $type = 'success'; 51 51 $message = __( 'Your profile settings have been saved.', 'buddypress' ); 52 52 53 // Community moderator editing another user's settings 53 // Community moderator editing another user's settings. 54 54 if ( ! bp_is_my_profile() && bp_core_can_edit_settings() ) { 55 55 $message = __( "This member's profile settings have been saved.", 'buddypress' ); 56 56 } 57 57 58 // Add the message 58 // Add the message. 59 59 bp_core_add_message( $message, $type ); 60 60 } -
trunk/src/bp-xprofile/bp-xprofile-template.php
r10140 r10163 116 116 * @since 2.4.0 Introduced `$member_type` argument. 117 117 * 118 * @param array $args {118 * @param array|string $args { 119 119 * An array of arguments. All items are optional. 120 120 * … … 134 134 public function __construct( $args = '' ) { 135 135 136 // Backward compatibility with old method of passing arguments 136 // Backward compatibility with old method of passing arguments. 137 137 if ( ! is_array( $args ) || func_num_args() > 1 ) { 138 138 _deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); … … 224 224 do_action( 'xprofile_template_loop_end' ); 225 225 226 // Do some cleaning up after the loop 226 // Do some cleaning up after the loop. 227 227 $this->rewind_groups(); 228 228 } … … 238 238 $group = $this->next_group(); 239 239 240 // loop has just started240 // Loop has just started. 241 241 if ( 0 === $this->current_group ) { 242 242 … … 285 285 return true; 286 286 } elseif ( $this->current_field + 1 == $this->field_count ) { 287 // Do some cleaning up after the loop 287 // Do some cleaning up after the loop. 288 288 $this->rewind_fields(); 289 289 } … … 297 297 $field = $this->next_field(); 298 298 299 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731 299 // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. 300 300 if ( ! empty( $field->data ) && ( ! empty( $field->data->value ) || ( '0' === $field->data->value ) ) ) { 301 301 $value = maybe_unserialize( $field->data->value ); … … 313 313 314 314 /** 315 * Query for XProfile groups and fields 315 * Query for XProfile groups and fields. 316 316 * 317 317 * @since 1.0.0 … … 320 320 * @see BP_XProfile_Group::get() for full description of `$args` array. 321 321 * 322 * @param array $args {322 * @param array|string $args { 323 323 * Array of arguments. See BP_XProfile_Group::get() for full description. Those arguments whose defaults differ 324 324 * from that method are described here: … … 339 339 340 340 // Only show empty fields if we're on the Dashboard, or we're on a user's 341 // profile edit page, or this is a registration page 341 // profile edit page, or this is a registration page. 342 342 $hide_empty_fields_default = ( ! is_network_admin() && ! is_admin() && ! bp_is_user_profile_edit() && ! bp_is_register_page() ); 343 343 344 // We only need to fetch visibility levels when viewing your own profile 344 // We only need to fetch visibility levels when viewing your own profile. 345 345 if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) { 346 346 $fetch_visibility_level_default = true; … … 349 349 } 350 350 351 // Parse arguments 351 // Parse arguments. 352 352 $r = bp_parse_args( $args, array( 353 353 'user_id' => bp_displayed_user_id(), … … 359 359 'fetch_field_data' => true, 360 360 'fetch_visibility_level' => $fetch_visibility_level_default, 361 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude 362 'exclude_fields' => false, // Comma-separated list of profile field IDs to exclude 361 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude. 362 'exclude_fields' => false, // Comma-separated list of profile field IDs to exclude. 363 363 'update_meta_cache' => true, 364 364 ), 'has_profile' ); 365 365 366 // Populate the template loop global 366 // Populate the template loop global. 367 367 $profile_template = new BP_XProfile_Data_Template( $r ); 368 368 … … 405 405 } 406 406 407 // Set a class with the field ID 407 // Set a class with the field ID. 408 408 $css_classes[] = 'field_' . $profile_template->field->id; 409 409 410 // Set a class with the field name (sanitized) 410 // Set a class with the field name (sanitized). 411 411 $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name ); 412 412 413 // Set a class indicating whether the field is required or optional 413 // Set a class indicating whether the field is required or optional. 414 414 if ( ! empty( $profile_template->field->is_required ) ) { 415 415 $css_classes[] = 'required-field'; … … 418 418 } 419 419 420 // Add the field visibility level 420 // Add the field visibility level. 421 421 $css_classes[] = 'visibility-' . esc_attr( bp_get_the_profile_field_visibility_level() ); 422 422 … … 531 531 global $group; 532 532 533 // Build the form action URL 533 // Build the form action URL. 534 534 $form_action = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $group->id ); 535 535 … … 750 750 751 751 /** 752 * Returns the action name for any signup errors related to this profile field 752 * Returns the action name for any signup errors related to this profile field. 753 753 * 754 754 * In the registration templates, signup errors are pulled from the global … … 759 759 * 760 760 * @since 1.8.0 761 * @return string The _errors action name corresponding to this profile field 761 * 762 * @return string The _errors action name corresponding to this profile field. 762 763 */ 763 764 function bp_get_the_profile_field_errors_action() { … … 767 768 768 769 /** 769 * bp_the_profile_field_options()770 *771 770 * Displays field options HTML for field types of 'selectbox', 'multiselectbox', 772 771 * 'radio', 'checkbox', and 'datebox'. 773 772 * 774 * @package BuddyPress Xprofile775 773 * @since 1.1.0 776 774 * … … 783 781 } 784 782 /** 785 * bp_get_the_profile_field_options()786 *787 783 * Retrieves field options HTML for field types of 'selectbox', 'multiselectbox', 'radio', 'checkbox', and 'datebox'. 788 784 * 789 * @package BuddyPress Xprofile790 785 * @since 1.1.0 791 786 * … … 795 790 * @param array $args { 796 791 * Array of optional arguments. 797 * @type string|bool $type Type of datebox. False if it's not a798 * datebox, otherwise 'day, 'month', or 'year'. Default: false.799 * @type int $user_id ID of the user whose profile values should be800 * used when rendering options. Default: displayed user.792 * @type string|bool $type Type of datebox. False if it's not a 793 * datebox, otherwise 'day, 'month', or 'year'. Default: false. 794 * @type int $user_id ID of the user whose profile values should be 795 * used when rendering options. Default: displayed user. 801 796 * } 797 * 798 * @return string $vaue Field options markup. 802 799 */ 803 800 function bp_get_the_profile_field_options( $args = array() ) { … … 839 836 global $field; 840 837 841 // Define locale variable(s) 838 // Define locale variable(s). 842 839 $retval = false; 843 840 844 // Super admins can skip required check 841 // Super admins can skip required check. 845 842 if ( bp_current_user_can( 'bp_moderate' ) && !is_admin() ) { 846 843 $retval = false; 847 844 848 // All other users will use the field's setting 845 // All other users will use the field's setting. 849 846 } elseif ( isset( $field->is_required ) ) { 850 847 $retval = $field->is_required; … … 862 859 863 860 /** 864 * Echo the visibility level of this field 861 * Echo the visibility level of this field. 865 862 */ 866 863 function bp_the_profile_field_visibility_level() { … … 868 865 } 869 866 /** 870 * Return the visibility level of this field 867 * Return the visibility level of this field. 871 868 */ 872 869 function bp_get_the_profile_field_visibility_level() { … … 875 872 // On the registration page, values stored in POST should take 876 873 // precedence over default visibility, so that submitted values 877 // are not lost on failure 874 // are not lost on failure. 878 875 if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) { 879 876 $retval = esc_attr( $_POST['field_' . $field->id . '_visibility'] ); … … 893 890 894 891 /** 895 * Echo the visibility level label of this field 892 * Echo the visibility level label of this field. 896 893 */ 897 894 function bp_the_profile_field_visibility_level_label() { … … 899 896 } 900 897 /** 901 * Return the visibility level label of this field 898 * Return the visibility level label of this field. 902 899 */ 903 900 function bp_get_the_profile_field_visibility_level_label() { … … 906 903 // On the registration page, values stored in POST should take 907 904 // precedence over default visibility, so that submitted values 908 // are not lost on failure 905 // are not lost on failure. 909 906 if ( bp_is_register_page() && ! empty( $_POST['field_' . $field->id . '_visibility'] ) ) { 910 907 $level = esc_html( $_POST['field_' . $field->id . '_visibility'] ); … … 959 956 * Get all profile field groups. 960 957 * 961 * @since 958 * @since 2.1.0 962 959 * 963 960 * @return object $groups … … 984 981 * Check if there is more than one group of fields for the profile being edited. 985 982 * 986 * @since 983 * @since 2.1.0 987 984 * 988 985 * @return bool True if there is more than one profile field group. … … 1005 1002 * 1006 1003 * @since 1.0.0 1007 *1008 * @return string Field group tabs markup.1009 1004 */ 1010 1005 function bp_profile_group_tabs() { … … 1021 1016 1022 1017 /** 1023 * Return the XProfile group tabs 1018 * Return the XProfile group tabs. 1024 1019 * 1025 1020 * @since 2.3.0 … … 1029 1024 function bp_get_profile_group_tabs() { 1030 1025 1031 // Get field group data 1026 // Get field group data. 1032 1027 $groups = bp_profile_get_field_groups(); 1033 1028 $group_name = bp_get_profile_group_name(); 1034 1029 $tabs = array(); 1035 1030 1036 // Loop through field groups and put a tab-lst together 1031 // Loop through field groups and put a tab-lst together. 1037 1032 for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) { 1038 1033 1039 // Setup the selected class 1034 // Setup the selected class. 1040 1035 $selected = ''; 1041 1036 if ( $group_name === $groups[ $i ]->name ) { … … 1043 1038 } 1044 1039 1045 // Skip if group has no fields 1040 // Skip if group has no fields. 1046 1041 if ( empty( $groups[ $i ]->fields ) ) { 1047 1042 continue; 1048 1043 } 1049 1044 1050 // Build the profile field group link 1045 // Build the profile field group link. 1051 1046 $link = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $groups[ $i ]->id ); 1052 1047 1053 // Add tab to end of tabs array 1048 // Add tab to end of tabs array. 1054 1049 $tabs[] = sprintf( 1055 1050 '<li %1$s><a href="%2$s">%3$s</a></li>', … … 1083 1078 function bp_get_profile_group_name() { 1084 1079 1085 // Check action variable 1080 // Check action variable. 1086 1081 $group_id = bp_action_variable( 1 ); 1087 1082 if ( empty( $group_id ) || ! is_numeric( $group_id ) ) { … … 1089 1084 } 1090 1085 1091 // Check for cached group 1086 // Check for cached group. 1092 1087 $group = new BP_XProfile_Group( $group_id ); 1093 1088 … … 1143 1138 * Filters the current profile group ID. 1144 1139 * 1145 * Possible values are admin/profile/edit/[group-id] 1140 * Possible values are admin/profile/edit/[group-id]. 1146 1141 * 1147 1142 * @since 1.1.0 … … 1183 1178 1184 1179 /** 1185 * Echo the field visibility radio buttons 1180 * Echo the field visibility radio buttons. 1181 * 1182 * @param array|string $args Args for the radio buttons. 1186 1183 */ 1187 1184 function bp_profile_visibility_radio_buttons( $args = '' ) { … … 1189 1186 } 1190 1187 /** 1191 * Return the field visibility radio buttons 1188 * Return the field visibility radio buttons. 1189 * 1190 * @param array|string $args Args for the radio buttons. 1191 * 1192 * @return string $retval 1192 1193 */ 1193 1194 function bp_profile_get_visibility_radio_buttons( $args = '' ) { 1194 1195 1195 // Parse optional arguments 1196 // Parse optional arguments. 1196 1197 $r = bp_parse_args( $args, array( 1197 1198 'field_id' => bp_get_the_profile_field_id(), … … 1203 1204 ), 'xprofile_visibility_radio_buttons' ); 1204 1205 1205 // Empty return value, filled in below if a valid field ID is found 1206 // Empty return value, filled in below if a valid field ID is found. 1206 1207 $retval = ''; 1207 1208 1208 // Only do-the-do if there's a valid field ID 1209 // Only do-the-do if there's a valid field ID. 1209 1210 if ( ! empty( $r['field_id'] ) ) : 1210 1211 1211 // Start the output buffer 1212 // Start the output buffer. 1212 1213 ob_start(); 1213 1214 1214 // Output anything before 1215 // Output anything before. 1215 1216 echo $r['before']; ?> 1216 1217 … … 1232 1233 <?php endif; 1233 1234 1234 // Output anything after 1235 // Output anything after. 1235 1236 echo $r['after']; 1236 1237 1237 // Get the output buffer and empty it 1238 // Get the output buffer and empty it. 1238 1239 $retval = ob_get_clean(); 1239 1240 endif; … … 1252 1253 1253 1254 /** 1254 * Output the XProfile field visibility select list for settings 1255 * Output the XProfile field visibility select list for settings. 1255 1256 * 1256 1257 * @since 2.0.0 1258 * 1259 * @param array|string $args Args for the select list. 1257 1260 */ 1258 1261 function bp_profile_settings_visibility_select( $args = '' ) { … … 1260 1263 } 1261 1264 /** 1262 * Return the XProfile field visibility select list for settings 1265 * Return the XProfile field visibility select list for settings. 1263 1266 * 1264 1267 * @since 2.0.0 1268 * 1269 * @param array|string $args Args for the select list. 1270 * 1271 * @return string $retval 1265 1272 */ 1266 1273 function bp_profile_get_settings_visibility_select( $args = '' ) { 1267 1274 1268 // Parse optional arguments 1275 // Parse optional arguments. 1269 1276 $r = bp_parse_args( $args, array( 1270 1277 'field_id' => bp_get_the_profile_field_id(), … … 1274 1281 ), 'xprofile_settings_visibility_select' ); 1275 1282 1276 // Empty return value, filled in below if a valid field ID is found 1283 // Empty return value, filled in below if a valid field ID is found. 1277 1284 $retval = ''; 1278 1285 1279 // Only do-the-do if there's a valid field ID 1286 // Only do-the-do if there's a valid field ID. 1280 1287 if ( ! empty( $r['field_id'] ) ) : 1281 1288 1282 // Start the output buffer 1289 // Start the output buffer. 1283 1290 ob_start(); 1284 1291 1285 // Output anything before 1292 // Output anything before. 1286 1293 echo $r['before']; ?> 1287 1294 … … 1305 1312 <?php endif; 1306 1313 1307 // Output anything after 1314 // Output anything after. 1308 1315 echo $r['after']; 1309 1316 1310 // Get the output buffer and empty it 1317 // Get the output buffer and empty it. 1311 1318 $retval = ob_get_clean(); 1312 1319 endif; -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox.php
r10140 r10163 18 18 19 19 /** 20 * Constructor for the checkbox field type 20 * Constructor for the checkbox field type. 21 21 * 22 22 * @since 2.0.0 23 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 50 50 * Must be used inside the {@link bp_profile_fields()} template loop. 51 51 * 52 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.checkbox.html permitted attributes} that you want to add.53 52 * @since 2.0.0 53 * 54 * @param array $raw_properties Optional key/value array of 55 * {@link http://dev.w3.org/html5/markup/input.checkbox.html permitted attributes} 56 * that you want to add. 54 57 */ 55 58 public function edit_field_html( array $raw_properties = array() ) { 56 59 57 // user_id is a special optional parameter that we pass to60 // User_id is a special optional parameter that we pass to 58 61 // {@link bp_the_profile_field_options()}. 59 62 if ( isset( $raw_properties['user_id'] ) ) { … … 97 100 * Must be used inside the {@link bp_profile_fields()} template loop. 98 101 * 102 * @since 2.0.0 103 * 99 104 * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. 100 * @since 2.0.0101 105 */ 102 106 public function edit_field_options_html( array $args = array() ) { … … 108 112 109 113 // Check for updated posted values, but errors preventing them from 110 // being saved first time 114 // being saved first time. 111 115 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_values != maybe_serialize( $_POST['field_' . $this->field_obj->id] ) ) { 112 116 if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) { … … 118 122 $selected = ''; 119 123 120 // First, check to see whether the user's saved values match the option 124 // First, check to see whether the user's saved values match the option. 121 125 for ( $j = 0, $count_values = count( $option_values ); $j < $count_values; ++$j ) { 122 126 123 127 // Run the allowed option name through the before_save filter, 124 // so we'll be sure to get a match 128 // so we'll be sure to get a match. 125 129 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 126 130 … … 132 136 133 137 // If the user has not yet supplied a value for this field, check to 134 // see whether there is a default value available 138 // see whether there is a default value available. 135 139 if ( empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) { 136 140 $selected = ' checked="checked"'; … … 167 171 * Must be used inside the {@link bp_profile_fields()} template loop. 168 172 * 173 * @since 2.0.0 174 * 169 175 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 170 * @since 2.0.0171 176 */ 172 177 public function admin_field_html( array $raw_properties = array() ) { … … 179 184 * Must be used inside the {@link bp_profile_fields()} template loop. 180 185 * 186 * @since 2.0.0 187 * 181 188 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 182 * @param string $control_type Optional. HTML input type used to render the current field's child options.183 * @since 2.0.0189 * @param string $control_type Optional. HTML input type used to render the current 190 * field's child options. 184 191 */ 185 192 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php
r10140 r10163 18 18 19 19 /** 20 * Constructor for the datebox field type 21 * 22 * @since 2.0.0 23 20 * Constructor for the datebox field type. 21 * 22 * @since 2.0.0 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 46 46 * Must be used inside the {@link bp_profile_fields()} template loop. 47 47 * 48 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.html permitted attributes} that you want to add. 49 * @since 2.0.0 48 * @since 2.0.0 49 * 50 * @param array $raw_properties Optional key/value array of 51 * {@link http://dev.w3.org/html5/markup/input.html permitted attributes} 52 * that you want to add. 50 53 */ 51 54 public function edit_field_html( array $raw_properties = array() ) { 52 55 53 // user_id is a special optional parameter that we pass to56 // User_id is a special optional parameter that we pass to. 54 57 // {@link bp_the_profile_field_options()}. 55 58 if ( isset( $raw_properties['user_id'] ) ) { … … 128 131 * Must be used inside the {@link bp_profile_fields()} template loop. 129 132 * 133 * @since 2.0.0 134 * 130 135 * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. 131 * @since 2.0.0132 136 */ 133 137 public function edit_field_options_html( array $args = array() ) { … … 140 144 $eng_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); 141 145 142 // Set day, month, year defaults 146 // Set day, month, year defaults. 143 147 if ( ! empty( $date ) ) { 144 148 145 // If Unix timestamp 149 // If Unix timestamp. 146 150 if ( is_numeric( $date ) ) { 147 151 $day = date( 'j', $date ); … … 149 153 $year = date( 'Y', $date ); 150 154 151 // If MySQL timestamp 155 // If MySQL timestamp. 152 156 } else { 153 157 $day = mysql2date( 'j', $date ); 154 $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below 158 $month = mysql2date( 'F', $date, false ); // Not localized, so that selected() works below. 155 159 $year = mysql2date( 'Y', $date ); 156 160 } … … 179 183 } 180 184 181 // $type will be passed by calling function when needed 185 // $type will be passed by calling function when needed. 182 186 switch ( $args['type'] ) { 183 187 case 'day': … … 242 246 * Must be used inside the {@link bp_profile_fields()} template loop. 243 247 * 248 * @since 2.0.0 249 * 244 250 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 245 * @since 2.0.0246 251 */ 247 252 public function admin_field_html( array $raw_properties = array() ) { … … 281 286 * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out. 282 287 * 288 * @since 2.0.0 289 * 283 290 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 284 * @param string $control_type Optional. HTML input type used to render the current field's child options.285 * @since 2.0.0291 * @param string $control_type Optional. HTML input type used to render the current 292 * field's child options. 286 293 */ 287 294 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} … … 293 300 * 294 301 * @param string $field_value The date value, as saved in the database. 295 * Typically, this is a MySQL-formatted date string (Y-m-d H:i:s). 302 * Typically, this is a MySQL-formatted date 303 * string (Y-m-d H:i:s). 304 * 296 305 * @return string Date formatted by bp_format_time(). 297 306 */ 298 307 public static function display_filter( $field_value ) { 299 308 300 // If Unix timestamp 309 // If Unix timestamp. 301 310 if ( ! is_numeric( $field_value ) ) { 302 311 $field_value = strtotime( $field_value ); -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-multiselectbox.php
r10140 r10163 18 18 19 19 /** 20 * Constructor for the multi-selectbox field type 21 * 22 * @since 2.0.0 23 20 * Constructor for the multi-selectbox field type. 21 * 22 * @since 2.0.0 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 50 50 * Must be used inside the {@link bp_profile_fields()} template loop. 51 51 * 52 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/select.html permitted attributes} that you want to add. 53 * @since 2.0.0 52 * @since 2.0.0 53 * 54 * @param array $raw_properties Optional key/value array of 55 * {@link http://dev.w3.org/html5/markup/select.html permitted attributes} 56 * that you want to add. 54 57 */ 55 58 public function edit_field_html( array $raw_properties = array() ) { 56 59 57 // user_id is a special optional parameter that we pass to60 // User_id is a special optional parameter that we pass to 58 61 // {@link bp_the_profile_field_options()}. 59 62 if ( isset( $raw_properties['user_id'] ) ) { … … 104 107 * Must be used inside the {@link bp_profile_fields()} template loop. 105 108 * 109 * @since 2.0.0 110 * 106 111 * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. 107 * @since 2.0.0108 112 */ 109 113 public function edit_field_options_html( array $args = array() ) { … … 122 126 123 127 // Check for updated posted values, but errors preventing them from 124 // being saved first time 128 // being saved first time. 125 129 foreach( $option_values as $i => $option_value ) { 126 130 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id][$i] != $option_value ) { … … 132 136 133 137 // Run the allowed option name through the before_save filter, so 134 // we'll be sure to get a match 138 // we'll be sure to get a match. 135 139 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 136 140 137 // First, check to see whether the user-entered value matches 141 // First, check to see whether the user-entered value matches. 138 142 if ( in_array( $allowed_options, $option_values ) ) { 139 143 $selected = ' selected="selected"'; 140 144 } 141 145 142 // Then, if the user has not provided a value, check for defaults 146 // Then, if the user has not provided a value, check for defaults. 143 147 if ( ! is_array( $original_option_values ) && empty( $option_values ) && ! empty( $options[$k]->is_default_option ) ) { 144 148 $selected = ' selected="selected"'; … … 167 171 * Must be used inside the {@link bp_profile_fields()} template loop. 168 172 * 173 * @since 2.0.0 174 * 169 175 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 170 * @since 2.0.0171 176 */ 172 177 public function admin_field_html( array $raw_properties = array() ) { … … 183 188 184 189 /** 185 * Output HTML for this field type's children options on the wp-admin Profile Fields "Add Field" and "Edit Field" screens. 186 * 187 * Must be used inside the {@link bp_profile_fields()} template loop. 190 * Output HTML for this field type's children options on the wp-admin Profile Fields, 191 * "Add Field" and "Edit Field" screens. 192 * 193 * Must be used inside the {@link bp_profile_fields()} template loop. 194 * 195 * @since 2.0.0 188 196 * 189 197 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 190 * @param string $control_type Optional. HTML input type used to render the current field's child options.191 * @since 2.0.0198 * @param string $control_type Optional. HTML input type used to render the current 199 * field's child options. 192 200 */ 193 201 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-number.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 18 18 19 19 /** 20 * Constructor for the number field type 20 * Constructor for the number field type. 21 21 * 22 22 * @since 2.0.0 23 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 46 46 * Must be used inside the {@link bp_profile_fields()} template loop. 47 47 * 48 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} that you want to add.49 48 * @since 2.0.0 49 * 50 * @param array $raw_properties Optional key/value array of 51 * {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} 52 * that you want to add. 50 53 */ 51 54 public function edit_field_html( array $raw_properties = array() ) { 52 55 53 // user_id is a special optional parameter that certain other fields56 // User_id is a special optional parameter that certain other fields 54 57 // types pass to {@link bp_the_profile_field_options()}. 55 58 if ( isset( $raw_properties['user_id'] ) ) { … … 84 87 * Must be used inside the {@link bp_profile_fields()} template loop. 85 88 * 89 * @since 2.0.0 90 * 86 91 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 87 * @since 2.0.088 92 */ 89 93 public function admin_field_html( array $raw_properties = array() ) { … … 100 104 * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out. 101 105 * 106 * @since 2.0.0 107 * 102 108 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 103 * @param string $control_type Optional. HTML input type used to render the current field's child options.104 * @since 2.0.0109 * @param string $control_type Optional. HTML input type used to render the current 110 * field's child options. 105 111 */ 106 112 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-placeholder.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 31 31 * Prevent any HTML being output for this field type. 32 32 * 33 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} that you want to add.34 33 * @since 2.0.1 34 * 35 * @param array $raw_properties Optional key/value array of 36 * {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} 37 * that you want to add. 35 38 */ 36 39 public function edit_field_html( array $raw_properties = array() ) { … … 40 43 * Prevent any HTML being output for this field type. 41 44 * 45 * @since 2.0.1 46 * 42 47 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 43 * @since 2.0.144 48 */ 45 49 public function admin_field_html( array $raw_properties = array() ) { … … 49 53 * Prevent any HTML being output for this field type. 50 54 * 55 * @since 2.0.1 56 * 51 57 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 52 * @param string $control_type Optional. HTML input type used to render the current field's child options.53 * @since 2.0.158 * @param string $control_type Optional. HTML input type used to render the current 59 * field's child options. 54 60 */ 55 61 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-radiobutton.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 21 21 * 22 22 * @since 2.0.0 23 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 48 48 * Must be used inside the {@link bp_profile_fields()} template loop. 49 49 * 50 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.radio.html permitted attributes} that you want to add.51 50 * @since 2.0.0 51 * 52 * @param array $raw_properties Optional key/value array of 53 * {@link http://dev.w3.org/html5/markup/input.radio.html permitted attributes} 54 * that you want to add. 52 55 */ 53 56 public function edit_field_html( array $raw_properties = array() ) { 54 57 55 // user_id is a special optional parameter that we pass to58 // User_id is a special optional parameter that we pass to 56 59 // {@link bp_the_profile_field_options()}. 57 60 if ( isset( $raw_properties['user_id'] ) ) { … … 102 105 * Must be used inside the {@link bp_profile_fields()} template loop. 103 106 * 107 * @since 2.0.0 108 * 104 109 * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. 105 * @since 2.0.0106 110 */ 107 111 public function edit_field_options_html( array $args = array() ) { … … 114 118 115 119 // Check for updated posted values, but errors preventing them from 116 // being saved first time 120 // being saved first time. 117 121 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_value != $_POST['field_' . $this->field_obj->id] ) { 118 122 if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) { … … 122 126 123 127 // Run the allowed option name through the before_save filter, so 124 // we'll be sure to get a match 128 // we'll be sure to get a match. 125 129 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 126 130 $selected = ''; … … 160 164 * Must be used inside the {@link bp_profile_fields()} template loop. 161 165 * 166 * @since 2.0.0 167 * 162 168 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 163 * @since 2.0.0164 169 */ 165 170 public function admin_field_html( array $raw_properties = array() ) { … … 182 187 * Must be used inside the {@link bp_profile_fields()} template loop. 183 188 * 189 * @since 2.0.0 190 * 184 191 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 185 * @param string $control_type Optional. HTML input type used to render the current field's child options.186 * @since 2.0.0192 * @param string $control_type Optional. HTML input type used to render the current 193 * field's child options. 187 194 */ 188 195 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-selectbox.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 18 18 19 19 /** 20 * Constructor for the selectbox field type 20 * Constructor for the selectbox field type. 21 21 * 22 22 * @since 2.0.0 23 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 48 48 * Must be used inside the {@link bp_profile_fields()} template loop. 49 49 * 50 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/select.html permitted attributes} that you want to add.51 50 * @since 2.0.0 51 * 52 * @param array $raw_properties Optional key/value array of 53 * {@link http://dev.w3.org/html5/markup/select.html permitted attributes} 54 * that you want to add. 52 55 */ 53 56 public function edit_field_html( array $raw_properties = array() ) { 54 57 55 // user_id is a special optional parameter that we pass to58 // User_id is a special optional parameter that we pass to 56 59 // {@link bp_the_profile_field_options()}. 57 60 if ( isset( $raw_properties['user_id'] ) ) { … … 92 95 * Must be used inside the {@link bp_profile_fields()} template loop. 93 96 * 97 * @since 2.0.0 98 * 94 99 * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. 95 * @since 2.0.096 100 */ 97 101 public function edit_field_options_html( array $args = array() ) { … … 110 114 111 115 // Check for updated posted values, but errors preventing them from 112 // being saved first time 116 // being saved first time. 113 117 foreach( $option_values as $i => $option_value ) { 114 118 if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id] != $option_value ) { … … 120 124 121 125 // Run the allowed option name through the before_save filter, so 122 // we'll be sure to get a match 126 // we'll be sure to get a match. 123 127 $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 124 128 125 // First, check to see whether the user-entered value matches 129 // First, check to see whether the user-entered value matches. 126 130 if ( in_array( $allowed_options, $option_values ) ) { 127 131 $selected = ' selected="selected"'; 128 132 } 129 133 130 // Then, if the user has not provided a value, check for defaults 134 // Then, if the user has not provided a value, check for defaults. 131 135 if ( ! is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) { 132 136 $selected = ' selected="selected"'; … … 155 159 * Must be used inside the {@link bp_profile_fields()} template loop. 156 160 * 161 * @since 2.0.0 162 * 157 163 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 158 * @since 2.0.0159 164 */ 160 165 public function admin_field_html( array $raw_properties = array() ) { … … 173 178 * Must be used inside the {@link bp_profile_fields()} template loop. 174 179 * 180 * @since 2.0.0 181 * 175 182 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 176 * @param string $control_type Optional. HTML input type used to render the current field's child options.177 * @since 2.0.0183 * @param string $control_type Optional. HTML input type used to render the current 184 * field's child options. 178 185 */ 179 186 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 18 18 19 19 /** 20 * Constructor for the textarea field type 20 * Constructor for the textarea field type. 21 21 * 22 22 * @since 2.0.0 23 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 46 46 * Must be used inside the {@link bp_profile_fields()} template loop. 47 47 * 48 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} that you want to add.49 48 * @since 2.0.0 49 * 50 * @param array $raw_properties Optional key/value array of 51 * {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} 52 * that you want to add. 50 53 */ 51 54 public function edit_field_html( array $raw_properties = array() ) { 52 55 53 // user_id is a special optional parameter that certain other fields56 // User_id is a special optional parameter that certain other fields 54 57 // types pass to {@link bp_the_profile_field_options()}. 55 58 if ( isset( $raw_properties['user_id'] ) ) { … … 84 87 * Must be used inside the {@link bp_profile_fields()} template loop. 85 88 * 89 * @since 2.0.0 90 * 86 91 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 87 * @since 2.0.088 92 */ 89 93 public function admin_field_html( array $raw_properties = array() ) { … … 102 106 * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out. 103 107 * 108 * @since 2.0.0 109 * 104 110 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 105 * @param string $control_type Optional. HTML input type used to render the current field's child options.106 * @since 2.0.0111 * @param string $control_type Optional. HTML input type used to render the current 112 * field's child options. 107 113 */ 108 114 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textbox.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 18 18 19 19 /** 20 * Constructor for the textbox field type 20 * Constructor for the textbox field type. 21 21 * 22 22 * @since 2.0.0 23 23 */ 24 24 public function __construct() { 25 25 parent::__construct(); … … 43 43 /** 44 44 * Output the edit field HTML for this field type. 45 *46 45 * Must be used inside the {@link bp_profile_fields()} template loop. 47 46 * 48 * @param array $raw_properties Optional key/value array of {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} that you want to add.49 47 * @since 2.0.0 48 * 49 * @param array $raw_properties Optional key/value array of 50 * {@link http://dev.w3.org/html5/markup/input.text.html permitted attributes} 51 * that you want to add. 50 52 */ 51 53 public function edit_field_html( array $raw_properties = array() ) { 52 54 53 // user_id is a special optional parameter that certain other fields55 // User_id is a special optional parameter that certain other fields 54 56 // types pass to {@link bp_the_profile_field_options()}. 55 57 if ( isset( $raw_properties['user_id'] ) ) { … … 84 86 * Must be used inside the {@link bp_profile_fields()} template loop. 85 87 * 88 * @since 2.0.0 89 * 86 90 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 87 * @since 2.0.088 91 */ 89 92 public function admin_field_html( array $raw_properties = array() ) { … … 102 105 * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out. 103 106 * 107 * @since 2.0.0 108 * 104 109 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 105 * @param string $control_type Optional. HTML input type used to render the current field's child options.106 * @since 2.0.0110 * @param string $control_type Optional. HTML input type used to render the 111 * current field's child options. 107 112 */ 108 113 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-url.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 47 47 * 48 48 * @param array $raw_properties Optional key/value array of 49 * {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} 50 * that you want to add. 49 * {@link http://dev.w3.org/html5/markup/input.number.html permitted attributes} 50 * that you want to add. 51 * 51 52 * @since 2.1.0 52 53 */ … … 88 89 * 89 90 * @param array $raw_properties Optional key/value array of permitted 90 * attributes that you want to add.91 * attributes that you want to add. 91 92 * @since 2.1.0 92 93 */ … … 107 108 * for this field type, we don't want it, so it's stubbed out. 108 109 * 110 * @since 2.1.0 111 * 109 112 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 110 * @param string $control_type Optional. HTML input type used to render the current field's child options.111 * @since 2.1.0113 * @param string $control_type Optional. HTML input type used to render the current 114 * field's child options. 112 115 */ 113 116 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} … … 126 129 * 127 130 * @param string $submitted_value Raw value submitted by the user. 131 * 128 132 * @return string 129 133 */ 130 134 public static function pre_validate_filter( $submitted_value = '' ) { 131 135 132 // Allow empty URL values 136 // Allow empty URL values. 133 137 if ( empty( $submitted_value ) ) { 134 138 return ''; 135 139 } 136 140 137 // Run some checks on the submitted value 141 // Run some checks on the submitted value. 138 142 if ( false === strpos( $submitted_value, ':' ) 139 143 && substr( $submitted_value, 0, 1 ) !== '/' … … 153 157 * 154 158 * @param string $field_value The URL value, as saved in the database. 159 * 155 160 * @return string URL converted to a link. 156 161 */ -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 18 18 19 19 /** 20 * @since 2.0.0 21 * @var array Field type validation regexes 20 * Validation regex rules for field type. 21 22 * @since 2.0.0 23 * @var array Field type validation regexes. 22 24 */ 23 25 protected $validation_regex = array(); 24 26 25 27 /** 26 * @since 2.0.0 27 * @var array Field type whitelisted values 28 * Whitelisted values for field type. 29 * 30 * @since 2.0.0 31 * @var array Field type whitelisted values. 28 32 */ 29 33 protected $validation_whitelist = array(); 30 34 31 35 /** 32 * @since 2.0.0 33 * @var string The name of this field type 36 * Name for field type. 37 * 38 * @since 2.0.0 39 * @var string The name of this field type. 34 40 */ 35 41 public $name = ''; … … 44 50 45 51 /** 52 * If allowed to store null/empty values. 53 * 46 54 * @since 2.0.0 47 55 * @var bool If this is set, allow BP to store null/empty values for this field type. … … 58 66 59 67 /** 68 * If allowed to support multiple options as default. 69 * 60 70 * @since 2.0.0 61 71 * @var bool Does this field type support multiple options being set as default values? e.g. multiselectbox, checkbox. … … 64 74 65 75 /** 66 * @since 2.0.0 67 * @var BP_XProfile_Field If this object is created by instantiating a {@link BP_XProfile_Field}, this is a reference back to that object. 76 * If object is created by an BP_XProfile_Field object. 77 * 78 * @since 2.0.0 79 * @var BP_XProfile_Field If this object is created by instantiating a {@link BP_XProfile_Field}, 80 * this is a reference back to that object. 68 81 */ 69 82 public $field_obj = null; 70 83 71 84 /** 72 * Constructor 85 * Constructor. 73 86 * 74 87 * @since 2.0.0 … … 93 106 * it's successful as long as the new value matches any one of the registered formats. 94 107 * 95 * @param string $format Regex string 96 * @param string $replace_format Optional; if 'replace', replaces the format instead of adding to it. Defaults to 'add'. 108 * @since 2.0.0 109 * 110 * @param string $format Regex string. 111 * @param string $replace_format Optional; if 'replace', replaces the format instead of adding to it. 112 * Defaults to 'add'. 113 * 97 114 * @return BP_XProfile_Field_Type 98 * @since 2.0.099 115 */ 100 116 public function set_format( $format, $replace_format = 'add' ) { … … 127 143 * it's successful as long as the new value matches any one of the registered formats. 128 144 * 129 * @param string|array $values 145 * @since 2.0.0 146 * 147 * @param string|array $values Whitelisted values. 148 * 130 149 * @return BP_XProfile_Field_Type 131 * @since 2.0.0132 150 */ 133 151 public function set_whitelist_values( $values ) { … … 154 172 * This method doesn't support chaining. 155 173 * 156 * @param string|array $values Value to check against the registered formats 174 * @since 2.0.0 175 * 176 * @param string|array $values Value to check against the registered formats. 177 * 157 178 * @return bool True if the value validates 158 * @since 2.0.0159 179 */ 160 180 public function is_valid( $values ) { 161 181 $validated = false; 162 182 163 // Some types of field (e.g. multi-selectbox) may have multiple values to check 183 // Some types of field (e.g. multi-selectbox) may have multiple values to check. 164 184 foreach ( (array) $values as $value ) { 165 185 … … 176 196 } 177 197 178 // Handle field types with accepts_null_value set if $values is an empty array 198 // Handle field types with accepts_null_value set if $values is an empty array. 179 199 if ( ( false === $validated ) && is_array( $values ) && empty( $values ) && $this->accepts_null_value ) { 180 200 $validated = true; … … 205 225 * Must be used inside the {@link bp_profile_fields()} template loop. 206 226 * 227 * @since 2.0.0 228 * 207 229 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 208 * @since 2.0.0209 230 */ 210 231 abstract public function edit_field_html( array $raw_properties = array() ); 232 233 /** 234 * Output HTML for this field type on the wp-admin Profile Fields screen. 235 * 236 * Must be used inside the {@link bp_profile_fields()} template loop. 237 * 238 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. 239 * @since 2.0.0 240 */ 241 abstract public function admin_field_html( array $raw_properties = array() ); 211 242 212 243 /** … … 222 253 * Must be used inside the {@link bp_profile_fields()} template loop. 223 254 * 255 * @since 2.0.0 256 * 224 257 * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}. 225 * @since 2.0.0226 258 */ 227 259 public function edit_field_options_html( array $args = array() ) {} 228 229 /**230 * Output HTML for this field type on the wp-admin Profile Fields screen.231 *232 * Must be used inside the {@link bp_profile_fields()} template loop.233 *234 * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.235 * @since 2.0.0236 */237 abstract public function admin_field_html( array $raw_properties = array() );238 260 239 261 /** … … 246 268 * Must be used inside the {@link bp_profile_fields()} template loop. 247 269 * 270 * @since 2.0.0 271 * 248 272 * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen. 249 * @param string $control_type Optional. HTML input type used to render the current field's child options.250 * @since 2.0.0273 * @param string $control_type Optional. HTML input type used to render the current 274 * field's child options. 251 275 */ 252 276 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { … … 295 319 } 296 320 297 // Grab the values from $_POST to use as the form's options 321 // Grab the values from $_POST to use as the form's options. 298 322 $options[] = (object) array( 299 323 'id' => -1, … … 315 339 } 316 340 317 // Render the markup for the children options 341 // Render the markup for the children options. 318 342 if ( ! empty( $options ) ) { 319 343 $default_name = ''; … … 385 409 * @since 2.1.0 386 410 * 387 * @param mixed $submitted_value Submitted value. 411 * @param mixed $field_value Submitted field value. 412 * 388 413 * @return mixed 389 414 */ … … 402 427 * 403 428 * @param mixed $field_value Field value. 429 * 404 430 * @return mixed 405 431 */ … … 416 442 * This method was intended to be static but couldn't be because php.net/lsb/ requires PHP >= 5.3. 417 443 * 444 * @since 2.0.0 445 * 418 446 * @param array $properties Optional key/value array of attributes for this edit field. 447 * 419 448 * @return string 420 * @since 2.0.0421 449 */ 422 450 protected function get_edit_field_html_elements( array $properties = array() ) { … … 431 459 } 432 460 433 $html = '';434 435 461 /** 436 462 * Filters the edit html elements and attributes. -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php
r10160 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 13 13 14 14 /** 15 * Field ID. 16 * 15 17 * @since 1.0.0 16 18 * 17 * @var int ID of field 19 * @var int ID of field. 18 20 */ 19 21 public $id; 20 22 21 23 /** 24 * Field group ID. 25 * 22 26 * @since 1.0.0 23 27 * 24 * @var int Field group ID for field 28 * @var int Field group ID for field. 25 29 */ 26 30 public $group_id; 27 31 28 32 /** 33 * Field parent ID. 34 * 29 35 * @since 1.0.0 30 36 * 31 * @var int Parent ID of field 37 * @var int Parent ID of field. 32 38 */ 33 39 public $parent_id; 34 40 35 41 /** 42 * Field type. 43 * 36 44 * @since 1.0.0 37 45 * 38 * @var string Field type 46 * @var string Field type. 39 47 */ 40 48 public $type; 41 49 42 50 /** 51 * Field name. 52 * 43 53 * @since 1.0.0 44 54 * 45 * @var string Field name 55 * @var string Field name. 46 56 */ 47 57 public $name; 48 58 49 59 /** 60 * Field description. 61 * 50 62 * @since 1.0.0 51 63 * 52 * @var string Field description 64 * @var string Field description. 53 65 */ 54 66 public $description; 55 67 56 68 /** 69 * Required field? 70 * 57 71 * @since 1.0.0 58 72 * … … 62 76 63 77 /** 78 * Deletable field? 79 * 64 80 * @since 1.0.0 65 81 * … … 69 85 70 86 /** 87 * Field position. 88 * 71 89 * @since 1.0.0 72 90 * 73 * @var int Field position 91 * @var int Field position. 74 92 */ 75 93 public $field_order; 76 94 77 95 /** 96 * Option order. 97 * 78 98 * @since 1.0.0 79 99 * 80 * @var int Option order 100 * @var int Option order. 81 101 */ 82 102 public $option_order; 83 103 84 104 /** 105 * Order child fields. 106 * 85 107 * @since 1.0.0 86 108 * 87 * @var string Order child fields by 109 * @var string Order child fields by. 88 110 */ 89 111 public $order_by; 90 112 91 113 /** 114 * Is this the default option? 115 * 92 116 * @since 1.0.0 93 117 * … … 97 121 98 122 /** 123 * Field data visibility. 124 * 99 125 * @since 1.9.0 100 126 * 101 * @var string Default field data visibility 127 * @var string Default field data visibility. 102 128 */ 103 129 public $default_visibility = 'public'; 104 130 105 131 /** 132 * Is the visibility able to be modified? 133 * 106 134 * @since 2.3.0 107 135 * 108 * @var string Members are allowed/disallowed to modify data visibility 136 * @var string Members are allowed/disallowed to modify data visibility. 109 137 */ 110 138 public $allow_custom_visibility = 'allowed'; 111 139 112 140 /** 141 * Field type option. 142 * 113 143 * @since 2.0.0 114 144 * 115 * @var BP_XProfile_Field_Type Field type object used for validation 145 * @var BP_XProfile_Field_Type Field type object used for validation. 116 146 */ 117 147 public $type_obj = null; 118 148 119 149 /** 150 * Field data for user ID. 151 * 120 152 * @since 2.0.0 121 153 * 122 * @var BP_XProfile_ProfileData Field data for user ID 154 * @var BP_XProfile_ProfileData Field data for user ID. 123 155 */ 124 156 public $data; … … 134 166 135 167 /** 136 * Initialize and/or populate profile field 168 * Initialize and/or populate profile field. 137 169 * 138 170 * @since 1.1.0 139 171 * 140 * @param int $id141 * @param int $user_id142 * @param bool $get_data172 * @param int|null $id Field ID. 173 * @param int|null $user_id User ID. 174 * @param bool $get_data Get data. 143 175 */ 144 176 public function __construct( $id = null, $user_id = null, $get_data = true ) { … … 147 179 $this->populate( $id, $user_id, $get_data ); 148 180 149 // Initialise the type obj to prevent fatals when creating new profile fields 181 // Initialise the type obj to prevent fatals when creating new profile fields. 150 182 } else { 151 183 $this->type_obj = bp_xprofile_create_field_type( 'textbox' ); … … 155 187 156 188 /** 157 * Populate a profile field object 189 * Populate a profile field object. 158 190 * 159 191 * @since 1.1.0 … … 162 194 * @global object $userdata 163 195 * 164 * @param int $id165 * @param int $user_id166 * @param bool $get_data196 * @param int $id Field ID. 197 * @param int $user_id User ID. 198 * @param bool $get_data Get data. 167 199 */ 168 200 public function populate( $id, $user_id = null, $get_data = true ) { … … 198 230 } 199 231 200 // Get metadata for field 232 // Get metadata for field. 201 233 $default_visibility = bp_xprofile_get_meta( $id, 'field', 'default_visibility' ); 202 234 $allow_custom_visibility = bp_xprofile_get_meta( $id, 'field', 'allow_custom_visibility' ); 203 235 204 // Setup default visibility 236 // Setup default visibility. 205 237 $this->default_visibility = ! empty( $default_visibility ) 206 238 ? $default_visibility 207 239 : 'public'; 208 240 209 // Allow members to customize visibilty 241 // Allow members to customize visibilty. 210 242 $this->allow_custom_visibility = ( 'disabled' === $allow_custom_visibility ) 211 243 ? 'disabled' … … 215 247 216 248 /** 217 * Delete a profile field 249 * Delete a profile field. 218 250 * 219 251 * @since 1.1.0 220 252 * 221 * @global object $wpdb 222 * @param boolean $delete_data 253 * @global object $wpdb 254 * 255 * @param boolean $delete_data Whether or not to delete data. 256 * 223 257 * @return boolean 224 258 */ … … 226 260 global $wpdb; 227 261 228 // Prevent deletion if no ID is present 262 // Prevent deletion if no ID is present. 229 263 // Prevent deletion by url when can_delete is false. 230 264 // Prevent deletion of option 1 since this invalidates fields with options. … … 240 274 } 241 275 242 // delete the data in the DB for this field276 // Delete the data in the DB for this field. 243 277 if ( true === $delete_data ) { 244 278 BP_XProfile_ProfileData::delete_for_field( $this->id ); … … 249 283 250 284 /** 251 * Save a profile field 285 * Save a profile field. 252 286 * 253 287 * @since 1.1.0 … … 281 315 * @since 1.0.0 282 316 * 283 * @param BP_XProfile_Field Current instance of the field being saved.317 * @param BP_XProfile_Field $this Current instance of the field being saved. 284 318 */ 285 319 do_action_ref_array( 'xprofile_field_before_save', array( $this ) ); … … 303 337 } 304 338 305 // Only do this if we are editing an existing field 339 // Only do this if we are editing an existing field. 306 340 if ( ! $is_new_field ) { 307 341 … … 379 413 * @since 1.0.0 380 414 * 381 * @param BP_XProfile_Field Current instance of the field being saved.415 * @param BP_XProfile_Field $this Current instance of the field being saved. 382 416 */ 383 417 do_action_ref_array( 'xprofile_field_after_save', array( $this ) ); … … 394 428 395 429 /** 396 * Get field data for a user ID 430 * Get field data for a user ID. 397 431 * 398 432 * @since 1.2.0 399 433 * 400 * @param int $user_id 434 * @param int $user_id ID of the user to get field data for. 435 * 401 436 * @return object 402 437 */ … … 406 441 407 442 /** 408 * Get all child fields for this field ID 443 * Get all child fields for this field ID. 409 444 * 410 445 * @since 1.2.0 … … 412 447 * @global object $wpdb 413 448 * 414 * @param bool $for_editing 449 * @param bool $for_editing Whether or not the field is for editing. 450 * 415 451 * @return array 416 452 */ … … 418 454 global $wpdb; 419 455 420 // This is done here so we don't have problems with sql injection 456 // This is done here so we don't have problems with sql injection. 421 457 if ( empty( $for_editing ) && ( 'asc' === $this->order_by ) ) { 422 458 $sort_sql = 'ORDER BY name ASC'; … … 428 464 429 465 // This eliminates a problem with getting all fields when there is no 430 // id for the object 466 // id for the object. 431 467 if ( empty( $this->id ) ) { 432 468 $parent_id = -1; … … 452 488 453 489 /** 454 * Delete all field children for this field 490 * Delete all field children for this field. 455 491 * 456 492 * @since 1.2.0 … … 534 570 * @param bool $append Whether to append to existing member types. If false, all existing member type 535 571 * associations will be deleted before adding your `$member_types`. Default false. 572 * 536 573 * @return array Member types for the current field, after being saved. 537 574 */ … … 588 625 * @since 2.4.0 589 626 * 590 * @param BP_XProfile_Field $ fieldField object.627 * @param BP_XProfile_Field $this Field object. 591 628 */ 592 629 do_action( 'bp_xprofile_field_set_member_type', $this ); … … 661 698 global $wpdb; 662 699 663 // Bail if no field ID 700 // Bail if no field ID. 664 701 if ( empty( $field_id ) ) { 665 702 return false; … … 670 707 $type = $wpdb->get_var( $sql ); 671 708 672 // Return field type 709 // Return field type. 673 710 if ( ! empty( $type ) ) { 674 711 return $type; … … 679 716 680 717 /** 681 * Delete all fields in a field group 718 * Delete all fields in a field group. 682 719 * 683 720 * @since 1.2.0 … … 685 722 * @global object $wpdb 686 723 * 687 * @param int $group_id724 * @param int $group_id ID of the field group to delete fields from. 688 725 * 689 726 * @return boolean … … 692 729 global $wpdb; 693 730 694 // Bail if no group ID 731 // Bail if no group ID. 695 732 if ( empty( $group_id ) ) { 696 733 return false; … … 701 738 $deleted = $wpdb->get_var( $sql ); 702 739 703 // Return true if fields were deleted 740 // Return true if fields were deleted. 704 741 if ( false !== $deleted ) { 705 742 return true; … … 710 747 711 748 /** 712 * Get field ID from field name 749 * Get field ID from field name. 713 750 * 714 751 * @since 1.5.0 715 752 * 716 753 * @global object $wpdb 717 * @param string $field_name 754 * 755 * @param string $field_name Name of the field to query the ID for. 718 756 * 719 757 * @return boolean … … 734 772 735 773 /** 736 * Update field position and/or field group when relocating 774 * Update field position and/or field group when relocating. 737 775 * 738 776 * @since 1.5.0 … … 740 778 * @global object $wpdb 741 779 * 742 * @param int $field_id743 * @param int $position744 * @param int $field_group_id780 * @param int $field_id ID of the field to update. 781 * @param int|null $position Field position to update. 782 * @param int|null $field_group_id ID of the field group. 745 783 * 746 784 * @return boolean … … 749 787 global $wpdb; 750 788 751 // Bail if invalid position or field group 789 // Bail if invalid position or field group. 752 790 if ( ! is_numeric( $position ) || ! is_numeric( $field_group_id ) ) { 753 791 return false; 754 792 } 755 793 756 // Get table name and field parent 794 // Get table name and field parent. 757 795 $table_name = buddypress()->profile->table_name_fields; 758 796 $sql = $wpdb->prepare( "UPDATE {$table_name} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id ); 759 797 $parent = $wpdb->query( $sql ); 760 798 761 // Update $field_id with new $position and $field_group_id 799 // Update $field_id with new $position and $field_group_id. 762 800 if ( ! empty( $parent ) && ! is_wp_error( $parent ) ) { 763 801 764 // Update any children of this $field_id 802 // Update any children of this $field_id. 765 803 $sql = $wpdb->prepare( "UPDATE {$table_name} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id ); 766 804 $wpdb->query( $sql ); … … 779 817 * @param string|array $member_types Member type or array of member types. Use 'any' to return unrestricted 780 818 * fields (those available for anyone, regardless of member type). 819 * 781 820 * @return array Multi-dimensional array, with field IDs as top-level keys, and arrays of member types 782 821 * associated with each field as values. … … 847 886 848 887 /** 849 * Validate form field data on sumbission 888 * Validate form field data on sumbission. 850 889 * 851 890 * @since 2.2.0 852 891 * 853 * @global type $message 892 * @global $message 893 * 854 894 * @return boolean 855 895 */ … … 857 897 global $message; 858 898 859 // Check field name 899 // Check field name. 860 900 if ( ! isset( $_POST['title'] ) || ( '' === $_POST['title'] ) ) { 861 901 $message = esc_html__( 'Profile fields must have a name.', 'buddypress' ); … … 863 903 } 864 904 865 // Check field requirement 905 // Check field requirement. 866 906 if ( ! isset( $_POST['required'] ) ) { 867 907 $message = esc_html__( 'Profile field requirement is missing.', 'buddypress' ); … … 869 909 } 870 910 871 // Check field type 911 // Check field type. 872 912 if ( empty( $_POST['fieldtype'] ) ) { 873 913 $message = esc_html__( 'Profile field type is missing.', 'buddypress' ); … … 875 915 } 876 916 877 // Check that field is of valid type 917 // Check that field is of valid type. 878 918 if ( ! in_array( $_POST['fieldtype'], array_keys( bp_xprofile_get_field_types() ), true ) ) { 879 919 $message = sprintf( esc_html__( 'The profile field type %s is not registered.', 'buddypress' ), '<code>' . esc_attr( $_POST['fieldtype'] ) . '</code>' ); … … 881 921 } 882 922 883 // Get field type so we can check for and lavidate any field options 923 // Get field type so we can check for and lavidate any field options. 884 924 $field_type = bp_xprofile_create_field_type( $_POST['fieldtype'] ); 885 925 886 // Field type requires options 926 // Field type requires options. 887 927 if ( true === $field_type->supports_options ) { 888 928 889 // Build the field option key 929 // Build the field option key. 890 930 $option_name = sanitize_key( $_POST['fieldtype'] ) . '_option'; 891 931 892 // Check for missing or malformed options 932 // Check for missing or malformed options. 893 933 if ( empty( $_POST[ $option_name ] ) || ! is_array( $_POST[ $option_name ] ) ) { 894 934 $message = esc_html__( 'These field options are invalid.', 'buddypress' ); … … 896 936 } 897 937 898 // Trim out empty field options 938 // Trim out empty field options. 899 939 $field_values = array_values( $_POST[ $option_name ] ); 900 940 $field_options = array_map( 'sanitize_text_field', $field_values ); 901 941 $field_count = count( $field_options ); 902 942 903 // Check for missing or malformed options 943 // Check for missing or malformed options. 904 944 if ( 0 === $field_count ) { 905 945 $message = sprintf( esc_html__( '%s require at least one option.', 'buddypress' ), $field_type->name ); … … 907 947 } 908 948 909 // If only one option exists, it cannot be an empty string 949 // If only one option exists, it cannot be an empty string. 910 950 if ( ( 1 === $field_count ) && ( '' === $field_options[0] ) ) { 911 951 $message = sprintf( esc_html__( '%s require at least one option.', 'buddypress' ), $field_type->name ); … … 929 969 930 970 /** 931 * Oupput the admin form for this field 971 * Oupput the admin form for this field. 932 972 * 933 973 * @since 1.9.0 934 974 * 935 * @param type $message975 * @param string $message Message to display. 936 976 */ 937 977 public function render_admin_form( $message = '' ) { … … 976 1016 <?php 977 1017 978 // Output the name & description fields 1018 // Output the name & description fields. 979 1019 $this->name_and_description(); ?> 980 1020 … … 985 1025 <?php 986 1026 987 // Output the sumbit metabox 1027 // Output the sumbit metabox. 988 1028 $this->submit_metabox( $button ); 989 1029 990 // Output the required metabox 1030 // Output the required metabox. 991 1031 $this->required_metabox(); 992 1032 … … 994 1034 $this->member_type_metabox(); 995 1035 996 // Output the field visibility metaboxes 1036 // Output the field visibility metaboxes. 997 1037 $this->visibility_metabox(); 998 1038 … … 1021 1061 do_action( 'xprofile_field_before_contentbox', $this ); 1022 1062 1023 // Output the field attributes metabox 1063 // Output the field attributes metabox. 1024 1064 $this->type_metabox(); 1025 1065 1026 // Output hidden inputs for default field 1066 // Output hidden inputs for default field. 1027 1067 $this->default_field_hidden_inputs(); 1028 1068 … … 1046 1086 1047 1087 /** 1048 * Private method used to display the submit metabox 1088 * Private method used to display the submit metabox. 1049 1089 * 1050 1090 * @since 2.3.0 1051 1091 * 1052 * @param string $button_text 1092 * @param string $button_text Text to put on button. 1053 1093 */ 1054 1094 private function submit_metabox( $button_text = '' ) { … … 1115 1155 1116 1156 /** 1117 * Private method used to output field name and description fields 1157 * Private method used to output field name and description fields. 1118 1158 * 1119 1159 * @since 2.3.0 … … 1193 1233 1194 1234 /** 1195 * Private method used to output field visibility metaboxes 1235 * Private method used to output field visibility metaboxes. 1196 1236 * 1197 1237 * @since 2.3.0 1198 1238 * 1199 * @return if default field id 11239 * @return void If default field id 1. 1200 1240 */ 1201 1241 private function visibility_metabox() { 1202 1242 1203 // Default field cannot have custom visibility 1243 // Default field cannot have custom visibility. 1204 1244 if ( true === $this->is_default_field() ) { 1205 1245 return; … … 1242 1282 1243 1283 /** 1244 * Output the metabox for setting if field is required or not 1284 * Output the metabox for setting if field is required or not. 1245 1285 * 1246 1286 * @since 2.3.0 1247 1287 * 1248 * @return if default field1288 * @return void If default field. 1249 1289 */ 1250 1290 private function required_metabox() { 1251 1291 1252 // Default field is always required 1292 // Default field is always required. 1253 1293 if ( true === $this->is_default_field() ) { 1254 1294 return; … … 1269 1309 1270 1310 /** 1271 * Output the metabox for setting what type of field this is 1311 * Output the metabox for setting what type of field this is. 1272 1312 * 1273 1313 * @since 2.3.0 1274 1314 * 1275 * @return if default field1315 * @return void If default field. 1276 1316 */ 1277 1317 private function type_metabox() { 1278 1318 1279 // Default field cannot change type 1319 // Default field cannot change type. 1280 1320 if ( true === $this->is_default_field() ) { 1281 1321 return; … … 1305 1345 1306 1346 /** 1307 * Output hidden fields used by default field 1347 * Output hidden fields used by default field. 1308 1348 * 1309 1349 * @since 2.3.0 1310 1350 * 1311 * @return if not default field1351 * @return void If not default field. 1312 1352 */ 1313 1353 private function default_field_hidden_inputs() { 1314 1354 1315 // Field 1 is the fullname field, which cannot have custom visibility 1355 // Field 1 is the fullname field, which cannot have custom visibility. 1316 1356 if ( false === $this->is_default_field() ) { 1317 1357 return; … … 1325 1365 1326 1366 /** 1327 * Return if a field ID is the default field 1367 * Return if a field ID is the default field. 1328 1368 * 1329 1369 * @since 2.3.0 1330 1370 * 1331 * @param int $field_id ID of field to check 1371 * @param int $field_id ID of field to check. 1372 * 1332 1373 * @return bool 1333 1374 */ 1334 1375 private function is_default_field( $field_id = 0 ) { 1335 1376 1336 // Fallback to current field ID if none passed 1377 // Fallback to current field ID if none passed. 1337 1378 if ( empty( $field_id ) ) { 1338 1379 $field_id = $this->id; 1339 1380 } 1340 1381 1341 // Compare & return 1382 // Compare & return. 1342 1383 return (bool) ( 1 === (int) $field_id ); 1343 1384 } -
trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php
r10142 r10163 1 1 <?php 2 2 /** 3 * BuddyPress XProfile Classes 3 * BuddyPress XProfile Classes. 4 4 * 5 5 * @package BuddyPress … … 13 13 14 14 /** 15 * Field group ID. 16 * 15 17 * @since 1.1.0 16 18 * … … 20 22 21 23 /** 24 * Field group name. 25 * 22 26 * @since 1.1.0 23 27 * … … 27 31 28 32 /** 33 * Field group Description. 34 * 29 35 * @since 1.1.0 30 36 * … … 34 40 35 41 /** 42 * Group deletion boolean. 43 * 36 44 * @since 1.1.0 37 45 * … … 41 49 42 50 /** 51 * Group order. 52 * 43 53 * @since 1.1.0 44 54 * … … 48 58 49 59 /** 60 * Group fields. 61 * 50 62 * @since 1.1.0 51 63 * … … 55 67 56 68 /** 57 * Initialize and/or populate profile field group 69 * Initialize and/or populate profile field group. 58 70 * 59 71 * @since 1.1.0 60 72 * 61 * @param int $id 62 * @param int $user_id 63 * @param bool $get_data 73 * @param int|null $id Field group ID. 64 74 */ 65 75 public function __construct( $id = null ) { … … 70 80 71 81 /** 72 * Populate a profile field group 82 * Populate a profile field group. 73 83 * 74 84 * @since 1.0.0 75 85 * 76 86 * @global $wpdb $wpdb 77 * @param int $id 87 * 88 * @param int $id Field group ID. 78 89 * 79 90 * @return boolean … … 81 92 public function populate( $id ) { 82 93 83 // Get this group 94 // Get this group. 84 95 $group = self::get( array( 85 96 'profile_group_id' => $id 86 97 ) ); 87 98 88 // Bail if group not found 99 // Bail if group not found. 89 100 if ( empty( $group ) ) { 90 101 return false; 91 102 } 92 103 93 // Get the first array element 104 // Get the first array element. 94 105 $group = reset( $group ); 95 106 96 // Set object properties 107 // Set object properties. 97 108 $this->id = $group->id; 98 109 $this->name = $group->name; … … 103 114 104 115 /** 105 * Save a profile field group 116 * Save a profile field group. 106 117 * 107 118 * @since 1.1.0 … … 114 125 global $wpdb; 115 126 116 // Filter the field group attributes 127 // Filter the field group attributes. 117 128 $this->name = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id ); 118 129 $this->description = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id ); … … 125 136 * @since 1.0.0 126 137 * 127 * @param BP_XProfile_Group Current instance of the group being saved. Passed by reference.138 * @param BP_XProfile_Group $this Current instance of the group being saved. Passed by reference. 128 139 */ 129 140 do_action_ref_array( 'xprofile_group_before_save', array( &$this ) ); … … 131 142 $bp = buddypress(); 132 143 133 // Update or insert 144 // Update or insert. 134 145 if ( ! empty( $this->id ) ) { 135 146 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id ); … … 138 149 } 139 150 140 // Attempt to insert or update 151 // Attempt to insert or update. 141 152 $query = $wpdb->query( $sql ); 142 153 … … 146 157 } 147 158 148 // If not set, update the ID in the group object