Changeset 8440
- Timestamp:
- 05/21/2014 04:31:43 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-admin.php
r8232 r8440 485 485 */ 486 486 public static function register_xprofile_user_admin() { 487 if( ! is_admin() ) 487 488 // Bail if not in admin 489 if ( ! is_admin() ) { 488 490 return; 491 } 489 492 490 493 $bp = buddypress(); 491 494 492 if ( empty( $bp->profile->admin ) ) {495 if ( empty( $bp->profile->admin ) ) { 493 496 $bp->profile->admin = new self; 494 497 } … … 515 518 private function setup_actions() { 516 519 517 /** Actions ***************************************************/518 519 520 // Register the metabox in Member's community admin profile 520 521 add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 ); 521 522 522 523 // Saves the profile actions for user ( avatar, profile fields ) 523 add_action( 'bp_members_admin_update_user', array( $this, 'user_admin_load' ), 10, 4 ); 524 524 add_action( 'bp_members_admin_update_user', array( $this, 'user_admin_load' ), 10, 4 ); 525 525 } 526 526 … … 537 537 public function register_metaboxes( $user_id = 0, $screen_id = '', $stats_metabox = null ) { 538 538 539 // Set the screen ID if none was passed 539 540 if ( empty( $screen_id ) ) { 540 541 $screen_id = buddypress()->members->admin->user_page; 541 542 } 542 543 544 // Setup a new metabox class if none was passed 543 545 if ( empty( $stats_metabox ) ) { 544 546 $stats_metabox = new StdClass(); … … 546 548 547 549 // Moving the Stats Metabox 548 $stats_metabox->context = 'side';550 $stats_metabox->context = 'side'; 549 551 $stats_metabox->priority = 'low'; 550 552 551 553 // Each Group of fields will have his own metabox 552 if ( false == bp_is_user_spammer( $user_id ) && bp_has_profile( array( 'fetch_fields' => false ) ) ) { 554 if ( ! bp_is_user_spammer( $user_id ) && bp_has_profile( array( 'fetch_fields' => false ) ) ) { 555 556 // Loop through field groups and add a metabox for each one 553 557 while ( bp_profile_groups() ) : bp_the_profile_group(); 554 add_meta_box( 'bp_xprofile_user_admin_fields_' . sanitize_key( bp_get_the_profile_group_slug() ), esc_html( bp_get_the_profile_group_name() ), array( &$this, 'user_admin_profile_metaboxes' ), $screen_id, 'normal', 'core', array( 'profile_group_id' => absint( bp_get_the_profile_group_id() ) ) ); 558 add_meta_box( 559 'bp_xprofile_user_admin_fields_' . sanitize_key( bp_get_the_profile_group_slug() ), 560 esc_html( bp_get_the_profile_group_name() ), 561 array( $this, 'user_admin_profile_metaboxes' ), 562 $screen_id, 563 'normal', 564 'core', 565 array( 'profile_group_id' => absint( bp_get_the_profile_group_id() ) ) 566 ); 555 567 endwhile; 556 568 557 // if a user has been mark as a spammer, remove BP data569 // If member is already a spammer, show a generic metabox 558 570 } else { 559 add_meta_box( 'bp_xprofile_user_admin_empty_profile', _x( 'User marked as a spammer', 'xprofile user-admin edit screen', 'buddypress' ), array( &$this, 'user_admin_spammer_metabox' ), $screen_id, 'normal', 'core' ); 571 add_meta_box( 572 'bp_xprofile_user_admin_empty_profile', 573 _x( 'User marked as a spammer', 'xprofile user-admin edit screen', 'buddypress' ), 574 array( $this, 'user_admin_spammer_metabox' ), 575 $screen_id, 576 'normal', 577 'core' 578 ); 560 579 } 561 580 562 581 // Avatar Metabox 563 add_meta_box( 'bp_xprofile_user_admin_avatar', _x( 'Avatar', 'xprofile user-admin edit screen', 'buddypress' ), array( &$this, 'user_admin_avatar_metabox' ), $screen_id, 'side', 'low' ); 564 582 add_meta_box( 583 'bp_xprofile_user_admin_avatar', 584 _x( 'Avatar', 'xprofile user-admin edit screen', 'buddypress' ), 585 array( $this, 'user_admin_avatar_metabox' ), 586 $screen_id, 587 'side', 588 'low' 589 ); 565 590 } 566 591 … … 577 602 578 603 // Eventually delete avatar 579 if ( 'delete_avatar' == $doaction ) {604 if ( 'delete_avatar' === $doaction ) { 580 605 581 606 check_admin_referer( 'delete_avatar' ); … … 592 617 593 618 // Update profile fields 594 } else { 595 // Check to see if any new information has been submitted 596 if ( isset( $_POST['field_ids'] ) ) { 597 598 // Check the nonce 599 check_admin_referer( 'edit-bp-profile_' . $user_id ); 600 601 // Check we have field ID's 602 if ( empty( $_POST['field_ids'] ) ) { 603 $redirect_to = add_query_arg( 'error', '1', $redirect_to ); 619 } elseif ( isset( $_POST['field_ids'] ) ) { 620 621 // Check the nonce 622 check_admin_referer( 'edit-bp-profile_' . $user_id ); 623 624 // Check we have field ID's 625 if ( empty( $_POST['field_ids'] ) ) { 626 $redirect_to = add_query_arg( 'error', '1', $redirect_to ); 627 bp_core_redirect( $redirect_to ); 628 } 629 630 /** 631 * Unlike front-end edit-fields screens, the wp-admin/profile 632 * displays all groups of fields on a single page, so the list of 633 * field ids is an array gathering for each group of fields a 634 * distinct comma separated list of ids. 635 * 636 * As a result, before using the wp_parse_id_list() function, we 637 * must ensure that these ids are "merged" into a single comma 638 * separated list. 639 */ 640 $merge_ids = join( ',', $_POST['field_ids'] ); 641 642 // Explode the posted field IDs into an array so we know which fields have been submitted 643 $posted_field_ids = wp_parse_id_list( $merge_ids ); 644 $is_required = array(); 645 646 // Loop through the posted fields formatting any datebox values then validate the field 647 foreach ( (array) $posted_field_ids as $field_id ) { 648 if ( ! isset( $_POST['field_' . $field_id ] ) ) { 649 if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) { 650 651 // Concatenate the values 652 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; 653 654 // Turn the concatenated value into a timestamp 655 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); 656 } 657 } 658 659 $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id ); 660 if ( $is_required[ $field_id ] && empty( $_POST['field_' . $field_id ] ) ) { 661 $redirect_to = add_query_arg( 'error', '2', $redirect_to ); 604 662 bp_core_redirect( $redirect_to ); 605 663 } 606 607 /** 608 * Unlike front-end edit-fields screens, the wp-admin/profile displays all 609 * groups of fields on a single page, so the list of field ids is an array 610 * gathering for each group of fields a distinct comma separated list of ids. 611 * As a result, before using the wp_parse_id_list() function, we must ensure 612 * that these ids are "merged" into a single comma separated list. 613 */ 614 $merge_ids = join( ',', $_POST['field_ids'] ); 615 616 // Explode the posted field IDs into an array so we know which fields have been submitted 617 $posted_field_ids = wp_parse_id_list( $merge_ids ); 618 $is_required = array(); 619 620 // Loop through the posted fields formatting any datebox values then validate the field 621 foreach ( (array) $posted_field_ids as $field_id ) { 622 if ( ! isset( $_POST['field_' . $field_id] ) ) { 623 if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) { 624 // Concatenate the values 625 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year']; 626 627 // Turn the concatenated value into a timestamp 628 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) ); 629 } 630 } 631 632 $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id ); 633 if ( $is_required[ $field_id ] && empty( $_POST['field_' . $field_id] ) ) { 634 $redirect_to = add_query_arg( 'error', '2', $redirect_to ); 635 bp_core_redirect( $redirect_to ); 636 } 664 } 665 666 // Set the errors var 667 $errors = false; 668 669 // Now we've checked for required fields, let's save the values. 670 foreach ( (array) $posted_field_ids as $field_id ) { 671 672 // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit. 673 $value = isset( $_POST['field_' . $field_id] ) ? $_POST['field_' . $field_id] : ''; 674 675 if ( ! xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] ) ) { 676 $errors = true; 677 } else { 678 do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); 637 679 } 638 680 639 // Set the errors var 640 $errors = false; 641 642 // Now we've checked for required fields, let's save the values. 643 foreach ( (array) $posted_field_ids as $field_id ) { 644 645 // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit. 646 $value = isset( $_POST['field_' . $field_id] ) ? $_POST['field_' . $field_id] : ''; 647 648 if ( ! xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] ) ) { 649 $errors = true; 650 } else { 651 do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); 652 } 653 654 // Save the visibility level 655 $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public'; 656 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 657 } 658 659 do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors ); 660 661 // Set the feedback messages 662 if ( ! empty( $errors ) ) { 663 $redirect_to = add_query_arg( 'error', '3', $redirect_to ); 664 } else { 665 $redirect_to = add_query_arg( 'updated', '1', $redirect_to ); 666 } 667 668 bp_core_redirect( $redirect_to ); 681 // Save the visibility level 682 $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public'; 683 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 669 684 } 685 686 do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors ); 687 688 // Set the feedback messages 689 if ( ! empty( $errors ) ) { 690 $redirect_to = add_query_arg( 'error', '3', $redirect_to ); 691 } else { 692 $redirect_to = add_query_arg( 'updated', '1', $redirect_to ); 693 } 694 695 bp_core_redirect( $redirect_to ); 670 696 } 671 697 } … … 681 707 public function user_admin_profile_metaboxes( $user = null, $args = array() ) { 682 708 709 // Bail if no user ID 683 710 if ( empty( $user->ID ) ) { 684 711 return; … … 695 722 } 696 723 697 if ( bp_has_profile( $r ) ) : 698 while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 699 <input type="hidden" name="field_ids[]" id="<?php echo esc_attr( 'field_ids_' . bp_get_the_profile_group_slug() ); ?>" value="<?php echo esc_attr( bp_get_the_profile_group_field_ids() ); ?>" /> 700 701 <?php if ( bp_get_the_profile_group_description() ) : ?> 702 <p class="description"><?php bp_the_profile_group_description(); ?></p> 703 <?php 704 endif; 705 706 while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 707 708 <div<?php bp_field_css_class( 'bp-profile-field' ); ?>> 709 <?php 710 $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); 711 $field_type->edit_field_html( array( 'user_id' => $r['user_id'] ) ); 712 713 if ( bp_get_the_profile_field_description() ) : ?> 714 <p class="description"><?php bp_the_profile_field_description(); ?></p> 715 <?php endif; 716 717 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 718 $can_change_visibility = bp_current_user_can( 'bp_xprofile_change_field_visibility' ); 719 ?> 720 721 <p class="field-visibility-settings-<?php echo $can_change_visibility ? 'toggle' : 'notoggle'; ?>" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id(); ?>"> 722 <?php 723 printf( __( 'This field can be seen by: <span class="%s">%s</span>', 'buddypress' ), esc_attr( 'current-visibility-level' ), bp_get_the_profile_field_visibility_level_label() ); 724 725 if ( $can_change_visibility ) : ?> 726 <a href="#" class="button visibility-toggle-link"><?php _e( 'Change', 'buddypress' ); ?></a> 727 <?php endif; ?> 728 </p> 724 // Bail if no profile fields are available 725 if ( ! bp_has_profile( $r ) ) { 726 return; 727 } 728 729 // Loop through profile groups & fields 730 while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 731 732 <input type="hidden" name="field_ids[]" id="<?php echo esc_attr( 'field_ids_' . bp_get_the_profile_group_slug() ); ?>" value="<?php echo esc_attr( bp_get_the_profile_group_field_ids() ); ?>" /> 733 734 <?php if ( bp_get_the_profile_group_description() ) : ?> 735 736 <p class="description"><?php bp_the_profile_group_description(); ?></p> 737 738 <?php endif; ?> 739 740 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 741 742 <div<?php bp_field_css_class( 'bp-profile-field' ); ?>> 743 744 <?php 745 746 $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); 747 $field_type->edit_field_html( array( 'user_id' => $r['user_id'] ) ); 748 749 if ( bp_get_the_profile_field_description() ) : ?> 750 751 <p class="description"><?php bp_the_profile_field_description(); ?></p> 752 753 <?php endif; 754 755 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 756 757 $can_change_visibility = bp_current_user_can( 'bp_xprofile_change_field_visibility' ); ?> 758 759 <p class="field-visibility-settings-<?php echo $can_change_visibility ? 'toggle' : 'notoggle'; ?>" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id(); ?>"> 760 761 <?php printf( __( 'This field can be seen by: <span class="%s">%s</span>', 'buddypress' ), esc_attr( 'current-visibility-level' ), bp_get_the_profile_field_visibility_level_label() ); ?> 729 762 730 763 <?php if ( $can_change_visibility ) : ?> 731 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 732 <fieldset> 733 <legend><?php _e( 'Who can see this field?', 'buddypress' ); ?></legend> 734 <?php bp_profile_visibility_radio_buttons(); ?> 735 </fieldset> 736 <a class="button field-visibility-settings-close" href="#"><?php _e( 'Close', 'buddypress' ); ?></a> 737 </div> 738 <?php endif; 739 740 do_action( 'bp_custom_profile_edit_fields' ); ?> 741 </div> 742 743 <?php 744 endwhile; // bp_profile_fields() 745 746 endwhile; // bp_profile_groups() 747 endif; 764 765 <a href="#" class="button visibility-toggle-link"><?php esc_html_e( 'Change', 'buddypress' ); ?></a> 766 767 <?php endif; ?> 768 </p> 769 770 <?php if ( $can_change_visibility ) : ?> 771 772 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 773 <fieldset> 774 <legend><?php _e( 'Who can see this field?', 'buddypress' ); ?></legend> 775 776 <?php bp_profile_visibility_radio_buttons(); ?> 777 778 </fieldset> 779 <a class="button field-visibility-settings-close" href="#"><?php esc_html_e( 'Close', 'buddypress' ); ?></a> 780 </div> 781 782 <?php endif; ?> 783 784 <?php do_action( 'bp_custom_profile_edit_fields' ); ?> 785 786 </div> 787 788 <?php endwhile; // bp_profile_fields() ?> 789 790 <?php endwhile; // bp_profile_groups 748 791 } 749 792 … … 757 800 */ 758 801 public function user_admin_spammer_metabox( $user = null ) { 759 802 ?> 760 803 <p><?php printf( __( '%s has been marked as a spammer. All BuddyPress data associated with the user has been removed', 'buddypress' ), esc_html( bp_core_get_user_displayname( $user->ID ) ) ) ;?></p> 761 804 <?php 762 805 } 763 806 … … 774 817 if ( empty( $user->ID ) ) { 775 818 return; 776 } 777 778 $args = array( 779 'item_id' => $user->ID, 780 'object' => 'user', 781 'type' => 'full', 782 'title' => $user->display_name 783 ); 784 785 ?> 819 } ?> 786 820 787 821 <div class="avatar"> 788 822 789 <?php echo bp_core_fetch_avatar( $args ); ?> 823 <?php echo bp_core_fetch_avatar( array( 824 'item_id' => $user->ID, 825 'object' => 'user', 826 'type' => 'full', 827 'title' => $user->display_name 828 ) ); ?> 790 829 791 830 <?php if ( bp_get_user_has_avatar( $user->ID ) ) : … … 796 835 ); 797 836 798 if ( ! empty( $_REQUEST['wp_http_referer'] ) ) 837 if ( ! empty( $_REQUEST['wp_http_referer'] ) ) { 799 838 $query_args['wp_http_referer'] = urlencode( wp_unslash( $_REQUEST['wp_http_referer'] ) ); 800 801 $community_url = add_query_arg( $query_args, buddypress()->members->admin->edit_profile_url ); 802 $delete_link = wp_nonce_url( $community_url, 'delete_avatar' ); ?> 839 } 840 841 $community_url = add_query_arg( $query_args, buddypress()->members->admin->edit_profile_url ); 842 $delete_link = wp_nonce_url( $community_url, 'delete_avatar' ); ?> 803 843 804 844 <a href="<?php echo esc_url( $delete_link ); ?>" title="<?php esc_attr_e( 'Delete Avatar', 'buddypress' ); ?>" class="bp-xprofile-avatar-user-admin"><?php esc_html_e( 'Delete Avatar', 'buddypress' ); ?></a></li>
Note: See TracChangeset
for help on using the changeset viewer.