Changeset 10163 for trunk/src/bp-xprofile/bp-xprofile-admin.php
- Timestamp:
- 10/01/2015 04:18:13 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-xprofile/bp-xprofile-admin.php (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 );
Note: See TracChangeset
for help on using the changeset viewer.