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