/bp-members/classes/class-bp-signup.php

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