[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Signups Management class.
   4   *
   5   * @package BuddyPress
   6   * @subpackage coreClasses
   7   * @since 2.0.0
   8   */
   9  
  10  /**
  11   * Class used to handle Signups.
  12   *
  13   * @since 2.0.0
  14   */
  15  class BP_Signup {
  16  
  17      /**
  18       * ID of the signup which the object relates to.
  19       *
  20       * @since 2.0.0
  21       * @var integer
  22       */
  23      public $id;
  24  
  25      /**
  26       * The URL to the full size of the avatar for the user.
  27       *
  28       * @since 2.0.0
  29       * @var string
  30       */
  31      public $avatar;
  32  
  33      /**
  34       * The username for the user.
  35       *
  36       * @since 2.0.0
  37       * @var string
  38       */
  39      public $user_login;
  40  
  41      /**
  42       * The email for the user.
  43       *
  44       * @since 2.0.0
  45       * @var string
  46       */
  47      public $user_email;
  48  
  49      /**
  50       * The full name of the user.
  51       *
  52       * @since 2.0.0
  53       * @var string
  54       */
  55      public $user_name;
  56  
  57      /**
  58       * Metadata associated with the signup.
  59       *
  60       * @since 2.0.0
  61       * @var array
  62       */
  63      public $meta;
  64  
  65      /**
  66       * The registered date for the user.
  67       *
  68       * @since 2.0.0
  69       * @var string
  70       */
  71      public $registered;
  72  
  73      /**
  74       * The activation key for the user.
  75       *
  76       * @since 2.0.0
  77       * @var string
  78       */
  79      public $activation_key;
  80  
  81  
  82      /** Public Methods *******************************************************/
  83  
  84      /**
  85       * Class constructor.
  86       *
  87       * @since 2.0.0
  88       *
  89       * @param integer $signup_id The ID for the signup being queried.
  90       */
  91  	public function __construct( $signup_id = 0 ) {
  92          if ( !empty( $signup_id ) ) {
  93              $this->id = $signup_id;
  94              $this->populate();
  95          }
  96      }
  97  
  98      /**
  99       * Populate the instantiated class with data based on the signup_id provided.
 100       *
 101       * @since 2.0.0
 102       */
 103  	public function populate() {
 104          global $wpdb;
 105  
 106          $signups_table = buddypress()->members->table_name_signups;
 107          $signup        = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE signup_id = %d AND active = 0", $this->id ) );
 108  
 109          $this->avatar         = get_avatar( $signup->user_email, 32 );
 110          $this->user_login     = $signup->user_login;
 111          $this->user_email     = $signup->user_email;
 112          $this->meta           = maybe_unserialize( $signup->meta );
 113          $this->user_name      = ! empty( $this->meta['field_1'] ) ? wp_unslash( $this->meta['field_1'] ) : '';
 114          $this->registered     = $signup->registered;
 115          $this->activation_key = $signup->activation_key;
 116      }
 117  
 118      /** Static Methods *******************************************************/
 119  
 120      /**
 121       * Fetch signups based on parameters.
 122       *
 123       * @since 2.0.0
 124       *
 125       * @param array $args {
 126       *     The argument to retrieve desired signups.
 127       *     @type int         $offset         Offset amount. Default 0.
 128       *     @type int         $number         How many to fetch. Default 1.
 129       *     @type bool|string $usersearch     Whether or not to search for a username. Default false.
 130       *     @type string      $orderby        Order By parameter. Default 'signup_id'.
 131       *     @type string      $order          Order direction. Default 'DESC'.
 132       *     @type bool        $include        Whether or not to include more specific query params.
 133       *     @type string      $activation_key Activation key to search for.
 134       *     @type string      $user_login     Specific user login to return.
 135       *     @type string      $fields         Which fields to return. Specify 'ids' to fetch a list of signups IDs.
 136       *                                       Default: 'all' (return BP_Signup objects).
 137       * }
 138       * @return array {
 139       *     @type array $signups Located signups. (IDs only if `fields` is set to `ids`.)
 140       *     @type int   $total   Total number of signups matching params.
 141       * }
 142       */
 143  	public static function get( $args = array() ) {
 144          global $wpdb;
 145  
 146          $r = bp_parse_args( $args,
 147              array(
 148                  'offset'         => 0,
 149                  'number'         => 1,
 150                  'usersearch'     => false,
 151                  'orderby'        => 'signup_id',
 152                  'order'          => 'DESC',
 153                  'include'        => false,
 154                  'activation_key' => '',
 155                  'user_login'     => '',
 156                  'fields'         => 'all',
 157              ),
 158              'bp_core_signups_get_args'
 159          );
 160  
 161          // @todo whitelist sanitization
 162          if ( $r['orderby'] !== 'signup_id' ) {
 163              $r['orderby'] = 'user_' . $r['orderby'];
 164          }
 165  
 166          $r['orderby'] = sanitize_title( $r['orderby'] );
 167  
 168          $sql = array();
 169          $signups_table  = buddypress()->members->table_name_signups;
 170          $sql['select']  = "SELECT * FROM {$signups_table}";
 171          $sql['where']   = array();
 172          $sql['where'][] = "active = 0";
 173  
 174          if ( empty( $r['include'] ) ) {
 175  
 176              // Search terms.
 177              if ( ! empty( $r['usersearch'] ) ) {
 178                  $search_terms_like = '%' . bp_esc_like( $r['usersearch'] ) . '%';
 179                  $sql['where'][]    = $wpdb->prepare( "( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )", $search_terms_like, $search_terms_like, $search_terms_like );
 180              }
 181  
 182              // Activation key.
 183              if ( ! empty( $r['activation_key'] ) ) {
 184                  $sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] );
 185              }
 186  
 187              // User login.
 188              if ( ! empty( $r['user_login'] ) ) {
 189                  $sql['where'][] = $wpdb->prepare( "user_login = %s", $r['user_login'] );
 190              }
 191  
 192              $sql['orderby'] = "ORDER BY {$r['orderby']}";
 193              $sql['order']    = bp_esc_sql_order( $r['order'] );
 194              $sql['limit']    = $wpdb->prepare( "LIMIT %d, %d", $r['offset'], $r['number'] );
 195          } else {
 196              $in = implode( ',', wp_parse_id_list( $r['include'] ) );
 197              $sql['in'] = "AND signup_id IN ({$in})";
 198          }
 199  
 200          // Implode WHERE clauses.
 201          $sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] );
 202  
 203          /**
 204           * Filters the Signups paged query.
 205           *
 206           * @since 2.0.0
 207           *
 208           * @param string $value SQL statement.
 209           * @param array  $sql   Array of SQL statement parts.
 210           * @param array  $args  Array of original arguments for get() method.
 211           * @param array  $r     Array of parsed arguments for get() method.
 212           */
 213          $paged_signups = $wpdb->get_results( apply_filters( 'bp_members_signups_paged_query', join( ' ', $sql ), $sql, $args, $r ) );
 214  
 215          if ( empty( $paged_signups ) ) {
 216              return array( 'signups' => false, 'total' => false );
 217          }
 218  
 219          // We only want the IDs.
 220          if ( 'ids' === $r['fields'] ) {
 221              $paged_signups = wp_list_pluck( $paged_signups, 'signup_id' );
 222          } else {
 223  
 224              // Used to calculate a diff between now & last
 225              // time an activation link has been resent.
 226              $now = current_time( 'timestamp', true );
 227  
 228              foreach ( (array) $paged_signups as $key => $signup ) {
 229  
 230                  $signup->id   = intval( $signup->signup_id );
 231  
 232                  $signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false;
 233  
 234                  $signup->user_name = '';
 235                  if ( ! empty( $signup->meta['field_1'] ) ) {
 236                      $signup->user_name = wp_unslash( $signup->meta['field_1'] );
 237                  }
 238  
 239                  // Sent date defaults to date of registration.
 240                  if ( ! empty( $signup->meta['sent_date'] ) ) {
 241                      $signup->date_sent = $signup->meta['sent_date'];
 242                  } else {
 243                      $signup->date_sent = $signup->registered;
 244                  }
 245  
 246                  $sent_at = mysql2date('U', $signup->date_sent );
 247                  $diff    = $now - $sent_at;
 248  
 249                  /**
 250                   * Add a boolean in case the last time an activation link
 251                   * has been sent happened less than a day ago.
 252                   */
 253                  if ( $diff < 1 * DAY_IN_SECONDS ) {
 254                      $signup->recently_sent = true;
 255                  }
 256  
 257                  if ( ! empty( $signup->meta['count_sent'] ) ) {
 258                      $signup->count_sent = absint( $signup->meta['count_sent'] );
 259                  } else {
 260                      $signup->count_sent = 1;
 261                  }
 262  
 263                  $paged_signups[ $key ] = $signup;
 264              }
 265          }
 266  
 267          unset( $sql['limit'] );
 268          $sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] );
 269  
 270          /**
 271           * Filters the Signups count query.
 272           *
 273           * @since 2.0.0
 274           *
 275           * @param string $value SQL statement.
 276           * @param array  $sql   Array of SQL statement parts.
 277           * @param array  $args  Array of original arguments for get() method.
 278           * @param array  $r     Array of parsed arguments for get() method.
 279           */
 280          $total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) );
 281  
 282          return array( 'signups' => $paged_signups, 'total' => $total_signups );
 283      }
 284  
 285      /**
 286       * Add a signup.
 287       *
 288       * @since 2.0.0
 289       *
 290       * @param array $args {
 291       *     Array of arguments for signup addition.
 292       *     @type string     $domain         New user's domain.
 293       *     @type string     $path           New user's path.
 294       *     @type string     $title          New user's title.
 295       *     @type string     $user_login     New user's user_login.
 296       *     @type string     $user_email     New user's email address.
 297       *     @type int|string $registered     Time the user registered.
 298       *     @type string     $activation_key New user's activation key.
 299       *     @type string     $meta           New user's user meta.
 300       * }
 301       * @return int|bool ID of newly created signup on success, false on failure.
 302       */
 303  	public static function add( $args = array() ) {
 304          global $wpdb;
 305  
 306          $r = bp_parse_args( $args,
 307              array(
 308                  'domain'         => '',
 309                  'path'           => '',
 310                  'title'          => '',
 311                  'user_login'     => '',
 312                  'user_email'     => '',
 313                  'registered'     => current_time( 'mysql', true ),
 314                  'activation_key' => '',
 315                  'meta'           => '',
 316              ),
 317              'bp_core_signups_add_args'
 318          );
 319  
 320          $r['meta'] = maybe_serialize( $r['meta'] );
 321  
 322          $inserted = $wpdb->insert(
 323              buddypress()->members->table_name_signups,
 324              $r,
 325              array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )
 326          );
 327  
 328          if ( $inserted ) {
 329              $retval = $wpdb->insert_id;
 330          } else {
 331              $retval = false;
 332          }
 333  
 334          /**
 335           * Filters the result of a signup addition.
 336           *
 337           * @since 2.0.0
 338           *
 339           * @param int|bool $retval Newly added user ID on success, false on failure.
 340           */
 341          return apply_filters( 'bp_core_signups_add', $retval );
 342      }
 343  
 344      /**
 345       * Create a WP user at signup.
 346       *
 347       * Since BP 2.0, non-multisite configurations have stored signups in
 348       * the same way as Multisite configs traditionally have: in the
 349       * wp_signups table. However, because some plugins may be looking
 350       * directly in the wp_users table for non-activated signups, we
 351       * mirror signups there by creating "phantom" users, mimicking WP's
 352       * default behavior.
 353       *
 354       * @since 2.0.0
 355       *
 356       * @param string $user_login    User login string.
 357       * @param string $user_password User password.
 358       * @param string $user_email    User email address.
 359       * @param array  $usermeta      Metadata associated with the signup.
 360       * @return int User id.
 361       */
 362  	public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) {
 363          global $wpdb;
 364  
 365          $user_id = wp_insert_user( array(
 366              'user_login'   => $user_login,
 367              'user_pass'    => $user_password,
 368              'display_name' => sanitize_title( $user_login ),
 369              'user_email'   => $user_email
 370          ) );
 371  
 372          if ( is_wp_error( $user_id ) || empty( $user_id ) ) {
 373              return $user_id;
 374          }
 375  
 376          // Update the user status to '2', ie "not activated"
 377          // (0 = active, 1 = spam, 2 = not active).
 378          $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) );
 379  
 380          // WordPress creates these options automatically on
 381          // wp_insert_user(), but we delete them so that inactive
 382          // signups don't appear in various user counts.
 383          delete_user_option( $user_id, 'capabilities' );
 384          delete_user_option( $user_id, 'user_level'   );
 385  
 386          // Set any profile data.
 387          if ( bp_is_active( 'xprofile' ) ) {
 388              if ( ! empty( $usermeta['profile_field_ids'] ) ) {
 389                  $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
 390  
 391                  foreach ( (array) $profile_field_ids as $field_id ) {
 392                      if ( empty( $usermeta["field_{$field_id}"] ) ) {
 393                          continue;
 394                      }
 395  
 396                      $current_field = $usermeta["field_{$field_id}"];
 397                      xprofile_set_field_data( $field_id, $user_id, $current_field );
 398  
 399                      /*
 400                       * Save the visibility level.
 401                       *
 402                       * Use the field's default visibility if not present, and 'public' if a
 403                       * default visibility is not defined.
 404                       */
 405                      $key = "field_{$field_id}_visibility";
 406                      if ( isset( $usermeta[ $key ] ) ) {
 407                          $visibility_level = $usermeta[ $key ];
 408                      } else {
 409                          $vfield           = xprofile_get_field( $field_id );
 410                          $visibility_level = isset( $vfield->default_visibility ) ? $vfield->default_visibility : 'public';
 411                      }
 412                      xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
 413                  }
 414              }
 415          }
 416  
 417          /**
 418           * Filters the user ID for the backcompat functionality.
 419           *
 420           * @since 2.0.0
 421           *
 422           * @param int $user_id User ID being registered.
 423           */
 424          return apply_filters( 'bp_core_signups_add_backcompat', $user_id );
 425      }
 426  
 427      /**
 428       * Check a user status (from wp_users) on a non-multisite config.
 429       *
 430       * @since 2.0.0
 431       *
 432       * @param int $user_id ID of the user being checked.
 433       * @return int|bool The status if found, otherwise false.
 434       */
 435  	public static function check_user_status( $user_id = 0 ) {
 436          global $wpdb;
 437  
 438          if ( empty( $user_id ) ) {
 439              return false;
 440          }
 441  
 442          $user_status = $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id ) );
 443  
 444          /**
 445           * Filters the user status of a provided user ID.
 446           *
 447           * @since 2.0.0
 448           *
 449           * @param int $value User status of the provided user ID.
 450           */
 451          return apply_filters( 'bp_core_signups_check_user_status', intval( $user_status ) );
 452      }
 453  
 454      /**
 455       * Activate a signup.
 456       *
 457       * @since 2.0.0
 458       *
 459       * @param string $key Activation key.
 460       * @return bool True on success, false on failure.
 461       */
 462  	public static function validate( $key = '' ) {
 463          global $wpdb;
 464  
 465          if ( empty( $key ) ) {
 466              return;
 467          }
 468  
 469          $activated = $wpdb->update(
 470              // Signups table.
 471              buddypress()->members->table_name_signups,
 472              array(
 473                  'active' => 1,
 474                  'activated' => current_time( 'mysql', true ),
 475              ),
 476              array(
 477                  'activation_key' => $key,
 478              ),
 479              // Data sanitization format.
 480              array(
 481                  '%d',
 482                  '%s',
 483              ),
 484              // WHERE sanitization format.
 485              array(
 486                  '%s',
 487              )
 488          );
 489  
 490          /**
 491           * Filters the status of the activated user.
 492           *
 493           * @since 2.0.0
 494           *
 495           * @param bool $activated Whether or not the activation was successful.
 496           */
 497          return apply_filters( 'bp_core_signups_validate', $activated );
 498      }
 499  
 500      /**
 501       * How many inactive signups do we have?
 502       *
 503       * @since 2.0.0
 504       *
 505       * @return int The number of signups.
 506       */
 507  	public static function count_signups() {
 508          global $wpdb;
 509  
 510          $signups_table = buddypress()->members->table_name_signups;
 511          $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) );
 512  
 513          /**
 514           * Filters the total inactive signups.
 515           *
 516           * @since 2.0.0
 517           *
 518           * @param int $count_signups How many total signups there are.
 519           */
 520          return apply_filters( 'bp_core_signups_count', (int) $count_signups );
 521      }
 522  
 523      /**
 524       * Update the meta for a signup.
 525       *
 526       * This is the way we use to "trace" the last date an activation
 527       * email was sent and how many times activation was sent.
 528       *
 529       * @since 2.0.0
 530       *
 531       * @param array $args {
 532       *     Array of arguments for the signup update.
 533       *     @type int $signup_id User signup ID.
 534       *     @type array $meta Meta to update.
 535       * }
 536       * @return int The signup id.
 537       */
 538  	public static function update( $args = array() ) {
 539          global $wpdb;
 540  
 541          $r = bp_parse_args( $args,
 542              array(
 543                  'signup_id'  => 0,
 544                  'meta'       => array(),
 545              ),
 546              'bp_core_signups_update_args'
 547          );
 548  
 549          if ( empty( $r['signup_id'] ) || empty( $r['meta'] ) ) {
 550              return false;
 551          }
 552  
 553          $wpdb->update(
 554              // Signups table.
 555              buddypress()->members->table_name_signups,
 556              // Data to update.
 557              array(
 558                  'meta' => serialize( $r['meta'] ),
 559              ),
 560              // WHERE.
 561              array(
 562                  'signup_id' => $r['signup_id'],
 563              ),
 564              // Data sanitization format.
 565              array(
 566                  '%s',
 567              ),
 568              // WHERE sanitization format.
 569              array(
 570                  '%d',
 571              )
 572          );
 573  
 574          /**
 575           * Filters the signup ID which received a meta update.
 576           *
 577           * @since 2.0.0
 578           *
 579           * @param int $value The signup ID.
 580           */
 581          return apply_filters( 'bp_core_signups_update', $r['signup_id'] );
 582      }
 583  
 584      /**
 585       * Resend an activation email.
 586       *
 587       * @since 2.0.0
 588       *
 589       * @param array $signup_ids Single ID or list of IDs to resend.
 590       * @return array
 591       */
 592  	public static function resend( $signup_ids = array() ) {
 593          if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) {
 594              return false;
 595          }
 596  
 597          $to_resend = self::get( array(
 598              'include' => $signup_ids,
 599          ) );
 600  
 601          if ( ! $signups = $to_resend['signups'] ) {
 602              return false;
 603          }
 604  
 605          $result = array();
 606  
 607          /**
 608           * Fires before activation emails are resent.
 609           *
 610           * @since 2.0.0
 611           *
 612           * @param array $signup_ids Array of IDs to resend activation emails to.
 613           */
 614          do_action( 'bp_core_signup_before_resend', $signup_ids );
 615  
 616          foreach ( $signups as $signup ) {
 617  
 618              $meta               = $signup->meta;
 619              $meta['sent_date']  = current_time( 'mysql', true );
 620              $meta['count_sent'] = $signup->count_sent + 1;
 621  
 622              // Send activation email.
 623              if ( is_multisite() ) {
 624                  wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) );
 625              } else {
 626  
 627                  // Check user status before sending email.
 628                  $user_id = email_exists( $signup->user_email );
 629  
 630                  if ( ! empty( $user_id ) && 2 != self::check_user_status( $user_id ) ) {
 631  
 632                      // Status is not 2, so user's account has been activated.
 633                      $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );
 634  
 635                      // Repair signups table.
 636                      self::validate( $signup->activation_key );
 637  
 638                      continue;
 639  
 640                  // Send the validation email.
 641                  } else {
 642                      $salutation = $signup->user_login;
 643                      if ( isset( $meta[ 'field_' . bp_xprofile_fullname_field_id() ] ) ) {
 644                          $salutation = $meta[ 'field_' . bp_xprofile_fullname_field_id() ];
 645                      }
 646  
 647                      bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key, $salutation );
 648                  }
 649              }
 650  
 651              // Update metas.
 652              $result['resent'][] = self::update( array(
 653                  'signup_id' => $signup->signup_id,
 654                  'meta'      => $meta,
 655              ) );
 656          }
 657  
 658          /**
 659           * Fires after activation emails are resent.
 660           *
 661           * @since 2.0.0
 662           *
 663           * @param array $signup_ids Array of IDs to resend activation emails to.
 664           * @param array $result     Updated metadata related to activation emails.
 665           */
 666          do_action( 'bp_core_signup_after_resend', $signup_ids, $result );
 667  
 668          /**
 669           * Filters the result of the metadata for signup activation email resends.
 670           *
 671           * @since 2.0.0
 672           *
 673           * @param array $result Updated metadata related to activation emails.
 674           */
 675          return apply_filters( 'bp_core_signup_resend', $result );
 676      }
 677  
 678      /**
 679       * Activate a pending account.
 680       *
 681       * @since 2.0.0
 682       *
 683       * @param array $signup_ids Single ID or list of IDs to activate.
 684       * @return array
 685       */
 686  	public static function activate( $signup_ids = array() ) {
 687          if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) {
 688              return false;
 689          }
 690  
 691          $to_activate = self::get( array(
 692              'include' => $signup_ids,
 693          ) );
 694  
 695          if ( ! $signups = $to_activate['signups'] ) {
 696              return false;
 697          }
 698  
 699          $result = array();
 700  
 701          /**
 702           * Fires before activation of user accounts.
 703           *
 704           * @since 2.0.0
 705           *
 706           * @param array $signup_ids Array of IDs to activate.
 707           */
 708          do_action( 'bp_core_signup_before_activate', $signup_ids );
 709  
 710          foreach ( $signups as $signup ) {
 711  
 712              $user = bp_core_activate_signup( $signup->activation_key );
 713  
 714              if ( ! empty( $user->errors ) ) {
 715  
 716                  $user_id = username_exists( $signup->user_login );
 717  
 718                  if ( 2 !== self::check_user_status( $user_id ) ) {
 719                      $user_id = false;
 720                  }
 721  
 722                  if ( empty( $user_id ) ) {
 723  
 724                      // Status is not 2, so user's account has been activated.
 725                      $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );
 726  
 727                      // Repair signups table.
 728                      self::validate( $signup->activation_key );
 729  
 730                  // We have a user id, account is not active, let's delete it.
 731                  } else {
 732                      $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() );
 733                  }
 734  
 735              } else {
 736                  $result['activated'][] = $user;
 737              }
 738          }
 739  
 740          /**
 741           * Fires after activation of user accounts.
 742           *
 743           * @since 2.0.0
 744           *
 745           * @param array $signup_ids Array of IDs activated activate.
 746           * @param array $result     Array of data for activated accounts.
 747           */
 748          do_action( 'bp_core_signup_after_activate', $signup_ids, $result );
 749  
 750          /**
 751           * Filters the result of the metadata after user activation.
 752           *
 753           * @since 2.0.0
 754           *
 755           * @param array $result Updated metadata related to user activation.
 756           */
 757          return apply_filters( 'bp_core_signup_activate', $result );
 758      }
 759  
 760      /**
 761       * Delete a pending account.
 762       *
 763       * @since 2.0.0
 764       *
 765       * @param array $signup_ids Single ID or list of IDs to delete.
 766       * @return array
 767       */
 768  	public static function delete( $signup_ids = array() ) {
 769          global $wpdb;
 770  
 771          if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) {
 772              return false;
 773          }
 774  
 775          $to_delete = self::get( array(
 776              'include' => $signup_ids,
 777          ) );
 778  
 779          if ( ! $signups = $to_delete['signups'] ) {
 780              return false;
 781          }
 782  
 783          $result = array();
 784  
 785          /**
 786           * Fires before deletion of pending accounts.
 787           *
 788           * @since 2.0.0
 789           *
 790           * @param array $signup_ids Array of pending IDs to delete.
 791           */
 792          do_action( 'bp_core_signup_before_delete', $signup_ids );
 793  
 794          foreach ( $signups as $signup ) {
 795              $user_id = username_exists( $signup->user_login );
 796  
 797              if ( ! empty( $user_id ) && $signup->activation_key === bp_get_user_meta( $user_id, 'activation_key', true ) ) {
 798  
 799                  if ( 2 != self::check_user_status( $user_id ) ) {
 800  
 801                      // Status is not 2, so user's account has been activated.
 802                      $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );
 803  
 804                      // Repair signups table.
 805                      self::validate( $signup->activation_key );
 806  
 807                  // We have a user id, account is not active, let's delete it.
 808                  } else {
 809                      bp_core_delete_account( $user_id );
 810                  }
 811              }
 812  
 813              if ( empty( $result['errors'][ $signup->signup_id ] ) ) {
 814                  $wpdb->delete(
 815                      // Signups table.
 816                      buddypress()->members->table_name_signups,
 817                      // Where.
 818                      array( 'signup_id' => $signup->signup_id, ),
 819                      // WHERE sanitization format.
 820                      array( '%d', )
 821                  );
 822  
 823                  $result['deleted'][] = $signup->signup_id;
 824              }
 825          }
 826  
 827          /**
 828           * Fires after deletion of pending accounts.
 829           *
 830           * @since 2.0.0
 831           *
 832           * @param array $signup_ids Array of pending IDs to delete.
 833           * @param array $result     Array of data for deleted accounts.
 834           */
 835          do_action( 'bp_core_signup_after_delete', $signup_ids, $result );
 836  
 837          /**
 838           * Filters the result of the metadata for deleted pending accounts.
 839           *
 840           * @since 2.0.0
 841           *
 842           * @param array $result Updated metadata related to deleted pending accounts.
 843           */
 844          return apply_filters( 'bp_core_signup_delete', $result );
 845      }
 846  }


Generated: Tue Jul 16 01:01:43 2019 Cross-referenced by PHPXref 0.7.1