Ticket #5374: 5374.07.patch
File 5374.07.patch, 84.7 KB (added by , 11 years ago) |
---|
-
bp-core/admin/bp-core-functions.php
diff --git bp-core/admin/bp-core-functions.php bp-core/admin/bp-core-functions.php index e47e7da..f2f214a 100644
function bp_core_activation_notice() { 271 271 'id' => 'register', 272 272 'name' => __( 'Register', 'buddypress' ) 273 273 ); 274 275 bp_core_maybe_install_signups(); 274 276 } 275 277 276 278 // On the first admin screen after a new installation, this isn't set, so grab it to supress a misleading error message. … … function bp_admin_wp_nav_menu_restrict_items() { 785 787 </script> 786 788 <?php 787 789 } 790 791 /** 792 * Check if the signups table needs to be created. 793 * 794 * @since BuddyPress (2.0.0) 795 * 796 * @global $wpdb 797 */ 798 function bp_core_maybe_install_signups() { 799 global $wpdb; 800 801 // Multisite installations already have the signups table. 802 if ( ! empty( $wpdb->signups ) ) { 803 return; 804 } 805 806 $bp_signups = bp_core_get_table_prefix() . 'signups'; 807 808 // Check for the table 809 $suppress = $wpdb->suppress_errors(); 810 $table_exists = $wpdb->get_results( "DESCRIBE {$bp_signups};" ); 811 $wpdb->suppress_errors( $suppress ); 812 813 // Bail if the table exists 814 if ( ! empty( $table_exists ) ) { 815 return; 816 } 817 818 // Signups is not there and we need it so let's create it 819 require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' ); 820 821 bp_core_install_signups(); 822 } -
bp-core/admin/bp-core-schema.php
diff --git bp-core/admin/bp-core-schema.php bp-core/admin/bp-core-schema.php index a082d87..53a4ceb 100644
function bp_core_install( $active_components = false ) { 50 50 // Blog tracking 51 51 if ( !empty( $active_components['blogs'] ) ) 52 52 bp_core_install_blog_tracking(); 53 54 // Install the signups table 55 if ( bp_get_signup_allowed() ) 56 bp_core_install_signups(); 57 53 58 } 54 59 55 60 function bp_core_install_notifications() { … … function bp_core_install_blog_tracking() { 343 348 344 349 dbDelta( $sql ); 345 350 } 351 352 /** 353 * Install the signups table. 354 * 355 * @since BuddyPress (2.0.0) 356 * 357 * @global $wpdb 358 * @uses wp_get_db_schema() to get WordPress ms_global schema 359 */ 360 function bp_core_install_signups() { 361 global $wpdb; 362 363 // Multisite installations already have the signups table 364 if ( ! empty( $wpdb->signups ) ) { 365 return; 366 } 367 368 $wpdb->signups = bp_core_get_table_prefix() . 'signups'; 369 370 // Setting the charset to be sure WordPress upgrade.php is loaded 371 $charset_collate = bp_core_set_charset(); 372 373 // Use WP's core CREATE TABLE query 374 $create_queries = wp_get_db_schema( 'ms_global' ); 375 376 if ( ! is_array( $create_queries ) ) { 377 $create_queries = explode( ';', $create_queries ); 378 $create_queries = array_filter( $create_queries ); 379 } 380 381 // Filter out all the queries except wp_signups 382 foreach ( $create_queries as $key => $query ) { 383 if ( preg_match( "|CREATE TABLE ([^ ]*)|", $query, $matches ) ) { 384 if ( $wpdb->signups != trim( $matches[1], '`' ) ) { 385 unset( $create_queries[ $key ] ); 386 } 387 } 388 } 389 390 if ( ! empty( $create_queries ) ) { 391 dbDelta( $create_queries ); 392 } 393 } -
bp-core/bp-core-update.php
diff --git bp-core/bp-core-update.php bp-core/bp-core-update.php index 0b6af15..011d483 100644
function bp_update_to_2_0() { 365 365 366 366 $wpdb->query( $sql ); 367 367 368 /** Migrate signups data *********************************************/ 369 370 if ( bp_get_signup_allowed() && ! is_multisite() ) { 371 372 if ( empty( $wpdb->signups ) ) { 373 bp_core_install_signups(); 374 } 375 376 $signups = get_users( array( 377 'fields' => 'all_with_meta', 378 'meta_key' => 'activation_key', 379 'meta_compare' => 'EXISTS', 380 ) ); 381 382 if ( empty( $signups ) ) { 383 return; 384 } 385 386 foreach ( $signups as $signup ) { 387 $meta = array(); 388 389 if ( bp_is_active( 'xprofile' ) ) { 390 $meta['field_1'] = $signup->display_name; 391 } 392 393 $meta['password'] = $signup->user_pass; 394 395 $user_login = preg_replace( '/\s+/', '', sanitize_user( $signup->user_login, true ) ); 396 $user_email = sanitize_email( $signup->user_email ); 397 398 $args = array( 399 'user_login' => $user_login, 400 'user_email' => $user_email, 401 'registered' => $signup->user_registered, 402 'activation_key' => $signup->activation_key, 403 'meta' => $meta 404 ); 405 406 BP_Signup::add( $args ); 407 408 // Deleting these options will remove signups from users count 409 delete_user_option( $signup->ID, 'capabilities' ); 410 delete_user_option( $signup->ID, 'user_level' ); 411 } 412 } 413 368 414 /** Add BP options to the options table ******************************/ 369 415 bp_add_options(); 370 416 } -
bp-members/admin/bp-members-classes.php
diff --git bp-members/admin/bp-members-classes.php bp-members/admin/bp-members-classes.php index e69de29..b66c9f4 100644
1 <?php 2 3 /** 4 * BuddyPress Members List Classes 5 * 6 * @package BuddyPress 7 * @subpackage MembersAdminClasses 8 */ 9 10 // Exit if accessed directly 11 if ( !defined( 'ABSPATH' ) ) exit; 12 13 if ( class_exists( 'WP_Users_List_Table') ) : 14 15 /** 16 * List table class for signups admin page. 17 * 18 * @since BuddyPress (2.0.0) 19 */ 20 class BP_Members_List_Table extends WP_Users_List_Table { 21 22 /** 23 * Signup counts. 24 * 25 * @since BuddyPress (2.0.0) 26 * 27 * @access public 28 * @var int 29 */ 30 public $signup_counts = 0; 31 32 /** 33 * Constructor. 34 * 35 * @since BuddyPress (2.0.0) 36 */ 37 public function __construct() { 38 // Define singular and plural labels, as well as whether we support AJAX. 39 parent::__construct( array( 40 'ajax' => false, 41 'plural' => 'signups', 42 'singular' => 'signup', 43 ) ); 44 } 45 46 /** 47 * Set up items for display in the list table. 48 * 49 * Handles filtering of data, sorting, pagination, and any other data 50 * manipulation required prior to rendering. 51 * 52 * @since BuddyPress (2.0.0) 53 */ 54 public function prepare_items() { 55 global $usersearch; 56 57 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 58 59 $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 60 61 $paged = $this->get_pagenum(); 62 63 $args = array( 64 'offset' => ( $paged - 1 ) * $signups_per_page, 65 'number' => $signups_per_page, 66 'usersearch' => $usersearch, 67 'orderby' => 'signup_id', 68 'order' => 'DESC' 69 ); 70 71 if ( isset( $_REQUEST['orderby'] ) ) { 72 $args['orderby'] = $_REQUEST['orderby']; 73 } 74 75 if ( isset( $_REQUEST['order'] ) ) { 76 $args['order'] = $_REQUEST['order']; 77 } 78 79 $signups = BP_Signup::get( $args ); 80 81 $this->items = $signups['signups']; 82 $this->signup_counts = $signups['total']; 83 84 $this->set_pagination_args( array( 85 'total_items' => $this->signup_counts, 86 'per_page' => $signups_per_page, 87 ) ); 88 } 89 90 /** 91 * Get the views (the links above the WP List Table). 92 * 93 * @since BuddyPress (2.0.0) 94 * 95 * @uses WP_Users_List_Table::get_views() to get the users views 96 */ 97 public function get_views() { 98 $views = parent::get_views(); 99 100 // Remove the 'current' class from the 'All' link 101 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 102 $views['registered'] = '<a href="' . add_query_arg( 'page', 'bp-signups', bp_get_admin_url( 'users.php' ) ) . '" class="current">' . sprintf( _nx( 'Pending account <span class="count">(%s)</span>', 'Pending accounts <span class="count">(%s)</span>', $this->signup_counts, 'signup users', 'buddypress' ), number_format_i18n( $this->signup_counts ) ) . '</a>'; 103 104 return $views; 105 } 106 107 /** 108 * Get rid of the extra nav. 109 * 110 * WP_Users_List_Table will add an extra nav to change user's role. 111 * As we're dealing with signups, we don't need this. 112 * 113 * @since BuddyPress (2.0.0) 114 */ 115 public function extra_tablenav( $which ) { 116 return; 117 } 118 119 /** 120 * Specific signups columns 121 * 122 * @since BuddyPress (2.0.0) 123 */ 124 public function get_columns() { 125 return apply_filters( 'bp_members_signup_columns', array( 126 'cb' => '<input type="checkbox" />', 127 'username' => __( 'Username', 'buddypress' ), 128 'name' => __( 'Name', 'buddypress' ), 129 'email' => __( 'E-mail', 'buddypress' ), 130 'registered' => __( 'Registered', 'buddypress' ), 131 'date_sent' => __( 'Last mail', 'buddypress' ), 132 'count_sent' => __( '# Times Resent', 'buddypress' ) 133 ) ); 134 } 135 136 /** 137 * Specific bulk actions for signups. 138 * 139 * @since BuddyPress (2.0.0) 140 */ 141 public function get_bulk_actions() { 142 $actions = array( 143 'activate' => _x( 'Activate', 'Pending signup action', 'buddypress' ), 144 'resend' => _x( 'Email', 'Pending signup action', 'buddypress' ), 145 ); 146 147 if ( current_user_can( 'delete_users' ) ) { 148 $actions['delete'] = __( 'Delete' ); 149 } 150 151 return $actions; 152 } 153 154 /** 155 * The text shown when no items are found. 156 * 157 * Nice job, clean sheet! 158 * 159 * @since BuddyPress (2.0.0) 160 */ 161 public function no_items() { 162 _e( 'No pending accounts found.', 'buddypress' ); 163 } 164 165 /** 166 * The columns signups can be reordered with. 167 * 168 * @since BuddyPress (2.0.0) 169 */ 170 public function get_sortable_columns() { 171 return array( 172 'username' => 'login', 173 'email' => 'email', 174 'registered' => 'signup_id', 175 ); 176 } 177 178 /** 179 * Display signups rows. 180 * 181 * @since BuddyPress (2.0.0) 182 */ 183 public function display_rows() { 184 $style = ''; 185 foreach ( $this->items as $userid => $signup_object ) { 186 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 187 echo "\n\t" . $this->single_row( $signup_object, $style ); 188 } 189 } 190 191 /** 192 * Display a signup row. 193 * 194 * @since BuddyPress (2.0.0) 195 * 196 * @see WP_List_Table::single_row() for explanation of params. 197 */ 198 public function single_row( $signup_object = null, $style = '', $role = '', $numposts = 0 ) { 199 echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">'; 200 echo $this->single_row_columns( $signup_object ); 201 echo '</tr>'; 202 } 203 204 /** 205 * Markup for the checkbox used to select items for bulk actions. 206 * 207 * @since BuddyPress (2.0.0) 208 */ 209 public function column_cb( $signup_object = null ) { 210 ?> 211 <label class="screen-reader-text" for="signup_<?php echo intval( $signup_object->id ); ?>"><?php echo esc_html( sprintf( __( 'Select %s' ), $signup_object->user_login ) ); ?></label> 212 <input type="checkbox" id="signup_<?php echo intval( $signup_object->id ) ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" /> 213 <?php 214 } 215 216 /** 217 * The row actions (delete/activate/email). 218 * 219 * @since BuddyPress (2.0.0) 220 * 221 * @param object $signup_object The signup data object. 222 */ 223 public function column_username( $signup_object = null ) { 224 $avatar = get_avatar( $signup_object->user_email, 32 ); 225 226 // Activation email link 227 $email_link = add_query_arg( 228 array( 229 'page' => 'bp-signups', 230 'signup_id' => $signup_object->id, 231 'action' => 'resend', 232 ), 233 bp_get_admin_url( 'users.php' ) 234 ); 235 236 // Activate link 237 $activate_link = add_query_arg( 238 array( 239 'page' => 'bp-signups', 240 'signup_id' => $signup_object->id, 241 'action' => 'activate', 242 ), 243 bp_get_admin_url( 'users.php' ) 244 ); 245 246 // Delete link 247 $delete_link = add_query_arg( 248 array( 249 'page' => 'bp-signups', 250 'signup_id' => $signup_object->id, 251 'action' => 'delete', 252 ), 253 bp_get_admin_url( 'users.php' ) 254 ); 255 256 echo $avatar . '<strong><a href="' . $activate_link .'" class="edit" title="' . esc_attr__( 'Activate', 'buddypress' ) . '">' . $signup_object->user_login .'</a></strong><br/>'; 257 258 $actions = array(); 259 260 $actions['activate'] = '<a href="' . esc_url( $activate_link ) . '">' . __( 'Activate', 'buddypress' ) . '</a>'; 261 262 $actions['resend'] = '<a href="' . esc_url( $email_link ) . '">' . __( 'Email', 'buddypress' ) . '</a>'; 263 264 if ( current_user_can( 'delete_users' ) ) { 265 $actions['delete'] = '<a href="' . esc_url( $delete_link ) . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>'; 266 } 267 268 $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object ); 269 echo $this->row_actions( $actions ); 270 } 271 272 /** 273 * Display user name, if any. 274 * 275 * @since BuddyPress (2.0.0) 276 * 277 * @param object $signup_object The signup data object. 278 */ 279 public function column_name( $signup_object = null ) { 280 echo esc_html( $signup_object->user_name ); 281 } 282 283 /** 284 * Display user email. 285 * 286 * @since BuddyPress (2.0.0) 287 * 288 * @param object $signup_object The signup data object. 289 */ 290 public function column_email( $signup_object = null ) { 291 echo '<a href="mailto:' . esc_attr( $signup_object->user_email ) . '">' . esc_html( $signup_object->user_email ) .'</a>'; 292 } 293 294 /** 295 * Display registration date. 296 * 297 * @since BuddyPress (2.0.0) 298 * 299 * @param object $signup_object The signup data object. 300 */ 301 public function column_registered( $signup_object = null ) { 302 echo mysql2date( 'Y/m/d', $signup_object->registered ); 303 } 304 305 /** 306 * Display the last time an activation email has been sent. 307 * 308 * @since BuddyPress (2.0.0) 309 * 310 * @param object $signup_object The signup data object. 311 */ 312 public function column_date_sent( $signup_object = null ) { 313 echo mysql2date( 'Y/m/d', $signup_object->date_sent ); 314 } 315 316 /** 317 * Display number of time an activation email has been sent. 318 * 319 * @since BuddyPress (2.0.0) 320 */ 321 public function column_count_sent( $signup_object = null ) { 322 echo absint( $signup_object->count_sent ); 323 } 324 } 325 326 endif; 327 328 if ( class_exists( 'WP_MS_Users_List_Table' ) ) : 329 /** 330 * List table class for signups network admin page. 331 * 332 * @since BuddyPress (2.0.0) 333 */ 334 class BP_Members_MS_List_Table extends WP_MS_Users_List_Table { 335 336 /** 337 * Signup counts. 338 * 339 * @since BuddyPress (2.0.0) 340 * 341 * @access public 342 * @var int 343 */ 344 public $signup_counts = 0; 345 346 /** 347 * Constructor 348 * 349 * @since BuddyPress (2.0.0) 350 */ 351 public function __construct() { 352 // Define singular and plural labels, as well as whether we support AJAX. 353 parent::__construct( array( 354 'ajax' => false, 355 'plural' => 'signups', 356 'singular' => 'signup', 357 ) ); 358 } 359 360 /** 361 * Set up items for display in the list table. 362 * 363 * Handles filtering of data, sorting, pagination, and any other data 364 * manipulation required prior to rendering. 365 * 366 * @since BuddyPress (2.0.0) 367 */ 368 public function prepare_items() { 369 global $usersearch, $wpdb, $mode; 370 371 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 372 373 $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 374 375 $paged = $this->get_pagenum(); 376 377 $args = array( 378 'offset' => ( $paged - 1 ) * $signups_per_page, 379 'number' => $signups_per_page, 380 'usersearch' => $usersearch, 381 'orderby' => 'signup_id', 382 'order' => 'DESC' 383 ); 384 385 if ( isset( $_REQUEST['orderby'] ) ) 386 $args['orderby'] = $_REQUEST['orderby']; 387 388 if ( isset( $_REQUEST['order'] ) ) 389 $args['order'] = $_REQUEST['order']; 390 391 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; 392 393 $signups = BP_Signup::get( $args ); 394 395 $this->items = $signups['signups']; 396 $this->signup_counts = $signups['total']; 397 398 $this->set_pagination_args( array( 399 'total_items' => $this->signup_counts, 400 'per_page' => $signups_per_page, 401 ) ); 402 } 403 404 /** 405 * Get the views : the links above the WP List Table. 406 * 407 * @since BuddyPress (2.0.0) 408 * 409 * @uses WP_MS_Users_List_Table::get_views() to get the users views 410 */ 411 function get_views() { 412 $views = parent::get_views(); 413 414 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 415 $class = ' class="current"'; 416 417 $views['registered'] = '<a href="' . add_query_arg( 'page', 'bp-signups', bp_get_admin_url( 'users.php' ) ) . '" class="current">' . sprintf( _nx( 'Pending account <span class="count">(%s)</span>', 'Pending accounts <span class="count">(%s)</span>', $this->signup_counts, 'signup users', 'buddypress' ), number_format_i18n( $this->signup_counts ) ) . '</a>'; 418 419 return $views; 420 } 421 422 /** 423 * Specific signups columns 424 * 425 * @since BuddyPress (2.0.0) 426 */ 427 public function get_columns() { 428 return apply_filters( 'bp_members_ms_signup_columns', array( 429 'cb' => '<input type="checkbox" />', 430 'username' => __( 'Username', 'buddypress' ), 431 'name' => __( 'Name', 'buddypress' ), 432 'email' => __( 'E-mail', 'buddypress' ), 433 'registered' => __( 'Registered', 'buddypress' ), 434 'date_sent' => __( 'Last mail', 'buddypress' ), 435 'count_sent' => __( '# Times Resent', 'buddypress' ) 436 ) ); 437 } 438 439 /** 440 * Specific bulk actions for signups 441 * 442 * @since BuddyPress (2.0.0) 443 */ 444 public function get_bulk_actions() { 445 $actions = array( 446 'activate' => _x( 'Activate', 'Pending signup action', 'buddypress' ), 447 'resend' => _x( 'Email', 'Pending signup action', 'buddypress' ), 448 ); 449 450 if ( current_user_can( 'delete_users' ) ) { 451 $actions['delete'] = __( 'Delete' ); 452 } 453 454 return $actions; 455 } 456 457 /** 458 * The text shown when no items are found. 459 * 460 * Nice job, clean sheet! 461 * 462 * @since BuddyPress (2.0.0) 463 */ 464 public function no_items() { 465 _e( 'No pending accounts found.', 'buddypress' ); 466 } 467 468 /** 469 * The columns signups can be reordered with 470 * 471 * @since BuddyPress (2.0.0) 472 */ 473 public function get_sortable_columns() { 474 return array( 475 'username' => 'login', 476 'email' => 'email', 477 'registered' => 'signup_id', 478 ); 479 } 480 481 /** 482 * Display signups rows. 483 * 484 * @since BuddyPress (2.0.0) 485 */ 486 public function display_rows() { 487 $style = ''; 488 foreach ( $this->items as $userid => $signup_object ) { 489 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 490 echo "\n\t" . $this->single_row( $signup_object, $style ); 491 } 492 } 493 494 /** 495 * Display a signup row. 496 * 497 * @since BuddyPress (2.0.0) 498 * 499 * @see WP_List_Table::single_row() for explanation of params. 500 */ 501 public function single_row( $signup_object = null, $style = '' ) { 502 echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">'; 503 echo $this->single_row_columns( $signup_object ); 504 echo '</tr>'; 505 } 506 507 /** 508 * Markup for the checkbox used to select items for bulk actions. 509 * 510 * @since BuddyPress (2.0.0) 511 */ 512 public function column_cb( $signup_object = null ) { 513 ?> 514 <label class="screen-reader-text" for="signup_<?php echo intval( $signup_object->id ); ?>"><?php echo esc_html( sprintf( __( 'Select %s' ), $signup_object->user_login ) ); ?></label> 515 <input type="checkbox" id="signup_<?php echo intval( $signup_object->id ) ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" /> 516 <?php 517 } 518 519 /** 520 * The row actions (delete/activate/email). 521 * 522 * @since BuddyPress (2.0.0) 523 * 524 * @param object $signup_object The signup data object. 525 */ 526 public function column_username( $signup_object = null ) { 527 $avatar = get_avatar( $signup_object->user_email, 32 ); 528 529 // Activation email link 530 $email_link = add_query_arg( 531 array( 532 'page' => 'bp-signups', 533 'signup_id' => $signup_object->id, 534 'action' => 'resend', 535 ), 536 bp_get_admin_url( 'users.php' ) 537 ); 538 539 // Activate link 540 $activate_link = add_query_arg( 541 array( 542 'page' => 'bp-signups', 543 'signup_id' => $signup_object->id, 544 'action' => 'activate', 545 ), 546 bp_get_admin_url( 'users.php' ) 547 ); 548 549 // Delete link 550 $delete_link = add_query_arg( 551 array( 552 'page' => 'bp-signups', 553 'signup_id' => $signup_object->id, 554 'action' => 'delete', 555 ), 556 bp_get_admin_url( 'users.php' ) 557 ); 558 559 echo $avatar . '<strong><a href="' . esc_url( $activate_link ) .'" class="edit" title="' . esc_attr__( 'Activate', 'buddypress' ) . '">' . $signup_object->user_login .'</a></strong><br/>'; 560 561 $actions['activate'] = '<a href="' . esc_url( $activate_link ) . '">' . __( 'Activate', 'buddypress' ) . '</a>'; 562 563 $actions['resend'] = '<a href="' . esc_url( $email_link ) . '">' . __( 'Email', 'buddypress' ) . '</a>'; 564 565 if ( current_user_can( 'delete_users' ) ) { 566 $actions['delete'] = '<a href="' . esc_url( $delete_link ) . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>'; 567 } 568 569 $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object ); 570 echo $this->row_actions( $actions ); 571 } 572 573 /** 574 * Display user name, if any. 575 * 576 * @since BuddyPress (2.0.0) 577 * 578 * @param object $signup_object The signup data object. 579 */ 580 public function column_name( $signup_object = null ) { 581 echo esc_html( $signup_object->user_name ); 582 } 583 584 /** 585 * Display user email. 586 * 587 * @since BuddyPress (2.0.0) 588 * 589 * @param object $signup_object The signup data object. 590 */ 591 public function column_email( $signup_object = null ) { 592 echo '<a href="mailto:' . esc_attr( $signup_object->user_email ) . '">' . esc_html( $signup_object->user_email ) .'</a>'; 593 } 594 595 /** 596 * Display registration date 597 * 598 * @since BuddyPress (2.0.0) 599 * 600 * @param object $signup_object The signup data object. 601 */ 602 public function column_registered( $signup_object = null ) { 603 global $mode; 604 605 if ( 'list' == $mode ) { 606 $date = 'Y/m/d'; 607 } else { 608 $date = 'Y/m/d \<\b\r \/\> g:i:s a'; 609 } 610 611 echo mysql2date( $date, $signup_object->registered ) . "</td>"; 612 } 613 614 /** 615 * Display the last time an activation email has been sent. 616 * 617 * @since BuddyPress (2.0.0) 618 */ 619 public function column_date_sent( $signup_object = null ) { 620 global $mode; 621 622 if ( 'list' == $mode ) { 623 $date = 'Y/m/d'; 624 } else { 625 $date = 'Y/m/d \<\b\r \/\> g:i:s a'; 626 } 627 628 echo mysql2date( $date, $signup_object->date_sent ); 629 } 630 631 /** 632 * Display number of time an activation email has been sent. 633 * 634 * @since BuddyPress (2.0.0) 635 */ 636 public function column_count_sent( $signup_object = null ) { 637 echo absint( $signup_object->count_sent ); 638 } 639 } 640 641 endif; -
bp-members/bp-members-admin.php
diff --git bp-members/bp-members-admin.php bp-members/bp-members-admin.php index d6fd5be..caddc0b 100644
class BP_Members_Admin { 116 116 117 117 // BuddyPress edit user's profile url 118 118 $this->edit_profile_url = add_query_arg( 'page', 'bp-profile-edit', bp_get_admin_url( 'users.php' ) ); 119 120 // Data specific to signups 121 $this->users_page = ''; 122 $this->signups_page = ''; 123 $this->users_url = bp_get_admin_url( 'users.php' ); 124 $this->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users'; 119 125 } 120 126 121 127 /** … … class BP_Members_Admin { 126 132 */ 127 133 private function setup_actions() { 128 134 129 /** Actions***************************************************/135 /** Community Profile ***************************************************/ 130 136 131 137 // Add some page specific output to the <head> 132 138 add_action( 'bp_admin_head', array( $this, 'admin_head' ), 999 ); … … class BP_Members_Admin { 140 146 // Create the Profile Navigation (WordPress/Community) 141 147 add_action( 'edit_user_profile', array( $this, 'profile_nav' ), 99, 1 ); 142 148 143 144 /** Filters ***************************************************/145 146 149 // Add a row action to users listing 147 150 add_filter( bp_core_do_network_admin() ? 'ms_user_row_actions' : 'user_row_actions', array( $this, 'row_actions' ), 10, 2 ); 148 151 152 /** Signups **************************************************************/ 153 154 if ( bp_get_signup_allowed() ) { 155 if ( ! is_multisite() ) { 156 add_action( 'pre_user_query', array( $this, 'remove_signups_from_user_query'), 10, 1 ); 157 } 158 159 // Reorganise the views navigation in users.php and signups page 160 add_filter( "views_{$this->users_screen}", array( $this, 'signup_filter_view' ), 10, 1 ); 161 add_filter( 'set-screen-option', array( $this, 'signup_screen_options' ), 10, 3 ); 162 } 149 163 } 150 164 151 165 /** 152 * Create the All Users > Edit Profile submenu.166 * Create the All Users > Edit Profile and Signups submenus. 153 167 * 154 168 * @access public 155 169 * @since BuddyPress (2.0.0) … … class BP_Members_Admin { 159 173 public function admin_menus() { 160 174 161 175 // Manage user's profile 162 $hook = $this->user_page = add_users_page(176 $hooks['user'] = $this->user_page = add_users_page( 163 177 __( 'Edit Profile', 'buddypress' ), 164 178 __( 'Edit Profile', 'buddypress' ), 165 179 'bp_moderate', … … class BP_Members_Admin { 167 181 array( &$this, 'user_admin' ) 168 182 ); 169 183 184 $hooks['signups'] = $this->users_page = add_users_page( 185 __( 'Manage Signups', 'buddypress' ), 186 __( 'Manage Signups', 'buddypress' ), 187 'bp_moderate', 188 'bp-signups', 189 array( &$this, 'signups_admin' ) 190 ); 191 170 192 $edit_page = 'user-edit'; 193 $this->users_page = 'users'; 171 194 172 195 if ( bp_core_do_network_admin() ) { 173 $edit_page .= '-network'; 174 $this->user_page .= '-network'; 196 $edit_page .= '-network'; 197 $this->users_page .= '-network'; 198 $this->user_page .= '-network'; 199 $this->signups_page .= '-network'; 175 200 } 176 201 177 202 $this->screen_id = array( $edit_page, $this->user_page ); 178 203 179 add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) ); 180 add_action( "load-$hook", array( $this, 'user_admin_load' ) ); 204 foreach ( $hooks as $key => $hook ) { 205 add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) ); 206 add_action( "load-$hook", array( $this, $key . '_admin_load' ) ); 207 } 208 209 } 210 211 /** 212 * Highlight the Users menu if on Edit Profile or Signups pages. 213 * 214 * @access public 215 * @since BuddyPress (2.0.0) 216 */ 217 public function modify_admin_menu_highlight() { 218 global $plugin_page, $submenu_file; 219 220 // Only Show the All users menu 221 if ( in_array( $plugin_page, array( 'bp-profile-edit', 'bp-signups' ) ) ) { 222 $submenu_file = 'users.php'; 223 } 224 } 181 225 226 /** 227 * Remove the Edit Profile & Signups submenu page. 228 * 229 * We add these pages in order to integrate with WP's Users panel, but 230 * we want them to show up as Views of the WP panel, not as separate 231 * subnav items under the Users menu. 232 * 233 * @access public 234 * @since BuddyPress (2.0.0) 235 */ 236 public function admin_head() { 237 // Remove submenu to force using Profile Navigation 238 remove_submenu_page( 'users.php', 'bp-profile-edit' ); 239 240 // Remove submenu to force using users views 241 remove_submenu_page( 'users.php', 'bp-signups' ); 182 242 } 183 243 244 /** Community Profile ************************************************/ 245 184 246 /** 185 247 * Add some specific styling to the Edit User and Edit User's Profile page. 186 248 * … … class BP_Members_Admin { 248 310 } 249 311 250 312 /** 251 * Highlight the Users menu if on Edit Profile pages.252 *253 * @access public254 * @since BuddyPress (2.0.0)255 */256 public function modify_admin_menu_highlight() {257 global $plugin_page, $submenu_file;258 259 // Only Show the All users menu260 if ( 'bp-profile-edit' == $plugin_page ) {261 $submenu_file = 'users.php';262 }263 }264 265 /**266 * Remove the Edit Profile submenu page.267 *268 * @access public269 * @since BuddyPress (2.0.0)270 */271 public function admin_head() {272 // Remove submenu to force using Profile Navigation273 remove_submenu_page( 'users.php', 'bp-profile-edit' );274 }275 276 /**277 313 * Set up the user's profile admin page. 278 314 * 279 315 * Loaded before the page is rendered, this function does all initial … … class BP_Members_Admin { 691 727 692 728 return array_merge( $new_edit_actions, $actions ); 693 729 } 730 731 /** Signups Management ***********************************************/ 732 733 /** 734 * Display the admin preferences about signups pagination. 735 * 736 * @access public 737 * @since BuddyPress (2.0.0) 738 * 739 * @param int $value 740 * @param string $option 741 * @param int $new_value 742 * @return int the pagination preferences 743 */ 744 public function signup_screen_options( $value = 0, $option = '', $new_value = 0 ) { 745 if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option ) { 746 return $value; 747 } 748 749 // Per page 750 $new_value = (int) $new_value; 751 if ( $new_value < 1 || $new_value > 999 ) { 752 return $value; 753 } 754 755 return $new_value; 756 } 757 758 /** 759 * Make sure no signups will show in users list. 760 * 761 * This is needed to handle signups that may have not been activated 762 * before the 2.0.0 upgrade. 763 * 764 * @since BuddyPress (2.0.0) 765 * 766 * @param WP_User_Query $query The users query. 767 * @return WP_User_Query The users query without the signups. 768 */ 769 public function remove_signups_from_user_query( $query = null ) { 770 global $wpdb; 771 772 if ( bp_is_update() ) { 773 return; 774 } 775 776 if ( $this->users_page != get_current_screen()->id ) { 777 return; 778 } 779 780 if ( ! empty( $query->query_vars['role'] ) ) { 781 return; 782 } 783 784 $query->query_where .= " AND {$wpdb->users}.user_status != 2"; 785 } 786 787 /** 788 * Filter the WP Users List Table views to include 'bp-signups'. 789 * 790 * @since BuddyPress (2.0.0) 791 * 792 * @param array $views WP List Table views. 793 * @return array The views with the signup view added. 794 */ 795 public function signup_filter_view( $views = array() ) { 796 $class = ''; 797 798 $signups = BP_Signup::count_signups(); 799 800 // Remove the 'current' class from All if we're on the signups 801 // view 802 if ( $this->signups_page == get_current_screen()->id ) { 803 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 804 $class = ' class="current"'; 805 } 806 807 $views['registered'] = '<a href="' . add_query_arg( 'page', 'bp-signups', bp_get_admin_url( 'users.php' ) ) . '"' . $class . '>' . sprintf( _nx( 'Pending account <span class="count">(%s)</span>', 'Pending accounts <span class="count">(%s)</span>', $signups, 'signup users', 'buddypress' ), number_format_i18n( $signups ) ) . '</a>'; 808 809 return $views; 810 } 811 812 /** 813 * Load the Signup WP Users List table. 814 * 815 * @since BuddyPress (2.0.0) 816 * 817 * @param string $class The name of the class to use. 818 * @param string $required The parent class. 819 * @return WP_List_Table The List table. 820 */ 821 public static function get_list_table_class( $class = '', $required = '' ) { 822 if ( empty( $class ) ) { 823 return; 824 } 825 826 if ( ! empty( $required ) ) { 827 require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); 828 require_once( buddypress()->members->admin->admin_dir . 'bp-members-classes.php' ); 829 } 830 831 return new $class(); 832 } 833 834 /** 835 * Set up the signups admin page. 836 * 837 * Loaded before the page is rendered, this function does all initial 838 * setup, including: processing form requests, registering contextual 839 * help, and setting up screen options. 840 * 841 * @since BuddyPress (2.0.0) 842 * 843 * @global $bp_members_signup_list_table 844 */ 845 public function signups_admin_load() { 846 global $bp_members_signup_list_table; 847 848 // Build redirection URL 849 $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids' ), $_SERVER['REQUEST_URI'] ); 850 $doaction = bp_admin_list_table_current_bulk_action(); 851 852 // Call an action for plugins to hook in early 853 do_action( 'bp_signups_admin_load', $doaction, $_REQUEST ); 854 855 // Allowed actions 856 $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions', array( 'do_delete', 'do_activate', 'do_resend' ) ); 857 858 // Prepare the display of the Community Profile screen 859 if ( ! in_array( $doaction, $allowed_actions ) || -1 == $doaction ) { 860 861 if ( bp_core_do_network_admin() ) { 862 $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table', 'ms-users' ); 863 } else { 864 $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table', 'users' ); 865 } 866 867 // per_page screen option 868 add_screen_option( 'per_page', array( 'label' => _x( 'Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress' ) ) ); 869 870 get_current_screen()->add_help_tab( array( 871 'id' => 'bp-signups-overview', 872 'title' => __( 'Overview', 'buddypress' ), 873 'content' => 874 '<p>' . __( 'This is the admininistration screen for pending accounts on your site.', 'buddypress' ) . '</p>' . 875 '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' . 876 '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, E-mail or Registered column headers.', 'buddypress' ) . '</p>' . 877 '<p>' . __( 'Using the search form, you can find pending accounts more easily. The Username and E-mail fields will included in the search.', 'buddypress' ) . '</p>' 878 ) ); 879 880 get_current_screen()->add_help_tab( array( 881 'id' => 'bp-signups-actions', 882 'title' => __( 'Actions', 'buddypress' ), 883 'content' => 884 '<p>' . __( 'Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:', 'buddypress' ) . '</p>' . 885 '<ul><li>' . __( '"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.', 'buddypress' ) . '</li>' . 886 '<li>' . __( '"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' . 887 '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress' ) . '</p>' . 888 '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress' ) . '</p>' 889 ) ); 890 891 // Help panel - sidebar links 892 get_current_screen()->set_help_sidebar( 893 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 894 '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-signups/">Managing Signups</a>', 'buddypress' ) . '</p>' . 895 '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 896 ); 897 } else { 898 if ( ! empty( $_REQUEST['signup_ids' ] ) ) { 899 $signups = wp_parse_id_list( $_REQUEST['signup_ids' ] ); 900 } 901 902 // Handle resent activation links 903 if ( 'do_resend' == $doaction ) { 904 // nonce check 905 check_admin_referer( 'signups_resend' ); 906 907 $resent = BP_Signup::resend( $signups ); 908 909 if ( empty( $resent ) ) { 910 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 911 } else { 912 $query_arg = array( 'updated' => 'resent' ); 913 914 if ( ! empty( $resent['resent'] ) ) { 915 $query_arg['resent'] = count( $resent['resent'] ); 916 } 917 918 if ( ! empty( $resent['errors'] ) ) { 919 $query_arg['notsent'] = count( $resent['errors'] ); 920 set_transient( '_bp_admin_signups_errors', $resent['errors'], 30 ); 921 } 922 923 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 924 } 925 926 bp_core_redirect( $redirect_to ); 927 928 // Handle activated accounts 929 } else if ( 'do_activate' == $doaction ) { 930 // nonce check 931 check_admin_referer( 'signups_activate' ); 932 933 $activated = BP_Signup::activate( $signups ); 934 935 if ( empty( $activated ) ) { 936 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 937 } else { 938 $query_arg = array( 'updated' => 'activated' ); 939 940 if ( ! empty( $activated['activated'] ) ) { 941 $query_arg['activated'] = count( $activated['activated'] ); 942 } 943 944 if ( ! empty( $activated['errors'] ) ) { 945 $query_arg['notactivated'] = count( $activated['errors'] ); 946 set_transient( '_bp_admin_signups_errors', $activated['errors'], 30 ); 947 } 948 949 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 950 } 951 952 bp_core_redirect( $redirect_to ); 953 954 // Handle sign-ups delete 955 } else if ( 'do_delete' == $doaction ) { 956 // nonce check 957 check_admin_referer( 'signups_delete' ); 958 959 $deleted = BP_Signup::delete( $signups ); 960 961 if ( empty( $deleted ) ) { 962 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 963 } else { 964 $query_arg = array( 'updated' => 'deleted' ); 965 966 if ( ! empty( $deleted['deleted'] ) ) { 967 $query_arg['deleted'] = count( $deleted['deleted'] ); 968 } 969 970 if ( ! empty( $deleted['errors'] ) ) { 971 $query_arg['notdeleted'] = count( $deleted['errors'] ); 972 set_transient( '_bp_admin_signups_errors', $deleted['errors'], 30 ); 973 } 974 975 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 976 } 977 978 bp_core_redirect( $redirect_to ); 979 980 // Plugins can update other stuff from here 981 } else { 982 $this->redirect = $redirect_to; 983 984 do_action( 'bp_members_admin_update_signups', $doaction, $_REQUEST, $this->redirect ); 985 986 bp_core_redirect( $this->redirect ); 987 } 988 } 989 } 990 991 /** 992 * Display any activation errors. 993 * 994 * @since BuddyPress (2.0.0) 995 */ 996 public function signups_display_errors() { 997 // Bail if no activation errors 998 if ( ! $errors = get_transient( '_bp_admin_signups_errors' ) ) { 999 return; 1000 } 1001 1002 foreach ( $errors as $error ) { 1003 ?> 1004 <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li> 1005 <?php 1006 } 1007 1008 // Delete the redirect transient 1009 delete_transient( '_bp_admin_signups_errors' ); 1010 } 1011 1012 /** 1013 * Signups admin page router. 1014 * 1015 * Depending on the context, display 1016 * - the list of signups 1017 * - or the delete confirmation screen 1018 * - or the activate confirmation screen 1019 * - or the "resend" email confirmation screen 1020 * 1021 * Also prepare the admin notices. 1022 * 1023 * @since BuddyPress (2.0.0) 1024 */ 1025 public function signups_admin() { 1026 $doaction = bp_admin_list_table_current_bulk_action(); 1027 1028 // Prepare notices for admin 1029 $notice = array(); 1030 1031 if ( ! empty( $_REQUEST['updated'] ) ) { 1032 switch ( $_REQUEST['updated'] ) { 1033 case 'resent': 1034 $notice = array( 1035 'class' => 'updated', 1036 'message' => '' 1037 ); 1038 1039 if ( ! empty( $_REQUEST['resent'] ) ) { 1040 $notice['message'] .= sprintf( 1041 _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ', 1042 absint( $_REQUEST['resent'] ), 1043 'signup resent', 1044 'buddypress' 1045 ), 1046 number_format_i18n( absint( $_REQUEST['resent'] ) ) 1047 ); 1048 } 1049 1050 if ( ! empty( $_REQUEST['notsent'] ) ) { 1051 $notice['message'] .= sprintf( 1052 _nx( '%s activation email was not sent.', '%s activation emails were not sent.', 1053 absint( $_REQUEST['notsent'] ), 1054 'signup notsent', 1055 'buddypress' 1056 ), 1057 number_format_i18n( absint( $_REQUEST['notsent'] ) ) 1058 ); 1059 1060 if ( empty( $_REQUEST['resent'] ) ) { 1061 $notice['class'] = 'error'; 1062 } 1063 } 1064 1065 break; 1066 1067 case 'activated': 1068 $notice = array( 1069 'class' => 'updated', 1070 'message' => '' 1071 ); 1072 1073 if ( ! empty( $_REQUEST['activated'] ) ) { 1074 $notice['message'] .= sprintf( 1075 _nx( '%s account successfully activated! ', '%s accounts successfully activated! ', 1076 absint( $_REQUEST['activated'] ), 1077 'signup resent', 1078 'buddypress' 1079 ), 1080 number_format_i18n( absint( $_REQUEST['activated'] ) ) 1081 ); 1082 } 1083 1084 if ( ! empty( $_REQUEST['notactivated'] ) ) { 1085 $notice['message'] .= sprintf( 1086 _nx( '%s account was not activated.', '%s accounts were not activated.', 1087 absint( $_REQUEST['notactivated'] ), 1088 'signup notsent', 1089 'buddypress' 1090 ), 1091 number_format_i18n( absint( $_REQUEST['notactivated'] ) ) 1092 ); 1093 1094 if ( empty( $_REQUEST['activated'] ) ) { 1095 $notice['class'] = 'error'; 1096 } 1097 } 1098 1099 break; 1100 1101 case 'deleted': 1102 $notice = array( 1103 'class' => 'updated', 1104 'message' => '' 1105 ); 1106 1107 if ( ! empty( $_REQUEST['deleted'] ) ) { 1108 $notice['message'] .= sprintf( 1109 _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!', 1110 absint( $_REQUEST['deleted'] ), 1111 'signup deleted', 1112 'buddypress' 1113 ), 1114 number_format_i18n( absint( $_REQUEST['deleted'] ) ) 1115 ); 1116 } 1117 1118 if ( ! empty( $_REQUEST['notdeleted'] ) ) { 1119 $notice['message'] .= sprintf( 1120 _nx( '%s sign-up was not deleted.', '%s sign-ups were not deleted.', 1121 absint( $_REQUEST['notdeleted'] ), 1122 'signup notdeleted', 1123 'buddypress' 1124 ), 1125 number_format_i18n( absint( $_REQUEST['notdeleted'] ) ) 1126 ); 1127 1128 if ( empty( $_REQUEST['deleted'] ) ) { 1129 $notice['class'] = 'error'; 1130 } 1131 } 1132 1133 break; 1134 } 1135 } 1136 1137 // Process error messages 1138 if ( ! empty( $_REQUEST['error'] ) ) { 1139 switch ( $_REQUEST['error'] ) { 1140 case 'do_resend': 1141 $notice = array( 1142 'class' => 'error', 1143 'message' => esc_html__( 'There was a problem sending the activation emails, please try again.', 'buddypress' ), 1144 ); 1145 break; 1146 1147 case 'do_activate': 1148 $notice = array( 1149 'class' => 'error', 1150 'message' => esc_html__( 'There was a problem activating accounts, please try again.', 'buddypress' ), 1151 ); 1152 break; 1153 1154 case 'do_delete': 1155 $notice = array( 1156 'class' => 'error', 1157 'message' => esc_html__( 'There was a problem deleting sign-ups, please try again.', 'buddypress' ), 1158 ); 1159 break; 1160 } 1161 } 1162 1163 // Display notices 1164 if ( ! empty( $notice ) ) : 1165 if ( 'updated' === $notice['class'] ) : ?> 1166 <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>"> 1167 <?php else: ?> 1168 <div class="<?php echo esc_attr( $notice['class'] ); ?>"> 1169 <?php endif; ?> 1170 <p><?php echo $notice['message']; ?></p> 1171 <?php if ( ! empty( $_REQUEST['notactivated'] ) || ! empty( $_REQUEST['notdeleted'] ) || ! empty( $_REQUEST['notsent'] ) ) :?> 1172 <ul><?php $this->signups_display_errors();?></ul> 1173 <?php endif ;?> 1174 </div> 1175 <?php endif; 1176 1177 // Show the proper screen 1178 switch ( $doaction ) { 1179 case 'activate' : 1180 case 'delete' : 1181 case 'resend' : 1182 $this->signups_admin_manage( $doaction ); 1183 break; 1184 1185 default: 1186 $this->signups_admin_index(); 1187 break; 1188 1189 } 1190 } 1191 1192 /** 1193 * This is the list of the Pending accounts (signups). 1194 * 1195 * @since BuddyPress (2.0.0) 1196 * 1197 * @global $plugin_page 1198 * @global $bp_members_signup_list_table 1199 */ 1200 public function signups_admin_index() { 1201 global $plugin_page, $bp_members_signup_list_table; 1202 1203 $usersearch = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; 1204 1205 // Prepare the group items for display 1206 $bp_members_signup_list_table->prepare_items(); 1207 1208 $form_url = add_query_arg( 1209 array( 1210 'page' => 'bp-signups', 1211 ), 1212 bp_get_admin_url( 'users.php' ) 1213 ); 1214 1215 $search_form_url = remove_query_arg( 1216 array( 1217 'action', 1218 'deleted', 1219 'notdeleted', 1220 'error', 1221 'updated', 1222 'delete', 1223 'activate', 1224 'activated', 1225 'notactivated', 1226 'resend', 1227 'resent', 1228 'notresent', 1229 'do_delete', 1230 'do_activate', 1231 'do_resend', 1232 'action2', 1233 '_wpnonce', 1234 'signup_ids' 1235 ), $_SERVER['REQUEST_URI'] 1236 ); 1237 1238 ?> 1239 1240 <div class="wrap"> 1241 <?php screen_icon( 'users' ); ?> 1242 <h2> 1243 <?php 1244 _e( 'Users', 'buddypress' ); 1245 if ( current_user_can( 'create_users' ) ) { ?> 1246 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> 1247 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> 1248 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> 1249 <?php } 1250 1251 if ( $usersearch ) { 1252 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); 1253 } 1254 1255 ?> 1256 </h2> 1257 1258 <?php // Display each signups on its own row ?> 1259 <?php $bp_members_signup_list_table->views(); ?> 1260 1261 <form id="bp-signups-search-form" action="<?php echo esc_url( $search_form_url ) ;?>"> 1262 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" /> 1263 <?php $bp_members_signup_list_table->search_box( __( 'Search Pending accounts', 'buddypress' ), 'bp-signups' ); ?> 1264 </form> 1265 1266 <form id="bp-signups-form" action="<?php echo esc_url( $form_url );?>" method="post"> 1267 <?php $bp_members_signup_list_table->display(); ?> 1268 </form> 1269 </div> 1270 <?php 1271 } 1272 1273 /** 1274 * This is the confirmation screen for actions. 1275 * 1276 * @since BuddyPress (2.0.0) 1277 * 1278 * @param string $action Delete, activate, or resend activation link. 1279 */ 1280 public function signups_admin_manage( $action = '' ) { 1281 if ( ! is_super_admin() || empty( $action ) ) { 1282 die( '-1' ); 1283 } 1284 1285 // Get the user IDs from the URL 1286 $ids = false; 1287 if ( ! empty( $_POST['allsignups'] ) ) { 1288 $ids = wp_parse_id_list( $_POST['allsignups'] ); 1289 } else if ( ! empty( $_GET['signup_id'] ) ) { 1290 $ids = absint( $_GET['signup_id'] ); 1291 } 1292 1293 if ( empty( $ids ) ) { 1294 return false; 1295 } 1296 1297 // Query for signups, and filter out those IDs that don't 1298 // correspond to an actual signup 1299 $signups_query = BP_Signup::get( array( 1300 'include' => $ids, 1301 ) ); 1302 1303 $signups = $signups_query['signups']; 1304 $signup_ids = wp_list_pluck( $signups, 'signup_id' ); 1305 1306 // Set up strings 1307 switch ( $action ) { 1308 case 'delete' : 1309 $header_text = __( 'Delete Pending Accounts', 'buddypress' ); 1310 $helper_text = _n( 'You are about to delete the following account:', 'You are about to delete the following accounts:', count( $signup_ids ), 'buddypress' ); 1311 break; 1312 1313 case 'activate' : 1314 $header_text = __( 'Activate Pending Accounts', 'buddypress' ); 1315 $helper_text = _n( 'You are about to activate the following account:', 'You are about to activate the following accounts:', count( $signup_ids ), 'buddypress' ); 1316 break; 1317 1318 case 'resend' : 1319 $header_text = __( 'Resend Activation Emails', 'buddypress' ); 1320 $helper_text = _n( 'You are about to resend an activation email to the following account:', 'You are about to resend activation emails to the following accounts:', count( $signup_ids ), 'buddypress' ); 1321 break; 1322 } 1323 1324 // These arguments are added to all URLs 1325 $url_args = array( 'page' => 'bp-signups' ); 1326 1327 // These arguments are only added when performing an action 1328 $action_args = array( 1329 'action' => 'do_' . $action, 1330 'signup_ids' => implode( ',', $signup_ids ) 1331 ); 1332 1333 $cancel_url = add_query_arg( $url_args, bp_get_admin_url( 'users.php' ) ); 1334 $action_url = wp_nonce_url( 1335 add_query_arg( 1336 array_merge( $url_args, $action_args ), 1337 bp_get_admin_url( 'users.php' ) 1338 ), 1339 'signups_' . $action 1340 ); 1341 1342 ?> 1343 1344 <div class="wrap"> 1345 <?php screen_icon( 'users' ); ?> 1346 <h2><?php echo esc_html( $header_text ); ?></h2> 1347 <p><?php echo esc_html( $helper_text ); ?></p> 1348 1349 <ol class="bp-signups-list"> 1350 <?php foreach ( $signups as $signup ) : 1351 $last_notified = mysql2date( 'Y/m/d g:i:s a', $signup->date_sent ) 1352 ?> 1353 1354 <li> 1355 <?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?> 1356 1357 <?php if ( 'resend' == $action ) :?> 1358 1359 <?php printf( esc_html__( 'Last notified: %s', 'buddypress'), $last_notified ) ;?> 1360 1361 <?php if ( ! empty( $signup->recently_sent ) ) : ?> 1362 <span class="attention wp-ui-text-notification"> (<?php esc_html_e( 'less than 24 hours ago', 'buddypress' );?>)</span> 1363 <?php endif; ?> 1364 1365 <?php endif; ?> 1366 </li> 1367 1368 <?php endforeach; ?> 1369 </ol> 1370 1371 <?php if ( 'resend' != $action ) : ?> 1372 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p> 1373 <?php endif ; ?> 1374 1375 <a class="button-primary" href="<?php echo esc_url( $action_url ); ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a> 1376 <a class="button" href="<?php echo esc_url( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a> 1377 </div> 1378 1379 <?php 1380 } 694 1381 } 695 1382 endif; // class_exists check 696 1383 -
bp-members/bp-members-classes.php
diff --git bp-members/bp-members-classes.php bp-members/bp-members-classes.php index e69de29..0554bab 100644
1 <?php 2 3 /** 4 * Signups Management class. 5 * 6 * @package BuddyPress 7 * @subpackage coreClasses 8 * 9 * @since BuddyPress (2.0.0) 10 */ 11 class BP_Signup { 12 13 /** 14 * ID of the signup which the object relates to. 15 * 16 * @var integer 17 */ 18 public $id; 19 20 /** 21 * The URL to the full size of the avatar for the user. 22 * 23 * @var string 24 */ 25 public $avatar; 26 27 /** 28 * The username for the user. 29 * 30 * @var string 31 */ 32 public $user_login; 33 34 /** 35 * The email for the user. 36 * 37 * @var string 38 */ 39 public $user_email; 40 41 /** 42 * The full name of the user. 43 * 44 * @var string 45 */ 46 public $user_name; 47 48 /** 49 * Metadata associated with the signup. 50 * 51 * @var array 52 */ 53 public $meta; 54 55 /** 56 * The registered date for the user. 57 * 58 * @var string 59 */ 60 public $registered; 61 62 /** 63 * The activation key for the user. 64 * 65 * @var string 66 */ 67 public $activation_key; 68 69 70 /** Public Methods *******************************************************/ 71 72 /** 73 * Class constructor. 74 * 75 * @since BuddyPress (2.0.0) 76 * 77 * @param integer $signup_id The ID for the signup being queried. 78 */ 79 public function __construct( $signup_id = 0 ) { 80 if ( !empty( $signup_id ) ) { 81 $this->id = $signup_id; 82 $this->populate(); 83 } 84 } 85 86 /** 87 * Populate the instantiated class with data based on the signup_id provided. 88 * 89 * @since BuddyPress (2.0.0) 90 */ 91 public function populate() { 92 global $wpdb; 93 94 $signups_table = buddypress()->members->table_name_signups; 95 96 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE signup_id = %d AND active = 0", $this->id ) ); 97 98 $this->avatar = get_avatar( $signup->user_email, 32 ); 99 $this->user_login = $signup->user_login; 100 $this->user_email = $signup->user_email; 101 $this->meta = maybe_unserialize( $signup->meta ); 102 $this->user_name = ! empty( $meta['field_1'] ) ? wp_unslash( $meta['field_1'] ) : ''; 103 $this->registered = $signup->registered; 104 $this->activation_key = $signup->activation_key; 105 } 106 107 /** Static Methods *******************************************************/ 108 109 /** 110 * Fetch signups based on parameters. 111 * 112 * @since BuddyPress (2.0.0) 113 * 114 * @param array $args the argument to retrieve desired signups 115 * @return array { 116 * @type array $signups Located signups. 117 * @type int $total Total number of signups matching params. 118 * } 119 */ 120 public static function get( $args = array() ) { 121 global $wpdb; 122 123 $r = bp_parse_args( $args, 124 array( 125 'offset' => 0, 126 'number' => 1, 127 'usersearch' => false, 128 'orderby' => 'signup_id', 129 'order' => 'DESC', 130 'include' => false, 131 'activation_key' => '', 132 'user_login' => '', 133 ), 134 'bp_core_signups_get_args' 135 ); 136 137 // @todo whitelist sanitization 138 if ( $r['orderby'] != 'signup_id' ) { 139 $r['orderby'] = 'user_' . $r['orderby']; 140 } 141 142 $r['orderby'] = sanitize_title( $r['orderby'] ); 143 144 $sql = array(); 145 $signups_table = buddypress()->members->table_name_signups; 146 $sql['select'] = "SELECT * FROM {$signups_table}"; 147 $sql['where'] = array(); 148 $sql['where'][] = "active = 0"; 149 150 if ( empty( $r['include'] ) ) { 151 // Search terms 152 if ( ! empty( $r['usersearch'] ) ) { 153 $search_terms_clean = mysql_real_escape_string( mysql_real_escape_string( $r['usersearch'] ) ); 154 $search_terms_clean = like_escape( $search_terms_clean ); 155 $sql['where'][] = "( user_login LIKE '%" . $search_terms_clean . "%' OR user_email LIKE '%" . $search_terms_clean . "%' OR meta LIKE '%" . $search_terms_clean . "%' )"; 156 } 157 158 // Activation key 159 if ( ! empty( $r['activation_key'] ) ) { 160 $sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] ); 161 } 162 163 // User login 164 if ( ! empty( $r['user_login'] ) ) { 165 $sql['where'][] = $wpdb->prepare( "user_login = %s", $r['user_login'] ); 166 } 167 168 $sql['orderby'] = "ORDER BY {$r['orderby']}"; 169 $sql['order'] = bp_esc_sql_order( $r['order'] ); 170 $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", $r['offset'], $r['number'] ); 171 } else { 172 $in = implode( ',', wp_parse_id_list( $r['include'] ) ); 173 $sql['in'] = "AND signup_id IN ({$in})"; 174 } 175 176 // Implode WHERE clauses 177 $sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] ); 178 179 $paged_signups = $wpdb->get_results( apply_filters( 'bp_members_signups_paged_query', join( ' ', $sql ), $sql, $args, $r ) ); 180 181 if ( empty( $paged_signups ) ) { 182 return array( 'signups' => false, 'total' => false ); 183 } 184 185 // Used to calculate a diff between now & last 186 // time an activation link has been resent 187 $now = current_time( 'timestamp', true ); 188 189 foreach ( (array) $paged_signups as $key => $signup ) { 190 191 $signup->id = intval( $signup->signup_id ); 192 193 $signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false; 194 195 $signup->user_name = ''; 196 if ( ! empty( $signup->meta['field_1'] ) ) { 197 $signup->user_name = wp_unslash( $signup->meta['field_1'] ); 198 } 199 200 // Sent date defaults to date of registration 201 if ( ! empty( $signup->meta['sent_date'] ) ) { 202 $signup->date_sent = $signup->meta['sent_date']; 203 } else { 204 $signup->date_sent = $signup->registered; 205 } 206 207 $sent_at = mysql2date('U', $signup->date_sent ); 208 $diff = $now - $sent_at; 209 210 /** 211 * add a boolean in case the last time an activation link 212 * has been sent happened less than a day ago 213 */ 214 if ( $diff < 1 * DAY_IN_SECONDS ) { 215 $signup->recently_sent = true; 216 } 217 218 if ( ! empty( $signup->meta['count_sent'] ) ) { 219 $signup->count_sent = absint( $signup->meta['count_sent'] ); 220 } else { 221 $signup->count_sent = 1; 222 } 223 224 $paged_signups[ $key ] = $signup; 225 } 226 227 unset( $sql['limit'] ); 228 $sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] ); 229 $total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) ); 230 231 return array( 'signups' => $paged_signups, 'total' => $total_signups ); 232 } 233 234 /** 235 * Add a signup. 236 * 237 * @since BuddyPress (2.0.0) 238 * 239 * @param array $args 240 * @return int|bool ID of newly created signup on success, false on 241 * failure. 242 */ 243 public static function add( $args = array() ) { 244 global $wpdb; 245 246 $r = bp_parse_args( $args, 247 array( 248 'domain' => '', 249 'path' => '', 250 'title' => '', 251 'user_login' => '', 252 'user_email' => '', 253 'registered' => current_time( 'mysql', true ), 254 'activation_key' => '', 255 'meta' => '', 256 ), 257 'bp_core_signups_add_args' 258 ); 259 260 $r['meta'] = maybe_serialize( $r['meta'] ); 261 262 $inserted = $wpdb->insert( 263 buddypress()->members->table_name_signups, 264 $r, 265 array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) 266 ); 267 268 if ( $inserted ) { 269 $retval = $wpdb->insert_id; 270 } else { 271 $retval = false; 272 } 273 274 return apply_filters( 'bp_core_signups_add', $retval ); 275 } 276 277 /** 278 * Create a WP user at signup. 279 * 280 * Since BP 2.0, non-multisite configurations have stored signups in 281 * the same way as Multisite configs traditionally have: in the 282 * wp_signups table. However, because some plugins may be looking 283 * directly in the wp_users table for non-activated signups, we 284 * mirror signups there by creating "phantom" users, mimicking WP's 285 * default behavior. 286 * 287 * @since BuddyPress (2.0.0) 288 * 289 * @param string $user_login User login string. 290 * @param string $user_password User password. 291 * @param string $user_email User email address. 292 * @param array $usermeta Metadata associated with the signup. 293 * @return int User id. 294 */ 295 public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) { 296 global $wpdb; 297 298 $errors = new WP_Error(); 299 300 $user_id = wp_insert_user( array( 301 'user_login' => $user_login, 302 'user_pass' => $user_password, 303 'display_name' => sanitize_title( $user_login ), 304 'user_email' => $user_email 305 ) ); 306 307 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 308 $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn’t register you. Please contact the <a href="mailto:%s">webmaster</a>.', 'buddypress' ), bp_get_option( 'admin_email' ) ) ); 309 return $errors; 310 } 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 332 $current_field = $usermeta["field_{$field_id}"]; 333 xprofile_set_field_data( $field_id, $user_id, $current_field ); 334 335 // Save the visibility level 336 $visibility_level = ! empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public'; 337 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 338 } 339 } 340 } 341 342 return apply_filters( 'bp_core_signups_add_backcompat', $user_id ); 343 } 344 345 /** 346 * Check a user status (from wp_users) on a non-multisite config. 347 * 348 * @since BuddyPress (2.0.0) 349 * 350 * @param int $user_id ID of the user being checked. 351 * @return int|bool The status if found, otherwise false. 352 */ 353 public static function check_user_status( $user_id = 0 ) { 354 global $wpdb; 355 356 if ( empty( $user_id ) ) 357 return false; 358 359 $user_status = $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id ) ); 360 361 return apply_filters( 'bp_core_signups_check_user_status', intval( $user_status ) ); 362 } 363 364 /** 365 * Activate a signup. 366 * 367 * @since BuddyPress (2.0.0) 368 * 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 379 $activated = $wpdb->update( 380 // Signups table 381 buddypress()->members->table_name_signups, 382 array( 383 'active' => 1, 384 'activated' => current_time( 'mysql', true ), 385 ), 386 array( 387 'activation_key' => $key, 388 ), 389 // Data sanitization format 390 array( 391 '%d', 392 '%s', 393 ), 394 // WHERE sanitization format 395 array( 396 '%s', 397 ) 398 ); 399 400 return apply_filters( 'bp_core_signups_validate', $activated ); 401 } 402 403 /** 404 * How many inactive signups do we have? 405 * 406 * @since BuddyPress (2.0.0) 407 * 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 return apply_filters( 'bp_core_signups_count', (int) $count_signups ); 417 } 418 419 /** 420 * Update the meta for a signup. 421 * 422 * This is the way we use to "trace" the last date an activation 423 * email was sent and how many times activation was sent. 424 * 425 * @since BuddyPress (2.0.0) 426 * 427 * @param array $args 428 * @return int the signup id 429 */ 430 public static function update( $args = array() ) { 431 global $wpdb; 432 433 $r = bp_parse_args( $args, 434 array( 435 'signup_id' => 0, 436 'meta' => array(), 437 ), 438 'bp_core_signups_update_args' 439 ); 440 441 if ( empty( $r['signup_id'] ) || empty( $r['meta'] ) ) { 442 return false; 443 } 444 445 $wpdb->update( 446 // Signups table 447 buddypress()->members->table_name_signups, 448 // Data to update 449 array( 450 'meta' => serialize( $r['meta'] ), 451 ), 452 // WHERE 453 array( 454 'signup_id' => $r['signup_id'], 455 ), 456 // Data sanitization format 457 array( 458 '%s', 459 ), 460 // WHERE sanitization format 461 array( 462 '%d', 463 ) 464 ); 465 466 return apply_filters( 'bp_core_signups_update', $r['signup_id'] ); 467 } 468 469 /** 470 * Resend an activation email. 471 * 472 * @since BuddyPress (2.0.0) 473 * 474 * @param array $signup_ids single id or list of ids to resend 475 * @return array the results 476 */ 477 public static function resend( $signup_ids = array() ) { 478 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) { 479 return false; 480 } 481 482 $to_resend = self::get( array( 483 'include' => $signup_ids, 484 ) ); 485 486 if ( ! $signups = $to_resend['signups'] ) { 487 return false; 488 } 489 490 $result = array(); 491 492 do_action( 'bp_core_signup_before_resend', $signup_ids ); 493 494 foreach ( $signups as $signup ) { 495 496 $meta = $signup->meta; 497 $meta['sent_date'] = current_time( 'mysql', true ); 498 $meta['count_sent'] = $signup->count_sent + 1; 499 500 // Send activation email 501 if ( is_multisite() ) { 502 wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) ); 503 } else { 504 505 // Check user status before sending email 506 $user_id = email_exists( $signup->user_email ); 507 508 if ( ! empty( $user_id ) && 2 != self::check_user_status( $user_id ) ) { 509 // Status is not 2, so user's account has been activated 510 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );; 511 // repare signups table 512 self::validate( $signup->activation_key ); 513 continue; 514 515 // Send the validation email 516 } else { 517 bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key ); 518 } 519 } 520 521 // Update metas 522 $result['resent'][] = self::update( array( 523 'signup_id' => $signup->signup_id, 524 'meta' => $meta, 525 ) ); 526 } 527 528 do_action( 'bp_core_signup_after_resend', $signup_ids, $result ); 529 530 return apply_filters( 'bp_core_signup_resend', $result ); 531 } 532 533 /** 534 * Activate a pending account. 535 * 536 * @since BuddyPress (2.0.0) 537 * 538 * @param array $signup_ids Single id or list of ids to resend. 539 * @return array the results 540 */ 541 public static function activate( $signup_ids = array() ) { 542 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) { 543 return false; 544 } 545 546 $to_activate = self::get( array( 547 'include' => $signup_ids, 548 ) ); 549 550 if ( ! $signups = $to_activate['signups'] ) { 551 return false; 552 } 553 554 $result = array(); 555 556 do_action( 'bp_core_signup_before_activate', $signup_ids ); 557 558 foreach ( $signups as $signup ) { 559 560 $user = bp_core_activate_signup( $signup->activation_key ); 561 562 if ( ! empty( $user->errors ) ) { 563 564 if ( $user_id = username_exists( $signup->user_login ) && 2 != self::check_user_status( $user_id ) ) { 565 // Status is not 2, so user's account has been activated 566 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) ); 567 // repare signups table 568 self::validate( $signup->activation_key ); 569 570 // we have a user id, account is not active, let's delete it 571 } else { 572 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() ); 573 } 574 575 } else { 576 $result['activated'][] = $user; 577 } 578 } 579 580 do_action( 'bp_core_signup_after_activate', $signup_ids, $result ); 581 582 return apply_filters( 'bp_core_signup_activate', $result ); 583 } 584 585 /** 586 * Delete a pending account. 587 * 588 * @since BuddyPress (2.0.0) 589 * 590 * @param array $signup_ids single id or list of ids to resend 591 * @return array the results 592 */ 593 public static function delete( $signup_ids = array() ) { 594 global $wpdb; 595 596 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) { 597 return false; 598 } 599 600 $to_delete = self::get( array( 601 'include' => $signup_ids, 602 ) ); 603 604 if ( ! $signups = $to_delete['signups'] ) { 605 return false; 606 } 607 608 $result = array(); 609 610 do_action( 'bp_core_signup_before_delete', $signup_ids ); 611 612 foreach ( $signups as $signup ) { 613 $user_id = username_exists( $signup->user_login ); 614 615 if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) { 616 617 if ( 2 != self::check_user_status( $user_id ) ) { 618 // Status is not 2, so user's account has been activated 619 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) ); 620 // repare signups table 621 self::validate( $signup->activation_key ); 622 623 // we have a user id, account is not active, let's delete it 624 } else { 625 bp_core_delete_account( $user_id ); 626 } 627 } 628 629 if ( empty( $result['errors'][ $signup->signup_id ] ) ) { 630 $wpdb->delete( 631 // Signups table 632 buddypress()->members->table_name_signups, 633 // Where 634 array( 'signup_id' => $signup->signup_id, ), 635 // WHERE sanitization format 636 array( '%d', ) 637 ); 638 639 $result['deleted'][] = $signup->signup_id; 640 } 641 } 642 643 do_action( 'bp_core_signup_after_delete', $signup_ids, $result ); 644 645 return apply_filters( 'bp_core_signup_delete', $result ); 646 } 647 } -
bp-members/bp-members-functions.php
diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php index 9212f9b..9021277 100644
function bp_core_validate_user_signup( $user_name, $user_email ) { 1300 1300 $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) ); 1301 1301 } 1302 1302 1303 // Check into signups 1304 $signups = BP_Signup::get( array( 1305 'user_login' => $user_name, 1306 ) ); 1307 1308 $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false; 1309 1303 1310 // Check if the username has been used already. 1304 if ( username_exists( $user_name ) ) {1311 if ( username_exists( $user_name ) || ! empty( $signup ) ) { 1305 1312 $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) ); 1306 1313 } 1307 1314 … … function bp_core_validate_blog_signup( $blog_url, $blog_title ) { 1332 1339 } 1333 1340 1334 1341 function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) { 1335 global $bp, $wpdb; 1342 global $bp; 1343 1344 // We need to cast $user_id to pass to the filters 1345 $user_id = false; 1336 1346 1337 1347 // Multisite installs have their own install procedure 1338 1348 if ( is_multisite() ) { 1339 1349 wpmu_signup_user( $user_login, $user_email, $usermeta ); 1340 1350 1341 // On multisite, the user id is not created until the user activates the account1342 // but we need to cast $user_id to pass to the filters1343 $user_id = false;1344 1345 1351 } else { 1346 $errors = new WP_Error(); 1347 1348 $user_id = wp_insert_user( array( 1349 'user_login' => $user_login, 1350 'user_pass' => $user_password, 1351 'display_name' => sanitize_title( $user_login ), 1352 'user_email' => $user_email 1353 ) ); 1352 // Format data 1353 $user_login = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) ); 1354 $user_email = sanitize_email( $user_email ); 1355 $activation_key = substr( md5( time() . rand() . $user_email ), 0, 16 ); 1356 1357 /** 1358 * WordPress's default behavior is to create user accounts 1359 * immediately at registration time. BuddyPress uses a system 1360 * borrowed from WordPress Multisite, where signups are stored 1361 * separately and accounts are only created at the time of 1362 * activation. For backward compatibility with plugins that may 1363 * be anticipating WP's default behavior, BP silently creates 1364 * accounts for registrations (though it does not use them). If 1365 * you know that you are not running any plugins dependent on 1366 * these pending accounts, you may want to save a little DB 1367 * clutter by defining setting the BP_SIGNUPS_SKIP_USER_CREATION 1368 * to true in your wp-config.php file. 1369 */ 1370 if ( ! defined( 'BP_SIGNUPS_SKIP_USER_CREATION' ) || ! BP_SIGNUPS_SKIP_USER_CREATION ) { 1371 $user_id = BP_Signup::add_backcompat( $user_login, $user_password, $user_email, $usermeta ); 1372 1373 if ( is_wp_error( $user_id ) ) { 1374 return $user_id; 1375 } 1354 1376 1355 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 1356 $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), bp_get_option( 'admin_email' ) ) ); 1357 return $errors; 1377 $activation_key = wp_hash( $user_id ); 1378 update_user_meta( $user_id, 'activation_key', $activation_key ); 1358 1379 } 1359 1380 1360 // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) 1361 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) ); 1362 1363 // Set any profile data 1364 if ( bp_is_active( 'xprofile' ) ) { 1365 if ( !empty( $usermeta['profile_field_ids'] ) ) { 1366 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); 1367 1368 foreach( (array) $profile_field_ids as $field_id ) { 1369 if ( empty( $usermeta["field_{$field_id}"] ) ) 1370 continue; 1371 1372 $current_field = $usermeta["field_{$field_id}"]; 1373 xprofile_set_field_data( $field_id, $user_id, $current_field ); 1374 1375 // Save the visibility level 1376 $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public'; 1377 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 1378 } 1379 } 1380 } 1381 } 1382 $bp->signup->username = $user_login; 1381 $args = array( 1382 'user_login' => $user_login, 1383 'user_email' => $user_email, 1384 'activation_key' => $activation_key, 1385 'meta' => $usermeta, 1386 ); 1383 1387 1384 /*** 1385 * Now generate an activation key and send an email to the user so they can activate their 1386 * account and validate their email address. Multisite installs send their own email, so 1387 * this is only for single blog installs. 1388 * 1389 * To disable sending activation emails you can user the filter 1390 * 'bp_core_signup_send_activation_key' and return false. Note that this will only disable 1391 * the email - a key will still be generated, and the account must still be activated 1392 * before use. 1393 */ 1394 if ( !is_multisite() ) { 1395 $activation_key = wp_hash( $user_id ); 1396 update_user_meta( $user_id, 'activation_key', $activation_key ); 1388 BP_Signup::add( $args ); 1397 1389 1398 1390 if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) { 1399 1391 bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key ); 1400 1392 } 1401 1393 } 1402 1394 1395 $bp->signup->username = $user_login; 1396 1403 1397 do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta ); 1404 1398 1405 1399 return $user_id; … … function bp_core_activate_signup( $key ) { 1422 1416 $user = wpmu_activate_signup( $key ); 1423 1417 1424 1418 // If there were errors, add a message and redirect 1425 if ( ! empty( $user->errors ) ) {1419 if ( ! empty( $user->errors ) ) { 1426 1420 return $user; 1427 1421 } 1428 1422 1429 1423 $user_id = $user['user_id']; 1430 1424 1431 // Set any profile data1432 if ( bp_is_active( 'xprofile' ) ) {1433 if ( !empty( $user['meta']['profile_field_ids'] ) ) {1434 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids']);1425 } else { 1426 $signups = BP_Signup::get( array( 1427 'activation_key' => $key, 1428 ) ); 1435 1429 1436 foreach( (array) $profile_field_ids as $field_id ) { 1437 $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false; 1430 if ( empty( $signups['signups'] ) ) { 1431 return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) ); 1432 } 1438 1433 1439 if ( !empty( $current_field ) ) 1440 xprofile_set_field_data( $field_id, $user_id, $current_field ); 1434 $signup = $signups['signups'][0]; 1441 1435 1442 // Save the visibility level 1443 $visibility_level = !empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; 1444 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 1445 } 1436 if ( $signup->active ) { 1437 if ( empty( $signup->domain ) ) { 1438 return new WP_Error( 'already_active', __( 'The user is already active.', 'buddypress' ), $signup ); 1439 } else { 1440 return new WP_Error( 'already_active', __( 'The site is already active.', 'buddypress' ), $signup ); 1446 1441 } 1447 1442 } 1448 } else {1449 1443 1450 // Get the user_id based on the $key 1451 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) ); 1444 // password is hashed again in wp_insert_user 1445 $password = wp_generate_password( 12, false ); 1446 1447 $user_id = username_exists( $signup->user_login ); 1448 1449 // Create the user 1450 if ( ! $user_id ) { 1451 $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email ); 1452 1453 // If a user ID is found, this may be a legacy signup, or one 1454 // created locally for backward compatibility. Process it. 1455 } else if ( $key == wp_hash( $user_id ) ) { 1456 // Change the user's status so they become active 1457 if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) { 1458 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1459 } 1460 1461 bp_delete_user_meta( $user_id, 'activation_key' ); 1462 1463 $member = get_userdata( $user_id ); 1464 $member->set_role( get_option('default_role') ); 1465 1466 $user_already_created = true; 1452 1467 1453 if ( empty( $user_id ) ) 1454 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1468 } else { 1469 $user_already_exists = true; 1470 } 1471 1472 if ( ! $user_id ) { 1473 return new WP_Error( 'create_user', __( 'Could not create user', 'buddypress' ), $signup ); 1474 } 1455 1475 1456 // Change the user's status so they become active 1457 if ( !$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) 1458 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1476 // Fetch the signup so we have the data later on 1477 $signups = BP_Signup::get( array( 1478 'activation_key' => $key, 1479 ) ); 1480 1481 $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false; 1482 1483 // Activate the signup 1484 BP_Signup::validate( $key ); 1485 1486 if ( isset( $user_already_exists ) ) { 1487 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup ); 1488 } 1489 1490 // Set up data to pass to the legacy filter 1491 $user = array( 1492 'user_id' => $user_id, 1493 'password' => $signup->meta['password'], 1494 'meta' => $signup->meta, 1495 ); 1459 1496 1460 1497 // Notify the site admin of a new user registration 1461 1498 wp_new_user_notification( $user_id ); 1462 1499 1463 // Remove the activation key meta 1464 delete_user_meta( $user_id, 'activation_key' ); 1500 if ( isset( $user_already_created ) ) { 1501 do_action( 'bp_core_activated_user', $user_id, $key, $user ); 1502 return $user_id; 1503 } 1504 } 1505 1506 // Set any profile data 1507 if ( bp_is_active( 'xprofile' ) ) { 1508 if ( ! empty( $user['meta']['profile_field_ids'] ) ) { 1509 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] ); 1510 1511 foreach( (array) $profile_field_ids as $field_id ) { 1512 $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false; 1513 1514 if ( !empty( $current_field ) ) 1515 xprofile_set_field_data( $field_id, $user_id, $current_field ); 1516 1517 // Save the visibility level 1518 $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; 1519 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 1520 } 1521 } 1465 1522 } 1466 1523 1467 1524 // Update the display_name 1468 wp_update_user( array( 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname( $user_id ) ) ); 1525 wp_update_user( array( 1526 'ID' => $user_id, 1527 'display_name' => bp_core_get_user_displayname( $user_id ), 1528 ) ); 1469 1529 1470 1530 // Set the password on multisite installs 1471 if ( is_multisite() && !empty( $user['meta']['password'] ) )1531 if ( ! empty( $user['meta']['password'] ) ) { 1472 1532 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) ); 1533 } 1473 1534 1474 1535 do_action( 'bp_core_activated_user', $user_id, $key, $user ); 1475 1536 -
bp-members/bp-members-loader.php
diff --git bp-members/bp-members-loader.php bp-members/bp-members-loader.php index d88380b..a9fafa4 100644
class BP_Members_Component extends BP_Component { 37 37 public function includes( $includes = array() ) { 38 38 $includes = array( 39 39 'actions', 40 'classes', 40 41 'filters', 41 42 'screens', 42 43 'template', … … class BP_Members_Component extends BP_Component { 68 69 if ( !defined( 'BP_MEMBERS_SLUG' ) ) 69 70 define( 'BP_MEMBERS_SLUG', $this->id ); 70 71 71 parent::setup_globals(array(72 $members_globals = array( 72 73 'slug' => BP_MEMBERS_SLUG, 73 74 'root_slug' => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 74 75 'has_directory' => true, … … class BP_Members_Component extends BP_Component { 76 77 'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 77 78 ), 78 79 'search_string' => __( 'Search Members...', 'buddypress' ), 79 ) ); 80 ); 81 82 if ( bp_get_signup_allowed() ) { 83 $members_globals['global_tables']['table_name_signups'] = bp_core_get_table_prefix() . 'signups'; 84 } 85 86 parent::setup_globals( $members_globals ); 80 87 81 88 /** Logged in user ****************************************************/ 82 89 -
bp-members/bp-members-screens.php
diff --git bp-members/bp-members-screens.php bp-members/bp-members-screens.php index 4cb9f40..5cf8b8a 100644
function bp_core_screen_activation() { 251 251 bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug ) ); 252 252 } 253 253 254 // Check for an uploaded avatar and move that to the correct user folder 255 if ( is_multisite() ) 256 $hashed_key = wp_hash( $_GET['key'] ); 257 else 258 $hashed_key = wp_hash( $user ); 254 $hashed_key = wp_hash( $_GET['key'] ); 259 255 260 256 // Check if the avatar folder exists. If it does, move rename it, move 261 257 // it and delete the signup avatar dir -
tests/includes/factory.php
diff --git tests/includes/factory.php tests/includes/factory.php index 317e58d..7c51942 100644
class BP_UnitTest_Factory extends WP_UnitTest_Factory { 10 10 $this->xprofile_group = new BP_UnitTest_Factory_For_XProfileGroup( $this ); 11 11 $this->xprofile_field = new BP_UnitTest_Factory_For_XProfileField( $this ); 12 12 $this->notification = new BP_UnitTest_Factory_For_Notification( $this ); 13 $this->signup = new BP_UnitTest_Factory_For_Signup( $this ); 13 14 } 14 15 } 15 16 … … class BP_UnitTest_Factory_For_Notification extends WP_UnitTest_Factory_For_Thing 163 164 return new BP_Notifications_Notification( $id ); 164 165 } 165 166 } 167 168 class BP_UnitTest_Factory_For_Signup extends WP_UnitTest_Factory_For_Thing { 169 public function __construct( $factory = null ) { 170 parent::__construct( $factory ); 171 } 172 173 public function create_object( $args ) { 174 return BP_Signup::add( $args ); 175 } 176 177 public function update_object( $id, $fields ) {} 178 179 public function get_object_by_id( $id ) { 180 return new BP_Signup( $id ); 181 } 182 } -
tests/includes/install.php
diff --git tests/includes/install.php tests/includes/install.php index 218346f..cecc10f 100644
function wp_test_bp_install( $value ) { 30 30 } 31 31 tests_add_filter( 'bp_new_install_default_components', 'wp_test_bp_install' ); 32 32 33 tests_add_filter( 'bp_get_signup_allowed', '__return_true' ); 34 33 35 $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; 34 36 $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN; 35 37 $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; -
tests/testcases/members/class-bp-signup.php
diff --git tests/testcases/members/class-bp-signup.php tests/testcases/members/class-bp-signup.php index e69de29..6326d1e 100644
1 <?php 2 3 /** 4 * @group members 5 * @group signups 6 * @group BP_Signup 7 */ 8 class BP_Tests_BP_Signup extends BP_UnitTestCase { 9 protected $signup_allowed; 10 11 public function setUp() { 12 13 if ( is_multisite() ) { 14 $this->signup_allowed = get_site_option( 'registration' ); 15 update_site_option( 'registration', 'all' ); 16 } else { 17 bp_get_option( 'users_can_register' ); 18 bp_update_option( 'users_can_register', 1 ); 19 } 20 21 parent::setUp(); 22 } 23 24 public function tearDown() { 25 if ( is_multisite() ) { 26 update_site_option( 'registration', $this->signup_allowed ); 27 } else { 28 bp_update_option( 'users_can_register', $this->signup_allowed ); 29 } 30 31 parent::tearDown(); 32 } 33 34 /** 35 * @group add 36 */ 37 public function test_add() { 38 $time = bp_core_current_time(); 39 $args = array( 40 'domain' => 'foo', 41 'path' => 'bar', 42 'title' => 'Foo bar', 43 'user_login' => 'user1', 44 'user_email' => 'user1@example.com', 45 'registered' => $time, 46 'activation_key' => '12345', 47 'meta' => array( 48 'field_1' => 'Foo Bar', 49 'meta1' => 'meta2', 50 ), 51 ); 52 53 $signup = BP_Signup::add( $args ); 54 $this->assertNotEmpty( $signup ); 55 56 $s = new BP_Signup( $signup ); 57 58 // spot check 59 $this->assertSame( $signup, $s->id ); 60 $this->assertSame( 'user1', $s->user_login ); 61 $this->assertSame( '12345', $s->activation_key ); 62 } 63 64 /** 65 * @group get 66 */ 67 public function test_get_with_offset() { 68 $s1 = $this->factory->signup->create(); 69 $s2 = $this->factory->signup->create(); 70 $s3 = $this->factory->signup->create(); 71 72 $ss = BP_Signup::get( array( 73 'offset' => 1, 74 ) ); 75 76 $this->assertEquals( array( $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 77 } 78 79 /** 80 * @group get 81 */ 82 public function test_get_with_number() { 83 $s1 = $this->factory->signup->create(); 84 $s2 = $this->factory->signup->create(); 85 $s3 = $this->factory->signup->create(); 86 87 $ss = BP_Signup::get( array( 88 'number' => 2, 89 ) ); 90 91 $this->assertEquals( array( $s3, $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 92 } 93 94 /** 95 * @group get 96 */ 97 public function test_get_with_usersearch() { 98 $s1 = $this->factory->signup->create( array( 99 'user_email' => 'fghij@example.com', 100 ) ); 101 $s2 = $this->factory->signup->create(); 102 $s3 = $this->factory->signup->create(); 103 104 $ss = BP_Signup::get( array( 105 'usersearch' => 'ghi', 106 ) ); 107 108 $this->assertEquals( array( $s1 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 109 } 110 111 /** 112 * @group get 113 */ 114 public function test_get_with_orderby_email() { 115 $s1 = $this->factory->signup->create( array( 116 'user_email' => 'fghij@example.com', 117 ) ); 118 $s2 = $this->factory->signup->create( array( 119 'user_email' => 'abcde@example.com', 120 ) ); 121 $s3 = $this->factory->signup->create( array( 122 'user_email' => 'zzzzz@example.com', 123 ) ); 124 125 $ss = BP_Signup::get( array( 126 'orderby' => 'email', 127 'number' => 3, 128 ) ); 129 130 // default order is DESC 131 $this->assertEquals( array( $s3, $s1, $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 132 } 133 134 /** 135 * @group get 136 */ 137 public function test_get_with_orderby_email_asc() { 138 $s1 = $this->factory->signup->create( array( 139 'user_email' => 'fghij@example.com', 140 ) ); 141 $s2 = $this->factory->signup->create( array( 142 'user_email' => 'abcde@example.com', 143 ) ); 144 $s3 = $this->factory->signup->create( array( 145 'user_email' => 'zzzzz@example.com', 146 ) ); 147 148 $ss = BP_Signup::get( array( 149 'orderby' => 'email', 150 'number' => 3, 151 'order' => 'ASC', 152 ) ); 153 154 $this->assertEquals( array( $s2, $s1, $s3 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 155 } 156 157 /** 158 * @group get 159 */ 160 public function test_get_with_include() { 161 $s1 = $this->factory->signup->create(); 162 $s2 = $this->factory->signup->create(); 163 $s3 = $this->factory->signup->create(); 164 165 $ss = BP_Signup::get( array( 166 'include' => array( $s1, $s3 ), 167 ) ); 168 169 $this->assertEquals( array( $s1, $s3 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 170 } 171 172 /** 173 * @group get 174 */ 175 public function test_get_with_activation_key() { 176 $s1 = $this->factory->signup->create( array( 177 'activation_key' => 'foo', 178 ) ); 179 $s2 = $this->factory->signup->create( array( 180 'activation_key' => 'bar', 181 ) ); 182 $s3 = $this->factory->signup->create( array( 183 'activation_key' => 'baz', 184 ) ); 185 186 $ss = BP_Signup::get( array( 187 'activation_key' => 'bar', 188 ) ); 189 190 $this->assertEquals( array( $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 191 } 192 193 /** 194 * @group get 195 */ 196 public function test_get_with_user_login() { 197 $s1 = $this->factory->signup->create( array( 198 'user_login' => 'aaaafoo', 199 ) ); 200 $s2 = $this->factory->signup->create( array( 201 'user_login' => 'zzzzfoo', 202 ) ); 203 $s3 = $this->factory->signup->create( array( 204 'user_login' => 'jjjjfoo', 205 ) ); 206 207 $ss = BP_Signup::get( array( 208 'user_login' => 'zzzzfoo', 209 ) ); 210 211 $this->assertEquals( array( $s2 ), wp_list_pluck( $ss['signups'], 'signup_id' ) ); 212 } 213 } 214 No newline at end of file