[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/classes/ -> class-bp-members-admin.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Members Admin
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersAdmin
   7   * @since 2.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  if ( !class_exists( 'BP_Members_Admin' ) ) :
  14  
  15  /**
  16   * Load Members admin area.
  17   *
  18   * @since 2.0.0
  19   */
  20  class BP_Members_Admin {
  21  
  22      /** Directory *************************************************************/
  23  
  24      /**
  25       * Path to the BP Members Admin directory.
  26       *
  27       * @var string $admin_dir
  28       */
  29      public $admin_dir = '';
  30  
  31      /** URLs ******************************************************************/
  32  
  33      /**
  34       * URL to the BP Members Admin directory.
  35       *
  36       * @var string $admin_url
  37       */
  38      public $admin_url = '';
  39  
  40      /**
  41       * URL to the BP Members Admin CSS directory.
  42       *
  43       * @var string $css_url
  44       */
  45      public $css_url = '';
  46  
  47      /**
  48       * URL to the BP Members Admin JS directory.
  49       *
  50       * @var string
  51       */
  52      public $js_url = '';
  53  
  54      /** Other *****************************************************************/
  55  
  56      /**
  57       * Screen id for edit user's profile page.
  58       *
  59       * @var string
  60       */
  61      public $user_page = '';
  62  
  63      /**
  64       * Setup BP Members Admin.
  65       *
  66       * @since 2.0.0
  67       *
  68       * @return BP_Members_Admin
  69       */
  70  	public static function register_members_admin() {
  71          if ( ! is_admin() ) {
  72              return;
  73          }
  74  
  75          $bp = buddypress();
  76  
  77          if ( empty( $bp->members->admin ) ) {
  78              $bp->members->admin = new self;
  79          }
  80  
  81          return $bp->members->admin;
  82      }
  83  
  84      /**
  85       * Constructor method.
  86       *
  87       * @since 2.0.0
  88       */
  89  	public function __construct() {
  90          $this->setup_globals();
  91          $this->setup_actions();
  92      }
  93  
  94      /**
  95       * Set admin-related globals.
  96       *
  97       * @since 2.0.0
  98       */
  99  	private function setup_globals() {
 100          $bp = buddypress();
 101  
 102          // Paths and URLs
 103          $this->admin_dir = trailingslashit( $bp->plugin_dir  . 'bp-members/admin' ); // Admin path.
 104          $this->admin_url = trailingslashit( $bp->plugin_url  . 'bp-members/admin' ); // Admin URL.
 105          $this->css_url   = trailingslashit( $this->admin_url . 'css' ); // Admin CSS URL.
 106          $this->js_url    = trailingslashit( $this->admin_url . 'js'  ); // Admin CSS URL.
 107  
 108          // Capability depends on config.
 109          $this->capability = bp_core_do_network_admin() ? 'manage_network_users' : 'edit_users';
 110  
 111          // The Edit Profile Screen id.
 112          $this->user_page = '';
 113  
 114          // The Show Profile Screen id.
 115          $this->user_profile = is_network_admin() ? 'users' : 'profile';
 116  
 117          // The current user id.
 118          $this->current_user_id = get_current_user_id();
 119  
 120          // The user id being edited.
 121          $this->user_id = 0;
 122  
 123          // Is a member editing their own profile.
 124          $this->is_self_profile = false;
 125  
 126          // The screen ids to load specific css for.
 127          $this->screen_id = array();
 128  
 129          // The stats metabox default position.
 130          $this->stats_metabox = new StdClass();
 131  
 132          // BuddyPress edit user's profile args.
 133          $this->edit_profile_args = array( 'page' => 'bp-profile-edit' );
 134          $this->edit_profile_url  = '';
 135          $this->edit_url          = '';
 136  
 137          // Data specific to signups.
 138          $this->users_page   = '';
 139          $this->signups_page = '';
 140          $this->users_url    = bp_get_admin_url( 'users.php' );
 141          $this->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users';
 142  
 143          // Specific config: BuddyPress is not network activated.
 144          $this->subsite_activated = (bool) is_multisite() && ! bp_is_network_activated();
 145  
 146          // When BuddyPress is not network activated, only Super Admin can moderate signups.
 147          if ( ! empty( $this->subsite_activated ) ) {
 148              $this->capability = 'manage_network_users';
 149          }
 150      }
 151  
 152      /**
 153       * Set admin-related actions and filters.
 154       *
 155       * @since 2.0.0
 156       */
 157  	private function setup_actions() {
 158  
 159          /** Extended Profile *************************************************
 160           */
 161  
 162          // Enqueue all admin JS and CSS.
 163          add_action( 'bp_admin_enqueue_scripts', array( $this, 'enqueue_scripts'   )        );
 164  
 165          // Add some page specific output to the <head>.
 166          add_action( 'bp_admin_head',            array( $this, 'admin_head'        ), 999   );
 167  
 168          // Add menu item to all users menu.
 169          add_action( 'admin_menu',               array( $this, 'admin_menus'       ), 5     );
 170          add_action( 'network_admin_menu',       array( $this, 'admin_menus'       ), 5     );
 171          add_action( 'user_admin_menu',          array( $this, 'user_profile_menu' ), 5     );
 172  
 173          // Create the Profile Navigation (Profile/Extended Profile).
 174          add_action( 'edit_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
 175          add_action( 'show_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
 176  
 177          // Editing users of a specific site.
 178          add_action( "admin_head-site-users.php", array( $this, 'profile_admin_head' ) );
 179  
 180          // Add a row action to users listing.
 181          if ( bp_core_do_network_admin() ) {
 182              add_filter( 'ms_user_row_actions',        array( $this, 'row_actions'                    ), 10, 2 );
 183              add_action( 'admin_init',                 array( $this, 'add_edit_profile_url_filter'    )        );
 184              add_action( 'wp_after_admin_bar_render',  array( $this, 'remove_edit_profile_url_filter' )        );
 185          }
 186  
 187          // Add user row actions for single site.
 188          add_filter( 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
 189  
 190          // Process changes to member type.
 191          add_action( 'bp_members_admin_load', array( $this, 'process_member_type_update' ) );
 192  
 193          /** Signups **********************************************************
 194           */
 195  
 196          if ( is_admin() ) {
 197  
 198              // Filter non multisite user query to remove sign-up users.
 199              if ( ! is_multisite() ) {
 200                  add_action( 'pre_user_query', array( $this, 'remove_signups_from_user_query' ), 10, 1 );
 201              }
 202  
 203              // Reorganise the views navigation in users.php and signups page.
 204              if ( current_user_can( $this->capability ) ) {
 205                  $user_screen = $this->users_screen;
 206  
 207                  /**
 208                   * Users screen on multiblog is users, but signups
 209                   * need to be managed in the network for this case
 210                   */
 211                  if ( bp_is_network_activated() && bp_is_multiblog_mode() && false === strpos( $user_screen, '-network' ) ) {
 212                      $user_screen .= '-network';
 213                  }
 214  
 215                  add_filter( "views_{$user_screen}", array( $this, 'signup_filter_view'    ), 10, 1 );
 216                  add_filter( 'set-screen-option',    array( $this, 'signup_screen_options' ), 10, 3 );
 217              }
 218  
 219              // Registration is turned on.
 220              add_action( 'update_site_option_registration',  array( $this, 'multisite_registration_on' ),   10, 2 );
 221              add_action( 'update_option_users_can_register', array( $this, 'single_site_registration_on' ), 10, 2 );
 222          }
 223  
 224          /** Users List - Members Types ***************************************
 225           */
 226  
 227          if ( is_admin() && bp_get_member_types() ) {
 228  
 229              // Add "Change type" <select> to WP admin users list table and process bulk members type changes.
 230              add_action( 'restrict_manage_users', array( $this, 'users_table_output_type_change_select' ) );
 231              add_action( 'load-users.php',        array( $this, 'users_table_process_bulk_type_change'  ) );
 232  
 233              // Add the member type column to the WP admin users list table.
 234              add_filter( 'manage_users_columns',       array( $this, 'users_table_add_type_column'    )        );
 235              add_filter( 'manage_users_custom_column', array( $this, 'users_table_populate_type_cell' ), 10, 3 );
 236  
 237              // Filter WP admin users list table to include users of the specified type.
 238              add_filter( 'pre_get_users', array( $this, 'users_table_filter_by_type' ) );
 239          }
 240      }
 241  
 242      /**
 243       * Create registration pages when multisite user registration is turned on.
 244       *
 245       * @since 2.7.0
 246       *
 247       * @param string $option_name Current option name; value is always 'registration'.
 248       * @param string $value
 249       */
 250  	public function multisite_registration_on( $option_name, $value ) {
 251          if ( 'user' === $value || 'all' === $value ) {
 252              bp_core_add_page_mappings( array(
 253                  'register' => 1,
 254                  'activate' => 1
 255              ) );
 256          }
 257      }
 258  
 259      /**
 260       * Create registration pages when single site registration is turned on.
 261       *
 262       * @since 2.7.0
 263       *
 264       * @param string $old_value
 265       * @param string $value
 266       */
 267  	public function single_site_registration_on( $old_value, $value ) {
 268          // Single site.
 269          if ( ! is_multisite() && ! empty( $value ) ) {
 270              bp_core_add_page_mappings( array(
 271                  'register' => 1,
 272                  'activate' => 1
 273              ) );
 274          }
 275      }
 276  
 277      /**
 278       * Get the user ID.
 279       *
 280       * Look for $_GET['user_id']. If anything else, force the user ID to the
 281       * current user's ID so they aren't left without a user to edit.
 282       *
 283       * @since 2.1.0
 284       *
 285       * @return int
 286       */
 287  	private function get_user_id() {
 288          if ( ! empty( $this->user_id ) ) {
 289              return $this->user_id;
 290          }
 291  
 292          $this->user_id = (int) get_current_user_id();
 293  
 294          // We'll need a user ID when not on self profile.
 295          if ( ! empty( $_GET['user_id'] ) ) {
 296              $this->user_id = (int) $_GET['user_id'];
 297          }
 298  
 299          return $this->user_id;
 300      }
 301  
 302      /**
 303       * Can the current user edit the one displayed.
 304       *
 305       * Self profile editing / or bp_moderate check.
 306       * This might be replaced by more granular capabilities
 307       * in the future.
 308       *
 309       * @since 2.1.0
 310       *
 311       * @param int $user_id ID of the user being checked for edit ability.
 312       *
 313       * @return bool
 314       */
 315  	private function member_can_edit( $user_id = 0 ) {
 316          $retval = false;
 317  
 318          // Bail if no user ID was passed.
 319          if ( empty( $user_id ) ) {
 320              return $retval;
 321          }
 322  
 323          // Member can edit if they are viewing their own profile.
 324          if ( $this->current_user_id === $user_id ) {
 325              $retval = true;
 326  
 327          // Trust the 'bp_moderate' capability.
 328          } else {
 329              $retval = bp_current_user_can( 'bp_moderate' );
 330          }
 331  
 332          return $retval;
 333      }
 334  
 335      /**
 336       * Get admin notice when saving a user or member profile.
 337       *
 338       * @since 2.1.0
 339       *
 340       * @return array
 341       */
 342  	private function get_user_notice() {
 343  
 344          // Setup empty notice for return value.
 345          $notice = array();
 346  
 347          // Updates.
 348          if ( ! empty( $_REQUEST['updated'] ) ) {
 349              switch ( $_REQUEST['updated'] ) {
 350              case 'avatar':
 351                  $notice = array(
 352                      'class'   => 'updated',
 353                      'message' => __( 'Profile photo was deleted.', 'buddypress' )
 354                  );
 355                  break;
 356              case 'ham' :
 357                  $notice = array(
 358                      'class'   => 'updated',
 359                      'message' => __( 'User removed as spammer.', 'buddypress' )
 360                  );
 361                  break;
 362              case 'spam' :
 363                  $notice = array(
 364                      'class'   => 'updated',
 365                      'message' => __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' )
 366                  );
 367                  break;
 368              case 1 :
 369                  $notice = array(
 370                      'class'   => 'updated',
 371                      'message' => __( 'Profile updated.', 'buddypress' )
 372                  );
 373                  break;
 374              }
 375          }
 376  
 377          // Errors.
 378          if ( ! empty( $_REQUEST['error'] ) ) {
 379              switch ( $_REQUEST['error'] ) {
 380              case 'avatar':
 381                  $notice = array(
 382                      'class'   => 'error',
 383                      'message' => __( 'There was a problem deleting that profile photo. Please try again.', 'buddypress' )
 384                  );
 385                  break;
 386              case 'ham' :
 387                  $notice = array(
 388                      'class'   => 'error',
 389                      'message' => __( 'User could not be removed as spammer.', 'buddypress' )
 390                  );
 391                  break;
 392              case 'spam' :
 393                  $notice = array(
 394                      'class'   => 'error',
 395                      'message' => __( 'User could not be marked as spammer.', 'buddypress' )
 396                  );
 397                  break;
 398              case 1 :
 399                  $notice = array(
 400                      'class'   => 'error',
 401                      'message' => __( 'An error occurred while trying to update the profile.', 'buddypress' )
 402                  );
 403                  break;
 404              case 2:
 405                  $notice = array(
 406                      'class'   => 'error',
 407                      'message' => __( 'Your changes have not been saved. Please fill in all required fields, and save your changes again.', 'buddypress' )
 408                  );
 409                  break;
 410              case 3:
 411                  $notice = array(
 412                      'class'   => 'error',
 413                      'message' => __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' )
 414                  );
 415                  break;
 416              }
 417          }
 418  
 419          return $notice;
 420      }
 421  
 422      /**
 423       * Create the /user/ admin Profile submenus for all members.
 424       *
 425       * @since 2.1.0
 426       *
 427       */
 428  	public function user_profile_menu() {
 429  
 430          // Setup the hooks array.
 431          $hooks = array();
 432  
 433          // Add the faux "Edit Profile" submenu page.
 434          $hooks['user'] = $this->user_page = add_submenu_page(
 435              'profile.php',
 436              __( 'Edit Profile',  'buddypress' ),
 437              __( 'Edit Profile',  'buddypress' ),
 438              'exist',
 439              'bp-profile-edit',
 440              array( $this, 'user_admin' )
 441          );
 442  
 443          // Setup the screen ID's.
 444          $this->screen_id = array(
 445              $this->user_page    . '-user',
 446              $this->user_profile . '-user'
 447          );
 448  
 449          // Loop through new hooks and add method actions.
 450          foreach ( $hooks as $key => $hook ) {
 451              add_action( "load-{$hook}", array( $this, $key . '_admin_load' ) );
 452          }
 453  
 454          // Add the profile_admin_head method to proper admin_head actions.
 455          add_action( "admin_head-{$this->user_page}", array( $this, 'profile_admin_head' ) );
 456          add_action( "admin_head-profile.php",        array( $this, 'profile_admin_head' ) );
 457      }
 458  
 459      /**
 460       * Create the All Users / Profile > Edit Profile and All Users Signups submenus.
 461       *
 462       * @since 2.0.0
 463       *
 464       */
 465  	public function admin_menus() {
 466  
 467          // Setup the hooks array.
 468          $hooks = array();
 469  
 470          // Manage user's profile.
 471          $hooks['user'] = $this->user_page = add_submenu_page(
 472              $this->user_profile . '.php',
 473              __( 'Edit Profile',  'buddypress' ),
 474              __( 'Edit Profile',  'buddypress' ),
 475              'read',
 476              'bp-profile-edit',
 477              array( $this, 'user_admin' )
 478          );
 479  
 480          // Only show sign-ups where they belong.
 481          if ( ( ! bp_is_network_activated() && ! is_network_admin() ) || ( is_network_admin() && bp_is_network_activated() ) ) {
 482  
 483              // Manage signups.
 484              $hooks['signups'] = $this->signups_page = add_users_page(
 485                  __( 'Manage Signups',  'buddypress' ),
 486                  __( 'Manage Signups',  'buddypress' ),
 487                  $this->capability,
 488                  'bp-signups',
 489                  array( $this, 'signups_admin' )
 490              );
 491          }
 492  
 493          $edit_page         = 'user-edit';
 494          $profile_page      = 'profile';
 495          $this->users_page  = 'users';
 496  
 497          // Self profile check is needed for this pages.
 498          $page_head = array(
 499              $edit_page        . '.php',
 500              $profile_page     . '.php',
 501              $this->user_page,
 502              $this->users_page . '.php',
 503          );
 504  
 505          // Append '-network' to each array item if in network admin.
 506          if ( is_network_admin() ) {
 507              $edit_page          .= '-network';
 508              $profile_page       .= '-network';
 509              $this->user_page    .= '-network';
 510              $this->users_page   .= '-network';
 511              $this->signups_page .= '-network';
 512          }
 513  
 514          // Setup the screen ID's.
 515          $this->screen_id = array(
 516              $edit_page,
 517              $this->user_page,
 518              $profile_page
 519          );
 520  
 521          // Loop through new hooks and add method actions.
 522          foreach ( $hooks as $key => $hook ) {
 523              add_action( "load-{$hook}", array( $this, $key . '_admin_load' ) );
 524          }
 525  
 526          // Add the profile_admin_head method to proper admin_head actions.
 527          foreach ( $page_head as $head ) {
 528              add_action( "admin_head-{$head}", array( $this, 'profile_admin_head' ) );
 529          }
 530      }
 531  
 532      /**
 533       * Highlight the Users menu if on Edit Profile and check if on the user's admin profile.
 534       *
 535       * @since 2.1.0
 536       */
 537  	public function profile_admin_head() {
 538          global $submenu_file, $parent_file;
 539  
 540          // Is the user editing their own profile?
 541          if ( is_user_admin() || ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) ) {
 542              $this->is_self_profile = true;
 543  
 544          // Is the user attempting to edit their own profile.
 545          } elseif ( isset( $_GET['user_id' ] ) || ( isset( $_GET['page'] ) && ( 'bp-profile-edit' === $_GET['page'] ) ) ) {
 546              $this->is_self_profile = (bool) ( $this->get_user_id() === $this->current_user_id );
 547          }
 548  
 549          // Force the parent file to users.php to open the correct top level menu
 550          // but only if not editing a site via the network site editing page.
 551          if ( 'sites.php' !== $parent_file ) {
 552              $parent_file  = 'users.php';
 553              $submenu_file = 'users.php';
 554          }
 555  
 556          // Editing your own profile, so recheck some vars.
 557          if ( true === $this->is_self_profile ) {
 558  
 559              // Use profile.php as the edit page.
 560              $edit_page = 'profile.php';
 561  
 562              // Set profile.php as the parent & sub files to correct the menu nav.
 563              if ( is_blog_admin() || is_user_admin() ) {
 564                  $parent_file  = 'profile.php';
 565                  $submenu_file = 'profile.php';
 566              }
 567  
 568          // Not editing yourself, so use user-edit.php.
 569          } else {
 570              $edit_page = 'user-edit.php';
 571          }
 572  
 573          if ( is_user_admin() ) {
 574              $this->edit_profile_url = add_query_arg( $this->edit_profile_args, user_admin_url( 'profile.php' ) );
 575              $this->edit_url         = user_admin_url( 'profile.php' );
 576  
 577          } elseif ( is_blog_admin() ) {
 578              $this->edit_profile_url = add_query_arg( $this->edit_profile_args, admin_url( 'users.php' ) );
 579              $this->edit_url         = admin_url( $edit_page );
 580  
 581          } elseif ( is_network_admin() ) {
 582              $this->edit_profile_url = add_query_arg( $this->edit_profile_args, network_admin_url( 'users.php' ) );
 583              $this->edit_url         = network_admin_url( $edit_page );
 584          }
 585      }
 586  
 587      /**
 588       * Remove the Edit Profile page.
 589       *
 590       * We add these pages in order to integrate with WP's Users panel, but
 591       * we want them to show up as a row action of the WP panel, not as separate
 592       * subnav items under the Users menu.
 593       *
 594       * @since 2.0.0
 595       */
 596  	public function admin_head() {
 597          remove_submenu_page( 'users.php',   'bp-profile-edit' );
 598          remove_submenu_page( 'profile.php', 'bp-profile-edit' );
 599      }
 600  
 601      /** Community Profile *****************************************************/
 602  
 603      /**
 604       * Add some specific styling to the Edit User and Edit User's Profile page.
 605       *
 606       * @since 2.0.0
 607       */
 608  	public function enqueue_scripts() {
 609          if ( ! in_array( get_current_screen()->id, $this->screen_id ) ) {
 610              return;
 611          }
 612  
 613          $min = bp_core_get_minified_asset_suffix();
 614          $css = $this->css_url . "admin{$min}.css";
 615  
 616          /**
 617           * Filters the CSS URL to enqueue in the Members admin area.
 618           *
 619           * @since 2.0.0
 620           *
 621           * @param string $css URL to the CSS admin file to load.
 622           */
 623          $css = apply_filters( 'bp_members_admin_css', $css );
 624  
 625          wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
 626  
 627          wp_style_add_data( 'bp-members-css', 'rtl', 'replace' );
 628          if ( $min ) {
 629              wp_style_add_data( 'bp-members-css', 'suffix', $min );
 630          }
 631  
 632          // Only load JavaScript for BuddyPress profile.
 633          if ( get_current_screen()->id == $this->user_page ) {
 634              $js = $this->js_url . "admin{$min}.js";
 635  
 636              /**
 637               * Filters the JS URL to enqueue in the Members admin area.
 638               *
 639               * @since 2.0.0
 640               *
 641               * @param string $js URL to the JavaScript admin file to load.
 642               */
 643              $js = apply_filters( 'bp_members_admin_js', $js );
 644              wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
 645          }
 646  
 647          /**
 648           * Fires after all of the members JavaScript and CSS are enqueued.
 649           *
 650           * @since 2.0.0
 651           *
 652           * @param string $id        ID of the current screen.
 653           * @param array  $screen_id Array of allowed screens to add scripts and styles to.
 654           */
 655          do_action( 'bp_members_admin_enqueue_scripts', get_current_screen()->id, $this->screen_id );
 656      }
 657  
 658      /**
 659       * Create the Profile navigation in Edit User & Edit Profile pages.
 660       *
 661       * @since 2.0.0
 662       *
 663       * @param object|null $user   User to create profile navigation for.
 664       * @param string      $active Which profile to highlight.
 665       * @return string|null
 666       */
 667  	public function profile_nav( $user = null, $active = 'WordPress' ) {
 668  
 669          // Bail if no user ID exists here.
 670          if ( empty( $user->ID ) ) {
 671              return;
 672          }
 673  
 674          // Add the user ID to query arguments when not editing yourself.
 675          if ( false === $this->is_self_profile ) {
 676              $query_args = array( 'user_id' => $user->ID );
 677          } else {
 678              $query_args = array();
 679          }
 680  
 681          // Conditionally add a referer if it exists in the existing request.
 682          if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
 683              $wp_http_referer = wp_unslash( $_REQUEST['wp_http_referer'] );
 684              $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
 685              $query_args['wp_http_referer'] = urlencode( $wp_http_referer );
 686          }
 687  
 688          // Setup the two distinct "edit" URL's.
 689          $community_url = add_query_arg( $query_args, $this->edit_profile_url );
 690          $wordpress_url = add_query_arg( $query_args, $this->edit_url         );
 691  
 692          $bp_active = false;
 693          $wp_active = ' nav-tab-active';
 694          if ( 'BuddyPress' === $active ) {
 695              $bp_active = ' nav-tab-active';
 696              $wp_active = false;
 697          } ?>
 698  
 699          <h2 id="profile-nav" class="nav-tab-wrapper">
 700              <?php
 701              /**
 702               * In configs where BuddyPress is not network activated, as regular
 703               * admins do not have the capacity to edit other users, we must add
 704               * this check.
 705               */
 706              if ( current_user_can( 'edit_user', $user->ID ) ) : ?>
 707  
 708                  <a class="nav-tab<?php echo esc_attr( $wp_active ); ?>" href="<?php echo esc_url( $wordpress_url );?>"><?php _e( 'Profile', 'buddypress' ); ?></a>
 709  
 710              <?php endif; ?>
 711  
 712              <a class="nav-tab<?php echo esc_attr( $bp_active ); ?>" href="<?php echo esc_url( $community_url );?>"><?php _e( 'Extended Profile', 'buddypress' ); ?></a>
 713          </h2>
 714  
 715          <?php
 716      }
 717  
 718      /**
 719       * Set up the user's profile admin page.
 720       *
 721       * Loaded before the page is rendered, this function does all initial
 722       * setup, including: processing form requests, registering contextual
 723       * help, and setting up screen options.
 724       *
 725       * @since 2.0.0
 726       */
 727  	public function user_admin_load() {
 728  
 729          // Get the user ID.
 730          $user_id = $this->get_user_id();
 731  
 732          // Can current user edit this profile?
 733          if ( ! $this->member_can_edit( $user_id ) ) {
 734              wp_die( __( 'You cannot edit the requested user.', 'buddypress' ) );
 735          }
 736  
 737          // Build redirection URL.
 738          $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham', 'delete_avatar' ), $_SERVER['REQUEST_URI'] );
 739          $doaction    = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;
 740  
 741          if ( ! empty( $_REQUEST['user_status'] ) ) {
 742              $spam = (bool) ( 'spam' === $_REQUEST['user_status'] );
 743  
 744              if ( $spam !== bp_is_user_spammer( $user_id ) ) {
 745                  $doaction = $_REQUEST['user_status'];
 746              }
 747          }
 748  
 749          /**
 750           * Fires at the start of the signups admin load.
 751           *
 752           * @since 2.0.0
 753           *
 754           * @param string $doaction Current bulk action being processed.
 755           * @param array  $_REQUEST Current $_REQUEST global.
 756           */
 757          do_action_ref_array( 'bp_members_admin_load', array( $doaction, $_REQUEST ) );
 758  
 759          /**
 760           * Filters the allowed actions for use in the user admin page.
 761           *
 762           * @since 2.0.0
 763           *
 764           * @param array $value Array of allowed actions to use.
 765           */
 766          $allowed_actions = apply_filters( 'bp_members_admin_allowed_actions', array( 'update', 'delete_avatar', 'spam', 'ham' ) );
 767  
 768          // Prepare the display of the Community Profile screen.
 769          if ( ! in_array( $doaction, $allowed_actions ) ) {
 770              add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
 771  
 772              get_current_screen()->add_help_tab( array(
 773                  'id'      => 'bp-profile-edit-overview',
 774                  'title'   => __( 'Overview', 'buddypress' ),
 775                  'content' =>
 776                  '<p>' . __( 'This is the admin view of a user&#39;s profile.', 'buddypress' ) . '</p>' .
 777                  '<p>' . __( 'In the main column, you can edit the fields of the user&#39;s extended profile.', 'buddypress' ) . '</p>' .
 778                  '<p>' . __( 'In the right-hand column, you can update the user&#39;s status, delete the user&#39;s avatar, and view recent statistics.', 'buddypress' ) . '</p>'
 779              ) );
 780  
 781              // Help panel - sidebar links.
 782              get_current_screen()->set_help_sidebar(
 783                  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
 784                  '<p>' . __( '<a href="https://codex.buddypress.org/administrator-guide/extended-profiles/">Managing Profiles</a>', 'buddypress' ) . '</p>' .
 785                  '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
 786              );
 787  
 788              // Register metaboxes for the edit screen.
 789              add_meta_box(
 790                  'submitdiv',
 791                  _x( 'Status', 'members user-admin edit screen', 'buddypress' ),
 792                  array( $this, 'user_admin_status_metabox' ),
 793                  get_current_screen()->id,
 794                  'side',
 795                  'core'
 796              );
 797  
 798              // In case xprofile is not active.
 799              $this->stats_metabox->context  = 'normal';
 800              $this->stats_metabox->priority = 'core';
 801  
 802              /**
 803               * Fires before loading the profile fields if component is active.
 804               *
 805               * Plugins should not use this hook, please use 'bp_members_admin_user_metaboxes' instead.
 806               *
 807               * @since 2.0.0
 808               *
 809               * @param int    $user_id       Current user ID for the screen.
 810               * @param string $id            Current screen ID.
 811               * @param object $stats_metabox Object holding position data for use with the stats metabox.
 812               */
 813              do_action_ref_array( 'bp_members_admin_xprofile_metabox', array( $user_id, get_current_screen()->id, $this->stats_metabox ) );
 814  
 815              // If xProfile is inactive, difficult to know what's profile we're on.
 816              if ( 'normal' === $this->stats_metabox->context ) {
 817                  $display_name = bp_core_get_user_displayname( $user_id );
 818              } else {
 819                  $display_name = __( 'Member', 'buddypress' );
 820              }
 821  
 822              // User Stat metabox.
 823              add_meta_box(
 824                  'bp_members_admin_user_stats',
 825                  sprintf( _x( "%s's Stats", 'members user-admin edit screen', 'buddypress' ), $display_name ),
 826                  array( $this, 'user_admin_stats_metabox' ),
 827                  get_current_screen()->id,
 828                  sanitize_key( $this->stats_metabox->context ),
 829                  sanitize_key( $this->stats_metabox->priority )
 830              );
 831  
 832              // Member Type metabox. Only added if member types have been registered.
 833              $member_types = bp_get_member_types();
 834              if ( ! empty( $member_types ) ) {
 835                  add_meta_box(
 836                      'bp_members_admin_member_type',
 837                      _x( 'Member Type', 'members user-admin edit screen', 'buddypress' ),
 838                      array( $this, 'user_admin_member_type_metabox' ),
 839                      get_current_screen()->id,
 840                      'side',
 841                      'core'
 842                  );
 843              }
 844  
 845              /**
 846               * Fires at the end of the Community Profile screen.
 847               *
 848               * Plugins can restrict metabox to "bp_moderate" admins by checking if
 849               * the first argument ($this->is_self_profile) is false in their callback.
 850               * They can also restrict their metabox to self profile editing
 851               * by setting it to true.
 852               *
 853               * @since 2.0.0
 854               *
 855               * @param bool $is_self_profile Whether or not it is the current user's profile.
 856               * @param int  $user_id         Current user ID.
 857               */
 858              do_action( 'bp_members_admin_user_metaboxes', $this->is_self_profile, $user_id );
 859  
 860              // Enqueue JavaScript files.
 861              wp_enqueue_script( 'postbox'   );
 862              wp_enqueue_script( 'dashboard' );
 863  
 864          // Spam or Ham user.
 865          } elseif ( in_array( $doaction, array( 'spam', 'ham' ) ) && empty( $this->is_self_profile ) ) {
 866  
 867              check_admin_referer( 'edit-bp-profile_' . $user_id );
 868  
 869              if ( bp_core_process_spammer_status( $user_id, $doaction ) ) {
 870                  $redirect_to = add_query_arg( 'updated', $doaction, $redirect_to );
 871              } else {
 872                  $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
 873              }
 874  
 875              bp_core_redirect( $redirect_to );
 876  
 877          // Update other stuff once above ones are done.
 878          } else {
 879              $this->redirect = $redirect_to;
 880  
 881              /**
 882               * Fires at end of user profile admin load if doaction does not match any available actions.
 883               *
 884               * @since 2.0.0
 885               *
 886               * @param string $doaction Current bulk action being processed.
 887               * @param int    $user_id  Current user ID.
 888               * @param array  $_REQUEST Current $_REQUEST global.
 889               * @param string $redirect Determined redirect url to send user to.
 890               */
 891              do_action_ref_array( 'bp_members_admin_update_user', array( $doaction, $user_id, $_REQUEST, $this->redirect ) );
 892  
 893              bp_core_redirect( $this->redirect );
 894          }
 895      }
 896  
 897      /**
 898       * Display the user's profile.
 899       *
 900       * @since 2.0.0
 901       */
 902  	public function user_admin() {
 903  
 904          if ( ! bp_current_user_can( 'bp_moderate' ) && empty( $this->is_self_profile ) ) {
 905              die( '-1' );
 906          }
 907  
 908          // Get the user ID.
 909          $user_id = $this->get_user_id();
 910          $user    = get_user_to_edit( $user_id );
 911  
 912          // Construct title.
 913          if ( true === $this->is_self_profile ) {
 914              $title = __( 'Profile',   'buddypress' );
 915          } else {
 916              $title = __( 'Edit User', 'buddypress' );
 917          }
 918  
 919          // Construct URL for form.
 920          $request_url     = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham' ), $_SERVER['REQUEST_URI'] );
 921          $form_action_url = add_query_arg( 'action', 'update', $request_url );
 922          $wp_http_referer = false;
 923          if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
 924              $wp_http_referer = wp_unslash( $_REQUEST['wp_http_referer'] );
 925              $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $wp_http_referer );
 926              $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
 927          }
 928  
 929          // Prepare notice for admin.
 930          $notice = $this->get_user_notice();
 931  
 932          if ( ! empty( $notice ) ) : ?>
 933  
 934              <div <?php if ( 'updated' === $notice['class'] ) : ?>id="message" <?php endif; ?>class="<?php echo esc_attr( $notice['class'] ); ?>">
 935  
 936                  <p><?php echo esc_html( $notice['message'] ); ?></p>
 937  
 938                  <?php if ( !empty( $wp_http_referer ) && ( 'updated' === $notice['class'] ) ) : ?>
 939  
 940                      <p><a href="<?php echo esc_url( $wp_http_referer ); ?>"><?php esc_html_e( '&larr; Back to Users', 'buddypress' ); ?></a></p>
 941  
 942                  <?php endif; ?>
 943  
 944              </div>
 945  
 946          <?php endif; ?>
 947  
 948          <div class="wrap" id="community-profile-page">
 949              <?php if ( version_compare( $GLOBALS['wp_version'], '4.8', '>=' ) ) : ?>
 950  
 951                  <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
 952  
 953                  <?php if ( empty( $this->is_self_profile ) ) : ?>
 954  
 955                      <?php if ( current_user_can( 'create_users' ) ) : ?>
 956  
 957                          <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
 958  
 959                      <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
 960  
 961                          <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
 962  
 963                      <?php endif; ?>
 964  
 965                  <?php endif; ?>
 966  
 967                  <hr class="wp-header-end">
 968  
 969              <?php else : ?>
 970  
 971                  <h1><?php echo esc_html( $title ); ?>
 972  
 973                      <?php if ( empty( $this->is_self_profile ) ) : ?>
 974  
 975                          <?php if ( current_user_can( 'create_users' ) ) : ?>
 976  
 977                              <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
 978  
 979                          <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
 980  
 981                              <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
 982  
 983                          <?php endif; ?>
 984  
 985                      <?php endif; ?>
 986                  </h1>
 987  
 988              <?php endif; ?>
 989  
 990              <?php if ( ! empty( $user ) ) :
 991  
 992                  $this->profile_nav( $user, 'BuddyPress' ); ?>
 993  
 994                  <form action="<?php echo esc_url( $form_action_url ); ?>" id="your-profile" method="post">
 995                      <div id="poststuff">
 996  
 997                          <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
 998  
 999                              <div id="postbox-container-1" class="postbox-container">
1000                                  <?php do_meta_boxes( get_current_screen()->id, 'side', $user ); ?>
1001                              </div>
1002  
1003                              <div id="postbox-container-2" class="postbox-container">
1004                                  <?php do_meta_boxes( get_current_screen()->id, 'normal',   $user ); ?>
1005                                  <?php do_meta_boxes( get_current_screen()->id, 'advanced', $user ); ?>
1006                              </div>
1007                          </div><!-- #post-body -->
1008  
1009                      </div><!-- #poststuff -->
1010  
1011                      <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
1012                      <?php wp_nonce_field( 'meta-box-order',  'meta-box-order-nonce', false ); ?>
1013                      <?php wp_nonce_field( 'edit-bp-profile_' . $user->ID ); ?>
1014  
1015                  </form>
1016  
1017              <?php else : ?>
1018  
1019                  <p><?php
1020                      printf(
1021                          '%1$s <a href="%2$s">%3$s</a>',
1022                          __( 'No user found with this ID.', 'buddypress' ),
1023                          esc_url( bp_get_admin_url( 'users.php' ) ),
1024                          __( 'Go back and try again.', 'buddypress' )
1025                      );
1026                  ?></p>
1027  
1028              <?php endif; ?>
1029  
1030          </div><!-- .wrap -->
1031          <?php
1032      }
1033  
1034      /**
1035       * Render the Status metabox for user's profile screen.
1036       *
1037       * Actions are:
1038       * - Update profile fields if xProfile component is active
1039       * - Spam/Unspam user
1040       *
1041       * @since 2.0.0
1042       *
1043       * @param WP_User|null $user The WP_User object to be edited.
1044       */
1045  	public function user_admin_status_metabox( $user = null ) {
1046  
1047          // Bail if no user id or if the user has not activated their account yet.
1048          if ( empty( $user->ID ) ) {
1049              return;
1050          }
1051  
1052          // Bail if user has not been activated yet (how did you get here?).
1053          if ( isset( $user->user_status ) && ( 2 == $user->user_status ) ) : ?>
1054  
1055              <p class="not-activated"><?php esc_html_e( 'User account has not yet been activated', 'buddypress' ); ?></p><br/>
1056  
1057              <?php return;
1058  
1059          endif; ?>
1060  
1061          <div class="submitbox" id="submitcomment">
1062              <div id="minor-publishing">
1063                  <div id="misc-publishing-actions">
1064                      <?php
1065  
1066                      // Get the spam status once here to compare against below.
1067                      $is_spammer = bp_is_user_spammer( $user->ID );
1068  
1069                      /**
1070                       * In configs where BuddyPress is not network activated,
1071                       * regular admins cannot mark a user as a spammer on front
1072                       * end. This prevent them to do it in the back end.
1073                       *
1074                       * Also prevent admins from marking themselves or other
1075                       * admins as spammers.
1076                       */
1077                      if ( ( empty( $this->is_self_profile ) && ( ! in_array( $user->user_login, get_super_admins() ) ) && empty( $this->subsite_activated ) ) || ( ! empty( $this->subsite_activated ) && current_user_can( 'manage_network_users' ) ) ) : ?>
1078  
1079                          <div class="misc-pub-section" id="comment-status-radio">
1080                              <label class="approved"><input type="radio" name="user_status" value="ham" <?php checked( $is_spammer, false ); ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></label><br />
1081                              <label class="spam"><input type="radio" name="user_status" value="spam" <?php checked( $is_spammer, true ); ?>><?php esc_html_e( 'Spammer', 'buddypress' ); ?></label>
1082                          </div>
1083  
1084                      <?php endif ;?>
1085  
1086                      <div class="misc-pub-section curtime misc-pub-section-last">
1087                          <?php
1088  
1089                          // Translators: Publish box date format, see http://php.net/date.
1090                          $datef = __( 'M j, Y @ G:i', 'buddypress' );
1091                          $date  = date_i18n( $datef, strtotime( $user->user_registered ) );
1092                          ?>
1093                          <span id="timestamp"><?php printf( __( 'Registered on: %s', 'buddypress' ), '<strong>' . $date . '</strong>' ); ?></span>
1094                      </div>
1095                  </div> <!-- #misc-publishing-actions -->
1096  
1097                  <div class="clear"></div>
1098              </div><!-- #minor-publishing -->
1099  
1100              <div id="major-publishing-actions">
1101  
1102                  <div id="publishing-action">
1103                      <a class="button bp-view-profile" href="<?php echo esc_url( bp_core_get_user_domain( $user->ID ) ); ?>" target="_blank"><?php esc_html_e( 'View Profile', 'buddypress' ); ?></a>
1104                      <?php submit_button( esc_html__( 'Update Profile', 'buddypress' ), 'primary', 'save', false ); ?>
1105                  </div>
1106                  <div class="clear"></div>
1107              </div><!-- #major-publishing-actions -->
1108  
1109          </div><!-- #submitcomment -->
1110  
1111          <?php
1112      }
1113  
1114      /**
1115       * Render the fallback metabox in case a user has been marked as a spammer.
1116       *
1117       * @since 2.0.0
1118       *
1119       * @param WP_User|null $user The WP_User object to be edited.
1120       */
1121  	public function user_admin_spammer_metabox( $user = null ) {
1122      ?>
1123          <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>
1124      <?php
1125      }
1126  
1127      /**
1128       * Render the Stats metabox to moderate inappropriate images.
1129       *
1130       * @since 2.0.0
1131       *
1132       * @param WP_User|null $user The WP_User object to be edited.
1133       */
1134  	public function user_admin_stats_metabox( $user = null ) {
1135  
1136          // Bail if no user ID.
1137          if ( empty( $user->ID ) ) {
1138              return;
1139          }
1140  
1141          // If account is not activated last activity is the time user registered.
1142          if ( isset( $user->user_status ) && 2 == $user->user_status ) {
1143              $last_active = $user->user_registered;
1144  
1145          // Account is activated, getting user's last activity.
1146          } else {
1147              $last_active = bp_get_user_last_activity( $user->ID );
1148          }
1149  
1150          $datef = __( 'M j, Y @ G:i', 'buddypress' );
1151          $date  = date_i18n( $datef, strtotime( $last_active ) ); ?>
1152  
1153          <ul>
1154              <li class="bp-members-profile-stats"><?php printf( __( 'Last active: %1$s', 'buddypress' ), '<strong>' . $date . '</strong>' ); ?></li>
1155  
1156              <?php
1157              // Loading other stats only if user has activated their account.
1158              if ( empty( $user->user_status ) ) {
1159  
1160                  /**
1161                   * Fires in the user stats metabox if the user has activated their account.
1162                   *
1163                   * @since 2.0.0
1164                   *
1165                   * @param array  $value Array holding the user ID.
1166                   * @param object $user  Current displayed user object.
1167                   */
1168                  do_action( 'bp_members_admin_user_stats', array( 'user_id' => $user->ID ), $user );
1169              }
1170              ?>
1171          </ul>
1172  
1173          <?php
1174      }
1175  
1176      /**
1177       * Render the Member Type metabox.
1178       *
1179       * @since 2.2.0
1180       *
1181       * @param WP_User|null $user The WP_User object to be edited.
1182       */
1183  	public function user_admin_member_type_metabox( $user = null ) {
1184  
1185          // Bail if no user ID.
1186          if ( empty( $user->ID ) ) {
1187              return;
1188          }
1189  
1190          $types = bp_get_member_types( array(), 'objects' );
1191          $current_type = bp_get_member_type( $user->ID );
1192          ?>
1193  
1194          <label for="bp-members-profile-member-type" class="screen-reader-text"><?php
1195              /* translators: accessibility text */
1196              esc_html_e( 'Select member type', 'buddypress' );
1197          ?></label>
1198          <select name="bp-members-profile-member-type" id="bp-members-profile-member-type">
1199              <option value="" <?php selected( '', $current_type ); ?>><?php
1200                  /* translators: no option picked in select box */
1201                  esc_attr_e( '----', 'buddypress' );
1202              ?></option>
1203              <?php foreach ( $types as $type ) : ?>
1204                  <option value="<?php echo esc_attr( $type->name ) ?>" <?php selected( $type->name, $current_type ) ?>><?php echo esc_html( $type->labels['singular_name'] ) ?></option>
1205              <?php endforeach; ?>
1206          </select>
1207  
1208          <?php
1209  
1210          wp_nonce_field( 'bp-member-type-change-' . $user->ID, 'bp-member-type-nonce' );
1211      }
1212  
1213      /**
1214       * Process changes from the Member Type metabox.
1215       *
1216       * @since 2.2.0
1217       */
1218  	public function process_member_type_update() {
1219          if ( ! isset( $_POST['bp-member-type-nonce'] ) || ! isset( $_POST['bp-members-profile-member-type'] ) ) {
1220              return;
1221          }
1222  
1223          $user_id = $this->get_user_id();
1224  
1225          check_admin_referer( 'bp-member-type-change-' . $user_id, 'bp-member-type-nonce' );
1226  
1227          // Permission check.
1228          if ( ! bp_current_user_can( 'bp_moderate' ) && $user_id != bp_loggedin_user_id() ) {
1229              return;
1230          }
1231  
1232          // Member type string must either reference a valid member type, or be empty.
1233          $member_type = stripslashes( $_POST['bp-members-profile-member-type'] );
1234          if ( ! empty( $member_type ) && ! bp_get_member_type_object( $member_type ) ) {
1235              return;
1236          }
1237  
1238          /*
1239           * If an invalid member type is passed, someone's doing something
1240           * fishy with the POST request, so we can fail silently.
1241           */
1242          if ( bp_set_member_type( $user_id, $member_type ) ) {
1243              // @todo Success messages can't be posted because other stuff happens on the page load.
1244          }
1245      }
1246  
1247      /**
1248       * Add a link to Profile in Users listing row actions.
1249       *
1250       * @since 2.0.0
1251       *
1252       * @param array|string $actions WordPress row actions (edit, delete).
1253       * @param object|null  $user    The object for the user row.
1254       * @return null|string|array Merged actions.
1255       */
1256  	public function row_actions( $actions = '', $user = null ) {
1257  
1258          // Bail if no user ID.
1259          if ( empty( $user->ID ) ) {
1260              return;
1261          }
1262  
1263          // Setup args array.
1264          $args = array();
1265  
1266          // Add the user ID if it's not for the current user.
1267          if ( $user->ID !== $this->current_user_id ) {
1268              $args['user_id'] = $user->ID;
1269          }
1270  
1271          // Add the referer.
1272          $wp_http_referer = wp_unslash( $_SERVER['REQUEST_URI'] );
1273          $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
1274          $args['wp_http_referer'] = urlencode( $wp_http_referer );
1275  
1276          // Add the "Extended" link if the current user can edit this user.
1277          if ( current_user_can( 'edit_user', $user->ID ) || bp_current_user_can( 'bp_moderate' ) ) {
1278  
1279              // Add query args and setup the Extended link.
1280              $edit_profile      = add_query_arg( $args, $this->edit_profile_url );
1281              $edit_profile_link = sprintf( '<a href="%1$s">%2$s</a>',  esc_url( $edit_profile ), esc_html__( 'Extended', 'buddypress' ) );
1282  
1283              /**
1284               * Check the edit action is available
1285               * and preserve the order edit | profile | remove/delete.
1286               */
1287              if ( ! empty( $actions['edit'] ) ) {
1288                  $edit_action = $actions['edit'];
1289                  unset( $actions['edit'] );
1290  
1291                  $new_edit_actions = array(
1292                      'edit'         => $edit_action,
1293                      'edit-profile' => $edit_profile_link,
1294                  );
1295  
1296              // If not available simply add the edit profile action.
1297              } else {
1298                  $new_edit_actions = array( 'edit-profile' => $edit_profile_link );
1299              }
1300  
1301              $actions = array_merge( $new_edit_actions, $actions );
1302          }
1303  
1304          return $actions;
1305      }
1306  
1307      /**
1308       * Add a filter to edit profile url in WP Admin Bar.
1309       *
1310       * @since 2.1.0
1311       */
1312  	public function add_edit_profile_url_filter() {
1313          add_filter( 'bp_members_edit_profile_url', array( $this, 'filter_adminbar_profile_link' ), 10, 3 );
1314      }
1315  
1316      /**
1317       * Filter the profile url.
1318       *
1319       * @since 2.1.0
1320       *
1321       *
1322       * @param string $profile_link Profile Link for admin bar.
1323       * @param string $url          Profile URL.
1324       * @param int    $user_id      User ID.
1325       * @return string
1326       */
1327  	public function filter_adminbar_profile_link( $profile_link = '', $url = '', $user_id = 0 ) {
1328          if ( ! is_super_admin( $user_id ) && is_admin() ) {
1329              $profile_link = user_admin_url( 'profile.php' );
1330          }
1331          return $profile_link;
1332      }
1333  
1334      /**
1335       * Remove the filter to edit profile url in WP Admin Bar.
1336       *
1337       * @since 2.1.0
1338       */
1339  	public function remove_edit_profile_url_filter() {
1340          remove_filter( 'bp_members_edit_profile_url', array( $this, 'filter_adminbar_profile_link' ), 10 );
1341      }
1342  
1343      /** Signups Management ****************************************************/
1344  
1345      /**
1346       * Display the admin preferences about signups pagination.
1347       *
1348       * @since 2.0.0
1349       *
1350       * @param int    $value     Value for signup option.
1351       * @param string $option    Value for the option key.
1352       * @param int    $new_value Value for the saved option.
1353       * @return int The pagination preferences.
1354       */
1355  	public function signup_screen_options( $value = 0, $option = '', $new_value = 0 ) {
1356          if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option ) {
1357              return $value;
1358          }
1359  
1360          // Per page.
1361          $new_value = (int) $new_value;
1362          if ( $new_value < 1 || $new_value > 999 ) {
1363              return $value;
1364          }
1365  
1366          return $new_value;
1367      }
1368  
1369      /**
1370       * Make sure no signups will show in users list.
1371       *
1372       * This is needed to handle signups that may have not been activated
1373       * before the 2.0.0 upgrade.
1374       *
1375       * @since 2.0.0
1376       *
1377       * @param WP_User_Query|null $query The users query.
1378       * @return WP_User_Query|null The users query without the signups.
1379       */
1380  	public function remove_signups_from_user_query( $query = null ) {
1381          global $wpdb;
1382  
1383          // Bail if this is an ajax request.
1384          if ( defined( 'DOING_AJAX' ) ) {
1385              return;
1386          }
1387  
1388          // Bail if updating BuddyPress.
1389          if ( bp_is_update() ) {
1390              return;
1391          }
1392  
1393          // Bail if there is no current admin screen.
1394          if ( ! function_exists( 'get_current_screen' ) || ! get_current_screen() ) {
1395              return;
1396          }
1397  
1398          // Get current screen.
1399          $current_screen = get_current_screen();
1400  
1401          // Bail if not on a users page.
1402          if ( ! isset( $current_screen->id ) || $this->users_page !== $current_screen->id ) {
1403              return;
1404          }
1405  
1406          // Bail if already querying by an existing role.
1407          if ( ! empty( $query->query_vars['role'] ) ) {
1408              return;
1409          }
1410  
1411          $query->query_where .= " AND {$wpdb->users}.user_status != 2";
1412      }
1413  
1414      /**
1415       * Filter the WP Users List Table views to include 'bp-signups'.
1416       *
1417       * @since 2.0.0
1418       *
1419       * @param array $views WP List Table views.
1420       * @return array The views with the signup view added.
1421       */
1422  	public function signup_filter_view( $views = array() ) {
1423          global $role;
1424  
1425          // Remove the 'current' class from All if we're on the signups view.
1426          if ( 'registered' === $role ) {
1427              $views['all'] = str_replace( 'class="current"', '', $views['all'] );
1428              $class        = 'current';
1429          } else {
1430              $class        = '';
1431          }
1432  
1433          $signups = BP_Signup::count_signups();
1434  
1435          if ( is_network_admin() ) {
1436              $base_url = network_admin_url( 'users.php' );
1437          } else {
1438              $base_url = bp_get_admin_url( 'users.php' );
1439          }
1440  
1441          $url     = add_query_arg( 'page', 'bp-signups', $base_url );
1442          $text    = sprintf( _x( 'Pending %s', 'signup users', 'buddypress' ), '<span class="count">(' . number_format_i18n( $signups ) . ')</span>' );
1443  
1444          $views['registered'] = sprintf( '<a href="%1$s" class="%2$s">%3$s</a>', esc_url( $url ), $class, $text );
1445  
1446          return $views;
1447      }
1448  
1449      /**
1450       * Load the Signup WP Users List table.
1451       *
1452       * @since 2.0.0
1453       *
1454       * @param string $class    The name of the class to use.
1455       * @param string $required The parent class.
1456       * @return WP_List_Table|null The List table.
1457       */
1458  	public static function get_list_table_class( $class = '', $required = '' ) {
1459          if ( empty( $class ) ) {
1460              return;
1461          }
1462  
1463          if ( ! empty( $required ) ) {
1464              require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
1465          }
1466  
1467          return new $class();
1468      }
1469  
1470      /**
1471       * Set up the signups admin page.
1472       *
1473       * Loaded before the page is rendered, this function does all initial
1474       * setup, including: processing form requests, registering contextual
1475       * help, and setting up screen options.
1476       *
1477       * @since 2.0.0
1478       *
1479       * @global $bp_members_signup_list_table
1480       */
1481  	public function signups_admin_load() {
1482          global $bp_members_signup_list_table;
1483  
1484          // Build redirection URL.
1485          $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids' ), $_SERVER['REQUEST_URI'] );
1486          $doaction    = bp_admin_list_table_current_bulk_action();
1487  
1488          /**
1489           * Fires at the start of the signups admin load.
1490           *
1491           * @since 2.0.0
1492           *
1493           * @param string $doaction Current bulk action being processed.
1494           * @param array  $_REQUEST Current $_REQUEST global.
1495           */
1496          do_action( 'bp_signups_admin_load', $doaction, $_REQUEST );
1497  
1498          /**
1499           * Filters the allowed actions for use in the user signups admin page.
1500           *
1501           * @since 2.0.0
1502           *
1503           * @param array $value Array of allowed actions to use.
1504           */
1505          $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions', array( 'do_delete', 'do_activate', 'do_resend' ) );
1506  
1507          // Prepare the display of the Community Profile screen.
1508          if ( ! in_array( $doaction, $allowed_actions ) || ( -1 == $doaction ) ) {
1509  
1510              if ( is_network_admin() ) {
1511                  $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table', 'ms-users' );
1512              } else {
1513                  $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table', 'users' );
1514              }
1515  
1516              // The per_page screen option.
1517              add_screen_option( 'per_page', array( 'label' => _x( 'Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress' ) ) );
1518  
1519              get_current_screen()->add_help_tab( array(
1520                  'id'      => 'bp-signups-overview',
1521                  'title'   => __( 'Overview', 'buddypress' ),
1522                  'content' =>
1523                  '<p>' . __( 'This is the administration screen for pending accounts on your site.', 'buddypress' ) . '</p>' .
1524                  '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' .
1525                  '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, Email or Registered column headers.', 'buddypress' ) . '</p>' .
1526                  '<p>' . __( 'Using the search form, you can find pending accounts more easily. The Username and Email fields will be included in the search.', 'buddypress' ) . '</p>'
1527              ) );
1528  
1529              get_current_screen()->add_help_tab( array(
1530                  'id'      => 'bp-signups-actions',
1531                  'title'   => __( 'Actions', 'buddypress' ),
1532                  'content' =>
1533                  '<p>' . __( 'Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:', 'buddypress' ) . '</p>' .
1534                  '<ul><li>' . __( '"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.', 'buddypress' ) . '</li>' .
1535                  '<li>' . __( '"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' .
1536                  '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress' ) . '</p>' .
1537                  '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress' ) . '</p>'
1538              ) );
1539  
1540              // Help panel - sidebar links.
1541              get_current_screen()->set_help_sidebar(
1542                  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
1543                  '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
1544              );
1545  
1546              // Add accessible hidden headings and text for the Pending Users screen.
1547              get_current_screen()->set_screen_reader_content( array(
1548                  /* translators: accessibility text */
1549                  'heading_views'      => __( 'Filter users list', 'buddypress' ),
1550                  /* translators: accessibility text */
1551                  'heading_pagination' => __( 'Pending users list navigation', 'buddypress' ),
1552                  /* translators: accessibility text */
1553                  'heading_list'       => __( 'Pending users list', 'buddypress' ),
1554              ) );
1555  
1556          } else {
1557              if ( ! empty( $_REQUEST['signup_ids' ] ) ) {
1558                  $signups = wp_parse_id_list( $_REQUEST['signup_ids' ] );
1559              }
1560  
1561              // Handle resent activation links.
1562              if ( 'do_resend' == $doaction ) {
1563  
1564                  // Nonce check.
1565                  check_admin_referer( 'signups_resend' );
1566  
1567                  $resent = BP_Signup::resend( $signups );
1568  
1569                  if ( empty( $resent ) ) {
1570                      $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
1571                  } else {
1572                      $query_arg = array( 'updated' => 'resent' );
1573  
1574                      if ( ! empty( $resent['resent'] ) ) {
1575                          $query_arg['resent'] = count( $resent['resent'] );
1576                      }
1577  
1578                      if ( ! empty( $resent['errors'] ) ) {
1579                          $query_arg['notsent'] = count( $resent['errors'] );
1580                          set_transient( '_bp_admin_signups_errors', $resent['errors'], 30 );
1581                      }
1582  
1583                      $redirect_to = add_query_arg( $query_arg, $redirect_to );
1584                  }
1585  
1586                  bp_core_redirect( $redirect_to );
1587  
1588              // Handle activated accounts.
1589              } elseif ( 'do_activate' == $doaction ) {
1590  
1591                  // Nonce check.
1592                  check_admin_referer( 'signups_activate' );
1593  
1594                  $activated = BP_Signup::activate( $signups );
1595  
1596                  if ( empty( $activated ) ) {
1597                      $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
1598                  } else {
1599                      $query_arg = array( 'updated' => 'activated' );
1600  
1601                      if ( ! empty( $activated['activated'] ) ) {
1602                          $query_arg['activated'] = count( $activated['activated'] );
1603                      }
1604  
1605                      if ( ! empty( $activated['errors'] ) ) {
1606                          $query_arg['notactivated'] = count( $activated['errors'] );
1607                          set_transient( '_bp_admin_signups_errors', $activated['errors'], 30 );
1608                      }
1609  
1610                      $redirect_to = add_query_arg( $query_arg, $redirect_to );
1611                  }
1612  
1613                  bp_core_redirect( $redirect_to );
1614  
1615              // Handle sign-ups delete.
1616              } elseif ( 'do_delete' == $doaction ) {
1617  
1618                  // Nonce check.
1619                  check_admin_referer( 'signups_delete' );
1620  
1621                  $deleted = BP_Signup::delete( $signups );
1622  
1623                  if ( empty( $deleted ) ) {
1624                      $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
1625                  } else {
1626                      $query_arg = array( 'updated' => 'deleted' );
1627  
1628                      if ( ! empty( $deleted['deleted'] ) ) {
1629                          $query_arg['deleted'] = count( $deleted['deleted'] );
1630                      }
1631  
1632                      if ( ! empty( $deleted['errors'] ) ) {
1633                          $query_arg['notdeleted'] = count( $deleted['errors'] );
1634                          set_transient( '_bp_admin_signups_errors', $deleted['errors'], 30 );
1635                      }
1636  
1637                      $redirect_to = add_query_arg( $query_arg, $redirect_to );
1638                  }
1639  
1640                  bp_core_redirect( $redirect_to );
1641  
1642              // Plugins can update other stuff from here.
1643              } else {
1644                  $this->redirect = $redirect_to;
1645  
1646                  /**
1647                   * Fires at end of signups admin load if doaction does not match any actions.
1648                   *
1649                   * @since 2.0.0
1650                   *
1651                   * @param string $doaction Current bulk action being processed.
1652                   * @param array  $_REQUEST Current $_REQUEST global.
1653                   * @param string $redirect Determined redirect url to send user to.
1654                   */
1655                  do_action( 'bp_members_admin_update_signups', $doaction, $_REQUEST, $this->redirect );
1656  
1657                  bp_core_redirect( $this->redirect );
1658              }
1659          }
1660      }
1661  
1662      /**
1663       * Display any activation errors.
1664       *
1665       * @since 2.0.0
1666       */
1667  	public function signups_display_errors() {
1668  
1669          // Look for sign-up errors.
1670          $errors = get_transient( '_bp_admin_signups_errors' );
1671  
1672          // Bail if no activation errors.
1673          if ( empty( $errors ) ) {
1674              return;
1675          }
1676  
1677          // Loop through errors and display them.
1678          foreach ( $errors as $error ) : ?>
1679  
1680              <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li>
1681  
1682          <?php endforeach;
1683  
1684          // Delete the redirect transient.
1685          delete_transient( '_bp_admin_signups_errors' );
1686      }
1687  
1688      /**
1689       * Get admin notice when viewing the sign-up page.
1690       *
1691       * @since 2.1.0
1692       *
1693       * @return array
1694       */
1695  	private function get_signup_notice() {
1696  
1697          // Setup empty notice for return value.
1698          $notice = array();
1699  
1700          // Updates.
1701          if ( ! empty( $_REQUEST['updated'] ) ) {
1702              switch ( $_REQUEST['updated'] ) {
1703                  case 'resent':
1704                      $notice = array(
1705                          'class'   => 'updated',
1706                          'message' => ''
1707                      );
1708  
1709                      if ( ! empty( $_REQUEST['resent'] ) ) {
1710                          $notice['message'] .= sprintf(
1711                              _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ',
1712                               absint( $_REQUEST['resent'] ),
1713                               'signup resent',
1714                               'buddypress'
1715                              ),
1716                              number_format_i18n( absint( $_REQUEST['resent'] ) )
1717                          );
1718                      }
1719  
1720                      if ( ! empty( $_REQUEST['notsent'] ) ) {
1721                          $notice['message'] .= sprintf(
1722                              _nx( '%s activation email was not sent.', '%s activation emails were not sent.',
1723                               absint( $_REQUEST['notsent'] ),
1724                               'signup notsent',
1725                               'buddypress'
1726                              ),
1727                              number_format_i18n( absint( $_REQUEST['notsent'] ) )
1728                          );
1729  
1730                          if ( empty( $_REQUEST['resent'] ) ) {
1731                              $notice['class'] = 'error';
1732                          }
1733                      }
1734  
1735                      break;
1736  
1737                  case 'activated':
1738                      $notice = array(
1739                          'class'   => 'updated',
1740                          'message' => ''
1741                      );
1742  
1743                      if ( ! empty( $_REQUEST['activated'] ) ) {
1744                          $notice['message'] .= sprintf(
1745                              _nx( '%s account successfully activated! ', '%s accounts successfully activated! ',
1746                               absint( $_REQUEST['activated'] ),
1747                               'signup resent',
1748                               'buddypress'
1749                              ),
1750                              number_format_i18n( absint( $_REQUEST['activated'] ) )
1751                          );
1752                      }
1753  
1754                      if ( ! empty( $_REQUEST['notactivated'] ) ) {
1755                          $notice['message'] .= sprintf(
1756                              _nx( '%s account was not activated.', '%s accounts were not activated.',
1757                               absint( $_REQUEST['notactivated'] ),
1758                               'signup notsent',
1759                               'buddypress'
1760                              ),
1761                              number_format_i18n( absint( $_REQUEST['notactivated'] ) )
1762                          );
1763  
1764                          if ( empty( $_REQUEST['activated'] ) ) {
1765                              $notice['class'] = 'error';
1766                          }
1767                      }
1768  
1769                      break;
1770  
1771                  case 'deleted':
1772                      $notice = array(
1773                          'class'   => 'updated',
1774                          'message' => ''
1775                      );
1776  
1777                      if ( ! empty( $_REQUEST['deleted'] ) ) {
1778                          $notice['message'] .= sprintf(
1779                              _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!',
1780                               absint( $_REQUEST['deleted'] ),
1781                               'signup deleted',
1782                               'buddypress'
1783                              ),
1784                              number_format_i18n( absint( $_REQUEST['deleted'] ) )
1785                          );
1786                      }
1787  
1788                      if ( ! empty( $_REQUEST['notdeleted'] ) ) {
1789                          $notice['message'] .= sprintf(
1790                              _nx( '%s sign-up was not deleted.', '%s sign-ups were not deleted.',
1791                               absint( $_REQUEST['notdeleted'] ),
1792                               'signup notdeleted',
1793                               'buddypress'
1794                              ),
1795                              number_format_i18n( absint( $_REQUEST['notdeleted'] ) )
1796                          );
1797  
1798                          if ( empty( $_REQUEST['deleted'] ) ) {
1799                              $notice['class'] = 'error';
1800                          }
1801                      }
1802  
1803                      break;
1804              }
1805          }
1806  
1807          // Errors.
1808          if ( ! empty( $_REQUEST['error'] ) ) {
1809              switch ( $_REQUEST['error'] ) {
1810                  case 'do_resend':
1811                      $notice = array(
1812                          'class'   => 'error',
1813                          'message' => esc_html__( 'There was a problem sending the activation emails. Please try again.', 'buddypress' ),
1814                      );
1815                      break;
1816  
1817                  case 'do_activate':
1818                      $notice = array(
1819                          'class'   => 'error',
1820                          'message' => esc_html__( 'There was a problem activating accounts. Please try again.', 'buddypress' ),
1821                      );
1822                      break;
1823  
1824                  case 'do_delete':
1825                      $notice = array(
1826                          'class'   => 'error',
1827                          'message' => esc_html__( 'There was a problem deleting sign-ups. Please try again.', 'buddypress' ),
1828                      );
1829                      break;
1830              }
1831          }
1832  
1833          return $notice;
1834      }
1835  
1836      /**
1837       * Signups admin page router.
1838       *
1839       * Depending on the context, display
1840       * - the list of signups,
1841       * - or the delete confirmation screen,
1842       * - or the activate confirmation screen,
1843       * - or the "resend" email confirmation screen.
1844       *
1845       * Also prepare the admin notices.
1846       *
1847       * @since 2.0.0
1848       */
1849  	public function signups_admin() {
1850          $doaction = bp_admin_list_table_current_bulk_action();
1851  
1852          // Prepare notices for admin.
1853          $notice = $this->get_signup_notice();
1854  
1855          // Display notices.
1856          if ( ! empty( $notice ) ) :
1857              if ( 'updated' === $notice['class'] ) : ?>
1858  
1859                  <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>">
1860  
1861              <?php else: ?>
1862  
1863                  <div class="<?php echo esc_attr( $notice['class'] ); ?>">
1864  
1865              <?php endif; ?>
1866  
1867                  <p><?php echo $notice['message']; ?></p>
1868  
1869                  <?php if ( ! empty( $_REQUEST['notactivated'] ) || ! empty( $_REQUEST['notdeleted'] ) || ! empty( $_REQUEST['notsent'] ) ) :?>
1870  
1871                      <ul><?php $this->signups_display_errors();?></ul>
1872  
1873                  <?php endif ;?>
1874  
1875              </div>
1876  
1877          <?php endif;
1878  
1879          // Show the proper screen.
1880          switch ( $doaction ) {
1881              case 'activate' :
1882              case 'delete' :
1883              case 'resend' :
1884                  $this->signups_admin_manage( $doaction );
1885                  break;
1886  
1887              default:
1888                  $this->signups_admin_index();
1889                  break;
1890  
1891          }
1892      }
1893  
1894      /**
1895       * This is the list of the Pending accounts (signups).
1896       *
1897       * @since 2.0.0
1898       *
1899       * @global $plugin_page
1900       * @global $bp_members_signup_list_table
1901       */
1902  	public function signups_admin_index() {
1903          global $plugin_page, $bp_members_signup_list_table;
1904  
1905          $usersearch = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
1906  
1907          // Prepare the group items for display.
1908          $bp_members_signup_list_table->prepare_items();
1909  
1910          if ( is_network_admin() ) {
1911              $form_url = network_admin_url( 'users.php' );
1912          } else {
1913              $form_url = bp_get_admin_url( 'users.php' );
1914          }
1915  
1916          $form_url = add_query_arg(
1917              array(
1918                  'page' => 'bp-signups',
1919              ),
1920              $form_url
1921          );
1922  
1923          $search_form_url = remove_query_arg(
1924              array(
1925                  'action',
1926                  'deleted',
1927                  'notdeleted',
1928                  'error',
1929                  'updated',
1930                  'delete',
1931                  'activate',
1932                  'activated',
1933                  'notactivated',
1934                  'resend',
1935                  'resent',
1936                  'notresent',
1937                  'do_delete',
1938                  'do_activate',
1939                  'do_resend',
1940                  'action2',
1941                  '_wpnonce',
1942                  'signup_ids'
1943              ), $_SERVER['REQUEST_URI']
1944          );
1945  
1946          ?>
1947  
1948          <div class="wrap">
1949              <?php if ( version_compare( $GLOBALS['wp_version'], '4.8', '>=' ) ) : ?>
1950  
1951                  <h1 class="wp-heading-inline"><?php _e( 'Users', 'buddypress' ); ?></h1>
1952  
1953                  <?php if ( current_user_can( 'create_users' ) ) : ?>
1954  
1955                      <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
1956  
1957                  <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
1958  
1959                      <a href="user-new.php" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
1960  
1961                  <?php endif;
1962  
1963                  if ( $usersearch ) {
1964                      printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;', 'buddypress' ) . '</span>', esc_html( $usersearch ) );
1965                  }
1966                  ?>
1967  
1968                  <hr class="wp-header-end">
1969  
1970              <?php else : ?>
1971  
1972                  <h1><?php _e( 'Users', 'buddypress' ); ?>
1973  
1974                      <?php if ( current_user_can( 'create_users' ) ) : ?>
1975  
1976                          <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
1977  
1978                      <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
1979  
1980                          <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
1981  
1982                      <?php endif;
1983  
1984                      if ( $usersearch ) {
1985                          printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;', 'buddypress' ) . '</span>', esc_html( $usersearch ) );
1986                      }
1987  
1988                      ?>
1989                  </h1>
1990  
1991              <?php endif; ?>
1992  
1993              <?php // Display each signups on its own row. ?>
1994              <?php $bp_members_signup_list_table->views(); ?>
1995  
1996              <form id="bp-signups-search-form" action="<?php echo esc_url( $search_form_url ) ;?>">
1997                  <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
1998                  <?php $bp_members_signup_list_table->search_box( __( 'Search Pending Users', 'buddypress' ), 'bp-signups' ); ?>
1999              </form>
2000  
2001              <form id="bp-signups-form" action="<?php echo esc_url( $form_url );?>" method="post">
2002                  <?php $bp_members_signup_list_table->display(); ?>
2003              </form>
2004          </div>
2005      <?php
2006      }
2007  
2008      /**
2009       * This is the confirmation screen for actions.
2010       *
2011       * @since 2.0.0
2012       *
2013       * @param string $action Delete, activate, or resend activation link.
2014       *
2015       * @return null|false
2016       */
2017  	public function signups_admin_manage( $action = '' ) {
2018          if ( ! current_user_can( $this->capability ) || empty( $action ) ) {
2019              die( '-1' );
2020          }
2021  
2022          // Get the user IDs from the URL.
2023          $ids = false;
2024          if ( ! empty( $_POST['allsignups'] ) ) {
2025              $ids = wp_parse_id_list( $_POST['allsignups'] );
2026          } elseif ( ! empty( $_GET['signup_id'] ) ) {
2027              $ids = absint( $_GET['signup_id'] );
2028          }
2029  
2030          if ( empty( $ids ) ) {
2031              return false;
2032          }
2033  
2034          // Query for signups, and filter out those IDs that don't
2035          // correspond to an actual signup.
2036          $signups_query = BP_Signup::get( array(
2037              'include' => $ids,
2038          ) );
2039  
2040          $signups    = $signups_query['signups'];
2041          $signup_ids = wp_list_pluck( $signups, 'signup_id' );
2042  
2043          // Set up strings.
2044          switch ( $action ) {
2045              case 'delete' :
2046                  $header_text = __( 'Delete Pending Accounts', 'buddypress' );
2047                  if ( 1 == count( $signup_ids ) ) {
2048                      $helper_text = __( 'You are about to delete the following account:', 'buddypress' );
2049                  } else {
2050                      $helper_text = __( 'You are about to delete the following accounts:', 'buddypress' );
2051                  }
2052                  break;
2053  
2054              case 'activate' :
2055                  $header_text = __( 'Activate Pending Accounts', 'buddypress' );
2056                  if ( 1 == count( $signup_ids ) ) {
2057                      $helper_text = __( 'You are about to activate the following account:', 'buddypress' );
2058                  } else {
2059                      $helper_text = __( 'You are about to activate the following accounts:', 'buddypress' );
2060                  }
2061                  break;
2062  
2063              case 'resend' :
2064                  $header_text = __( 'Resend Activation Emails', 'buddypress' );
2065                  if ( 1 == count( $signup_ids ) ) {
2066                      $helper_text = __( 'You are about to resend an activation email to the following account:', 'buddypress' );
2067                  } else {
2068                      $helper_text = __( 'You are about to resend an activation email to the following accounts:', 'buddypress' );
2069                  }
2070                  break;
2071          }
2072  
2073          // These arguments are added to all URLs.
2074          $url_args = array( 'page' => 'bp-signups' );
2075  
2076          // These arguments are only added when performing an action.
2077          $action_args = array(
2078              'action'     => 'do_' . $action,
2079              'signup_ids' => implode( ',', $signup_ids )
2080          );
2081  
2082          if ( is_network_admin() ) {
2083              $base_url = network_admin_url( 'users.php' );
2084          } else {
2085              $base_url = bp_get_admin_url( 'users.php' );
2086          }
2087  
2088          $cancel_url = add_query_arg( $url_args, $base_url );
2089          $action_url = wp_nonce_url(
2090              add_query_arg(
2091                  array_merge( $url_args, $action_args ),
2092                  $base_url
2093              ),
2094              'signups_' . $action
2095          );
2096  
2097          // Prefetch registration field data.
2098          $fdata = array();
2099          if ( 'activate' === $action && bp_is_active( 'xprofile' ) ) {
2100              $field_groups = bp_xprofile_get_groups( array(
2101                  'exclude_fields'    => 1,
2102                  'update_meta_cache' => false,
2103                  'fetch_fields'      => true,
2104              ) );
2105  
2106              foreach( $field_groups as $fg ) {
2107                  foreach( $fg->fields as $f ) {
2108                      $fdata[ $f->id ] = $f->name;
2109                  }
2110              }
2111          }
2112  
2113          ?>
2114  
2115          <div class="wrap">
2116              <h1><?php echo esc_html( $header_text ); ?></h1>
2117              <p><?php echo esc_html( $helper_text ); ?></p>
2118  
2119              <ol class="bp-signups-list">
2120              <?php foreach ( $signups as $signup ) :
2121                  $last_notified = mysql2date( 'Y/m/d g:i:s a', $signup->date_sent );
2122                  $profile_field_ids = array();
2123  
2124                  // Get all xprofile field IDs except field 1.
2125                  if ( ! empty( $signup->meta['profile_field_ids'] ) ) {
2126                      $profile_field_ids = array_flip( explode( ',', $signup->meta['profile_field_ids'] ) );
2127                      unset( $profile_field_ids[1] );
2128                  } ?>
2129  
2130                  <li>
2131                      <strong><?php echo esc_html( $signup->user_login ) ?></strong>
2132  
2133                      <?php if ( 'activate' == $action ) : ?>
2134                          <table class="wp-list-table widefat fixed striped">
2135                              <tbody>
2136                                  <tr>
2137                                      <td class="column-fields"><?php esc_html_e( 'Display Name', 'buddypress' ); ?></td>
2138                                      <td><?php echo esc_html( $signup->user_name ); ?></td>
2139                                  </tr>
2140  
2141                                  <tr>
2142                                      <td class="column-fields"><?php esc_html_e( 'Email', 'buddypress' ); ?></td>
2143                                      <td><?php echo sanitize_email( $signup->user_email ); ?></td>
2144                                  </tr>
2145  
2146                                  <?php if ( bp_is_active( 'xprofile' ) && ! empty( $profile_field_ids ) ) : ?>
2147                                      <?php foreach ( $profile_field_ids as $pid => $noop ) :
2148                                          $field_value = isset( $signup->meta[ "field_{$pid}" ] ) ? $signup->meta[ "field_{$pid}" ] : ''; ?>
2149                                          <tr>
2150                                              <td class="column-fields"><?php echo esc_html( $fdata[ $pid ] ); ?></td>
2151                                              <td><?php echo $this->format_xprofile_field_for_display( $field_value ); ?></td>
2152                                          </tr>
2153  
2154                                      <?php endforeach;  ?>
2155  
2156                                  <?php endif; ?>
2157  
2158                                  <?php
2159                                  /**
2160                                   * Fires inside the table listing the activate action confirmation details.
2161                                   *
2162                                   * @since 6.0.0
2163                                   *
2164                                   * @param object $signup The Sign-up Object.
2165                                   */
2166                                  do_action( 'bp_activate_signup_confirmation_details', $signup );
2167                                  ?>
2168  
2169                              </tbody>
2170                          </table>
2171  
2172                          <?php
2173                          /**
2174                           * Fires outside the table listing the activate action confirmation details.
2175                           *
2176                           * @since 6.0.0
2177                           *
2178                           * @param object $signup The Sign-up Object.
2179                           */
2180                          do_action( 'bp_activate_signup_confirmation_after_details', $signup );
2181                          ?>
2182  
2183                      <?php endif; ?>
2184  
2185                      <?php if ( 'resend' == $action ) : ?>
2186  
2187                          <p class="description">
2188                              <?php printf( esc_html__( 'Last notified: %s', 'buddypress'), $last_notified ) ;?>
2189  
2190                              <?php if ( ! empty( $signup->recently_sent ) ) : ?>
2191  
2192                                  <span class="attention wp-ui-text-notification"> <?php esc_html_e( '(less than 24 hours ago)', 'buddypress' ); ?></span>
2193  
2194                              <?php endif; ?>
2195                          </p>
2196  
2197                      <?php endif; ?>
2198  
2199                  </li>
2200  
2201              <?php endforeach; ?>
2202              </ol>
2203  
2204              <?php if ( 'delete' === $action ) : ?>
2205  
2206                  <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
2207  
2208              <?php endif ; ?>
2209  
2210              <a class="button-primary" href="<?php echo esc_url( $action_url ); ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a>
2211              <a class="button" href="<?php echo esc_url( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
2212          </div>
2213  
2214          <?php
2215      }
2216  
2217      /** Users List Management ****************************************************/
2218  
2219      /**
2220       * Display a dropdown to bulk change the member type of selected user(s).
2221       *
2222       * @since 2.7.0
2223       *
2224       * @param string $which Where this dropdown is displayed - top or bottom.
2225       */
2226  	public function users_table_output_type_change_select( $which = 'top' ) {
2227  
2228          // Bail if current user cannot promote users.
2229          if ( ! bp_current_user_can( 'promote_users' ) ) {
2230              return;
2231          }
2232  
2233          // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions.
2234          static $displayed = false;
2235          if ( version_compare( bp_get_major_wp_version(), '4.6', '<' ) && $displayed ) {
2236              return;
2237          }
2238          $displayed = true;
2239  
2240          $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type';
2241  
2242          $types = bp_get_member_types( array(), 'objects' ); ?>
2243  
2244          <label class="screen-reader-text" for="<?php echo $id_name; ?>"><?php _e( 'Change member type to&hellip;', 'buddypress' ) ?></label>
2245          <select name="<?php echo $id_name; ?>" id="<?php echo $id_name; ?>" style="display:inline-block;float:none;">
2246              <option value=""><?php _e( 'Change member type to&hellip;', 'buddypress' ) ?></option>
2247  
2248              <?php foreach( $types as $type ) : ?>
2249  
2250                  <option value="<?php echo esc_attr( $type->name ); ?>"><?php echo esc_html( $type->labels['singular_name'] ); ?></option>
2251  
2252              <?php endforeach; ?>
2253  
2254              <option value="remove_member_type"><?php _e( 'No Member Type', 'buddypress' ) ?></option>
2255  
2256          </select>
2257          <?php
2258          wp_nonce_field( 'bp-bulk-users-change-type-' . bp_loggedin_user_id(), 'bp-bulk-users-change-type-nonce' );
2259          submit_button( __( 'Change', 'buddypress' ), 'button', 'bp_change_member_type', false );
2260      }
2261  
2262      /**
2263       * Process bulk member type change submission from the WP admin users list table.
2264       *
2265       * @since 2.7.0
2266       */
2267  	public function users_table_process_bulk_type_change() {
2268          // Output the admin notice.
2269          $this->users_type_change_notice();
2270  
2271          // Bail if no users are specified or if this isn't a BuddyPress action.
2272          if ( empty( $_REQUEST['users'] )
2273              || ( empty( $_REQUEST['bp_change_type'] ) && empty( $_REQUEST['bp_change_type2'] ) )
2274              || empty( $_REQUEST['bp_change_member_type'] )
2275          ) {
2276              return;
2277          }
2278  
2279          // Bail if nonce check fails.
2280          check_admin_referer( 'bp-bulk-users-change-type-' . bp_loggedin_user_id(), 'bp-bulk-users-change-type-nonce' );
2281  
2282          // Bail if current user cannot promote users.
2283          if ( ! bp_current_user_can( 'promote_users' ) ) {
2284              return;
2285          }
2286  
2287          $new_type = '';
2288          if ( ! empty( $_REQUEST['bp_change_type2'] ) ) {
2289              $new_type = sanitize_text_field( $_REQUEST['bp_change_type2'] );
2290          } elseif ( ! empty( $_REQUEST['bp_change_type'] ) ) {
2291              $new_type = sanitize_text_field( $_REQUEST['bp_change_type'] );
2292          }
2293  
2294          // Check that the selected type actually exists.
2295          if ( 'remove_member_type' != $new_type && null === bp_get_member_type_object( $new_type ) ) {
2296              $error = true;
2297          } else {
2298              // Run through user ids.
2299              $error = false;
2300              foreach ( (array) $_REQUEST['users'] as $user_id ) {
2301                  $user_id = (int) $user_id;
2302  
2303                  // Get the old member type to check against.
2304                  $member_type = bp_get_member_type( $user_id );
2305  
2306                  if ( 'remove_member_type' === $new_type ) {
2307                      // Remove the current member type, if there's one to remove.
2308                      if ( $member_type ) {
2309                          $removed = bp_remove_member_type( $user_id, $member_type );
2310                          if ( false === $removed || is_wp_error( $removed ) ) {
2311                              $error = true;
2312                          }
2313                      }
2314                  } else {
2315                      // Set the new member type.
2316                      if ( $new_type !== $member_type ) {
2317                          $set = bp_set_member_type( $user_id, $new_type );
2318                          if ( false === $set || is_wp_error( $set ) ) {
2319                              $error = true;
2320                          }
2321                      }
2322                  }
2323              }
2324          }
2325  
2326          // If there were any errors, show the error message.
2327          if ( $error ) {
2328              $redirect = add_query_arg( array( 'updated' => 'member-type-change-error' ), wp_get_referer() );
2329          } else {
2330              $redirect = add_query_arg( array( 'updated' => 'member-type-change-success' ), wp_get_referer() );
2331          }
2332  
2333          wp_redirect( $redirect );
2334          exit();
2335      }
2336  
2337      /**
2338       * Display an admin notice upon member type bulk update.
2339       *
2340       * @since 2.7.0
2341       */
2342  	public function users_type_change_notice() {
2343          $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false;
2344  
2345          // Display feedback.
2346          if ( $updated && in_array( $updated, array( 'member-type-change-error', 'member-type-change-success' ), true ) ) {
2347  
2348              if ( 'member-type-change-error' === $updated ) {
2349                  $notice = __( 'There was an error while changing member type. Please try again.', 'buddypress' );
2350                  $type   = 'error';
2351              } else {
2352                  $notice = __( 'Member type was changed successfully.', 'buddypress' );
2353                  $type   = 'updated';
2354              }
2355  
2356              bp_core_add_admin_notice( $notice, $type );
2357          }
2358      }
2359  
2360      /**
2361       * Add member type column to the WordPress admin users list table.
2362       *
2363       * @since 2.7.0
2364       *
2365       * @param array $columns Users table columns.
2366       *
2367       * @return array $columns
2368       */
2369  	public function users_table_add_type_column( $columns = array() ) {
2370          $columns[ bp_get_member_type_tax_name() ] = _x( 'Member Type', 'Label for the WP users table member type column', 'buddypress' );
2371  
2372          return $columns;
2373      }
2374  
2375      /**
2376       * Return member's type for display in the WP admin users list table.
2377       *
2378       * @since 2.7.0
2379       *
2380       * @param string $retval
2381       * @param string $column_name
2382       * @param int $user_id
2383       *
2384       * @return string Member type as a link to filter all users.
2385       */
2386  	public function users_table_populate_type_cell( $retval = '', $column_name = '', $user_id = 0 ) {
2387          // Only looking for member type column.
2388          if ( bp_get_member_type_tax_name() !== $column_name ) {
2389              return $retval;
2390          }
2391  
2392          // Get the member type.
2393          $type = bp_get_member_type( $user_id );
2394  
2395          // Output the
2396          if ( $type_obj = bp_get_member_type_object( $type ) ) {
2397              $url = add_query_arg( array( 'bp-member-type' => urlencode( $type ) ) );
2398              $retval = '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj->labels['singular_name'] ) . '</a>';
2399          }
2400  
2401          return $retval;
2402      }
2403  
2404      /**
2405       * Filter WP Admin users list table to include users of the specified type.
2406       *
2407       * @param WP_Query $query
2408       *
2409       * @since 2.7.0
2410       */
2411  	public function users_table_filter_by_type( $query ) {
2412          global $pagenow;
2413  
2414          if ( is_admin() && 'users.php' === $pagenow && ! empty( $_REQUEST['bp-member-type'] ) ) {
2415              $type_slug = sanitize_text_field( $_REQUEST['bp-member-type'] );
2416  
2417              // Check that the type is registered.
2418              if ( null == bp_get_member_type_object( $type_slug ) ) {
2419                  return;
2420              }
2421  
2422              // Get the list of users that are assigned to this member type.
2423              $type = bp_get_term_by( 'slug', $type_slug, bp_get_member_type_tax_name() );
2424  
2425              if ( empty( $type->term_id ) ) {
2426                  return;
2427              }
2428  
2429              $user_ids = bp_get_objects_in_term( $type->term_id, bp_get_member_type_tax_name() );
2430  
2431              if ( $user_ids && ! is_wp_error( $user_ids ) ) {
2432                  $query->set( 'include', (array) $user_ids );
2433              }
2434          }
2435      }
2436  
2437      /**
2438       * Formats a signup's xprofile field data for display.
2439       *
2440       * Operates recursively on arrays, which are then imploded with commas.
2441       *
2442       * @since 2.8.0
2443       *
2444       * @param string|array $value Field value.
2445       * @return string
2446       */
2447  	protected function format_xprofile_field_for_display( $value ) {
2448          if ( is_array( $value ) ) {
2449              $value = array_map( array( $this, 'format_xprofile_field_for_display' ), $value );
2450              $value = implode( ', ', $value );
2451          } else {
2452              $value = stripslashes( $value );
2453              $value = esc_html( $value );
2454          }
2455  
2456          return $value;
2457      }
2458  }
2459  endif; // End class_exists check.


Generated: Mon Nov 18 01:01:37 2019 Cross-referenced by PHPXref 0.7.1