BP_Signup

Class used to handle Signups.

Defined (1)

The class is defined in the following location(s).

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