Ticket #5374: 5374.05.patch
File 5374.05.patch, 84.5 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..5168a48 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 // Use WP's core CREATE TABLE query 371 $create_queries = wp_get_db_schema( 'ms_global' ); 372 373 if ( ! is_array( $create_queries ) ) { 374 $create_queries = explode( ';', $create_queries ); 375 $create_queries = array_filter( $create_queries ); 376 } 377 378 // Filter out all the queries except wp_signups 379 foreach ( $create_queries as $key => $query ) { 380 if ( preg_match( "|CREATE TABLE ([^ ]*)|", $query, $matches ) ) { 381 if ( $wpdb->signups != trim( $matches[1], '`' ) ) { 382 unset( $create_queries[ $key ] ); 383 } 384 } 385 } 386 387 if ( ! empty( $create_queries ) ) { 388 dbDelta( $create_queries ); 389 } 390 } -
bp-core/bp-core-update.php
diff --git bp-core/bp-core-update.php bp-core/bp-core-update.php index 9ca5922..28b6939 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 } -
new file p-members/admin/bp-members-classes.php
diff --git bp-members/admin/bp-members-classes.php bp-members/admin/bp-members-classes.php new file mode 100644 index 0000000..c58c4c6
- + 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 // Don't show the Email link if a resend has happened within 263 // the last 24 hours 264 $now = current_time( 'timestamp', true ); 265 $sent_at = mysql2date('U', $signup_object->date_sent ); 266 $diff = $now - $sent_at; 267 268 if ( $diff > 1 * DAY_IN_SECONDS ) { 269 $actions['resend'] = '<a href="' . esc_url( $email_link ) . '">' . __( 'Email', 'buddypress' ) . '</a>'; 270 } 271 272 if ( current_user_can( 'delete_users' ) ) { 273 $actions['delete'] = '<a href="' . esc_url( $delete_link ) . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>'; 274 } 275 276 $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object ); 277 echo $this->row_actions( $actions ); 278 } 279 280 /** 281 * Display user name, if any. 282 * 283 * @since BuddyPress (2.0.0) 284 * 285 * @param object $signup_object The signup data object. 286 */ 287 public function column_name( $signup_object = null ) { 288 echo esc_html( $signup_object->user_name ); 289 } 290 291 /** 292 * Display user email. 293 * 294 * @since BuddyPress (2.0.0) 295 * 296 * @param object $signup_object The signup data object. 297 */ 298 public function column_email( $signup_object = null ) { 299 echo '<a href="mailto:' . esc_attr( $signup_object->user_email ) . '">' . esc_html( $signup_object->user_email ) .'</a>'; 300 } 301 302 /** 303 * Display registration date. 304 * 305 * @since BuddyPress (2.0.0) 306 * 307 * @param object $signup_object The signup data object. 308 */ 309 public function column_registered( $signup_object = null ) { 310 echo mysql2date( 'Y/m/d', $signup_object->registered ); 311 } 312 313 /** 314 * Display the last time an activation email has been sent. 315 * 316 * @since BuddyPress (2.0.0) 317 * 318 * @param object $signup_object The signup data object. 319 */ 320 public function column_date_sent( $signup_object = null ) { 321 echo mysql2date( 'Y/m/d', $signup_object->date_sent ); 322 } 323 324 /** 325 * Display number of time an activation email has been sent. 326 * 327 * @since BuddyPress (2.0.0) 328 */ 329 public function column_count_sent( $signup_object = null ) { 330 echo absint( $signup_object->count_sent ); 331 } 332 } 333 334 endif; 335 336 if ( class_exists( 'WP_MS_Users_List_Table' ) ) : 337 /** 338 * List table class for signups network admin page. 339 * 340 * @since BuddyPress (2.0.0) 341 */ 342 class BP_Members_MS_List_Table extends WP_MS_Users_List_Table { 343 344 /** 345 * Signup counts. 346 * 347 * @since BuddyPress (2.0.0) 348 * 349 * @access public 350 * @var int 351 */ 352 public $signup_counts = 0; 353 354 /** 355 * Constructor 356 * 357 * @since BuddyPress (2.0.0) 358 */ 359 public function __construct() { 360 // Define singular and plural labels, as well as whether we support AJAX. 361 parent::__construct( array( 362 'ajax' => false, 363 'plural' => 'signups', 364 'singular' => 'signup', 365 ) ); 366 } 367 368 /** 369 * Set up items for display in the list table. 370 * 371 * Handles filtering of data, sorting, pagination, and any other data 372 * manipulation required prior to rendering. 373 * 374 * @since BuddyPress (2.0.0) 375 */ 376 public function prepare_items() { 377 global $usersearch, $wpdb, $mode; 378 379 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 380 381 $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 382 383 $paged = $this->get_pagenum(); 384 385 $args = array( 386 'offset' => ( $paged - 1 ) * $signups_per_page, 387 'number' => $signups_per_page, 388 'usersearch' => $usersearch, 389 'orderby' => 'signup_id', 390 'order' => 'DESC' 391 ); 392 393 if ( isset( $_REQUEST['orderby'] ) ) 394 $args['orderby'] = $_REQUEST['orderby']; 395 396 if ( isset( $_REQUEST['order'] ) ) 397 $args['order'] = $_REQUEST['order']; 398 399 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; 400 401 $signups = BP_Signup::get( $args ); 402 403 $this->items = $signups['signups']; 404 $this->signup_counts = $signups['total']; 405 406 $this->set_pagination_args( array( 407 'total_items' => $this->signup_counts, 408 'per_page' => $signups_per_page, 409 ) ); 410 } 411 412 /** 413 * Get the views : the links above the WP List Table. 414 * 415 * @since BuddyPress (2.0.0) 416 * 417 * @uses WP_MS_Users_List_Table::get_views() to get the users views 418 */ 419 function get_views() { 420 $views = parent::get_views(); 421 422 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 423 $class = ' class="current"'; 424 425 $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>'; 426 427 return $views; 428 } 429 430 /** 431 * Specific signups columns 432 * 433 * @since BuddyPress (2.0.0) 434 */ 435 public function get_columns() { 436 return apply_filters( 'bp_members_ms_signup_columns', array( 437 'cb' => '<input type="checkbox" />', 438 'username' => __( 'Username', 'buddypress' ), 439 'name' => __( 'Name', 'buddypress' ), 440 'email' => __( 'E-mail', 'buddypress' ), 441 'registered' => __( 'Registered', 'buddypress' ), 442 'date_sent' => __( 'Last mail', 'buddypress' ), 443 'count_sent' => __( '# Times Resent', 'buddypress' ) 444 ) ); 445 } 446 447 /** 448 * Specific bulk actions for signups 449 * 450 * @since BuddyPress (2.0.0) 451 */ 452 public function get_bulk_actions() { 453 $actions = array( 454 'activate' => _x( 'Activate', 'Pending signup action', 'buddypress' ), 455 'resend' => _x( 'Email', 'Pending signup action', 'buddypress' ), 456 ); 457 458 if ( current_user_can( 'delete_users' ) ) { 459 $actions['delete'] = __( 'Delete' ); 460 } 461 462 return $actions; 463 } 464 465 /** 466 * The text shown when no items are found. 467 * 468 * Nice job, clean sheet! 469 * 470 * @since BuddyPress (2.0.0) 471 */ 472 public function no_items() { 473 _e( 'No pending accounts found.', 'buddypress' ); 474 } 475 476 /** 477 * The columns signups can be reordered with 478 * 479 * @since BuddyPress (2.0.0) 480 */ 481 public function get_sortable_columns() { 482 return array( 483 'username' => 'login', 484 'email' => 'email', 485 'registered' => 'signup_id', 486 ); 487 } 488 489 /** 490 * Display signups rows. 491 * 492 * @since BuddyPress (2.0.0) 493 */ 494 public function display_rows() { 495 $style = ''; 496 foreach ( $this->items as $userid => $signup_object ) { 497 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 498 echo "\n\t" . $this->single_row( $signup_object, $style ); 499 } 500 } 501 502 /** 503 * Display a signup row. 504 * 505 * @since BuddyPress (2.0.0) 506 * 507 * @see WP_List_Table::single_row() for explanation of params. 508 */ 509 public function single_row( $signup_object = null, $style = '' ) { 510 echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">'; 511 echo $this->single_row_columns( $signup_object ); 512 echo '</tr>'; 513 } 514 515 /** 516 * Markup for the checkbox used to select items for bulk actions. 517 * 518 * @since BuddyPress (2.0.0) 519 */ 520 public function column_cb( $signup_object = null ) { 521 ?> 522 <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> 523 <input type="checkbox" id="signup_<?php echo intval( $signup_object->id ) ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" /> 524 <?php 525 } 526 527 /** 528 * The row actions (delete/activate/email). 529 * 530 * @since BuddyPress (2.0.0) 531 * 532 * @param object $signup_object The signup data object. 533 */ 534 public function column_username( $signup_object = null ) { 535 $avatar = get_avatar( $signup_object->user_email, 32 ); 536 537 // Activation email link 538 $email_link = add_query_arg( 539 array( 540 'page' => 'bp-signups', 541 'signup_id' => $signup_object->id, 542 'action' => 'resend', 543 ), 544 bp_get_admin_url( 'users.php' ) 545 ); 546 547 // Activate link 548 $activate_link = add_query_arg( 549 array( 550 'page' => 'bp-signups', 551 'signup_id' => $signup_object->id, 552 'action' => 'activate', 553 ), 554 bp_get_admin_url( 'users.php' ) 555 ); 556 557 // Delete link 558 $delete_link = add_query_arg( 559 array( 560 'page' => 'bp-signups', 561 'signup_id' => $signup_object->id, 562 'action' => 'delete', 563 ), 564 bp_get_admin_url( 'users.php' ) 565 ); 566 567 echo $avatar . '<strong><a href="' . esc_url( $activate_link ) .'" class="edit" title="' . esc_attr__( 'Activate', 'buddypress' ) . '">' . $signup_object->user_login .'</a></strong><br/>'; 568 569 $actions['activate'] = '<a href="' . esc_url( $activate_link ) . '">' . __( 'Activate', 'buddypress' ) . '</a>'; 570 571 // Don't show the Email link if a resend has happened within 572 // the last 24 hours 573 $now = current_time( 'timestamp', true ); 574 $sent_at = mysql2date('U', $signup_object->date_sent ); 575 $diff = $now - $sent_at; 576 577 if ( $diff > 1 * DAY_IN_SECONDS ) { 578 $actions['resend'] = '<a href="' . esc_url( $email_link ) . '">' . __( 'Email', 'buddypress' ) . '</a>'; 579 } 580 581 if ( current_user_can( 'delete_users' ) ) { 582 $actions['delete'] = '<a href="' . esc_url( $delete_link ) . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>'; 583 } 584 585 $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object ); 586 echo $this->row_actions( $actions ); 587 } 588 589 /** 590 * Display user name, if any. 591 * 592 * @since BuddyPress (2.0.0) 593 * 594 * @param object $signup_object The signup data object. 595 */ 596 public function column_name( $signup_object = null ) { 597 echo esc_html( $signup_object->user_name ); 598 } 599 600 /** 601 * Display user email. 602 * 603 * @since BuddyPress (2.0.0) 604 * 605 * @param object $signup_object The signup data object. 606 */ 607 public function column_email( $signup_object = null ) { 608 echo '<a href="mailto:' . esc_attr( $signup_object->user_email ) . '">' . esc_html( $signup_object->user_email ) .'</a>'; 609 } 610 611 /** 612 * Display registration date 613 * 614 * @since BuddyPress (2.0.0) 615 * 616 * @param object $signup_object The signup data object. 617 */ 618 public function column_registered( $signup_object = null ) { 619 global $mode; 620 621 if ( 'list' == $mode ) { 622 $date = 'Y/m/d'; 623 } else { 624 $date = 'Y/m/d \<\b\r \/\> g:i:s a'; 625 } 626 627 echo mysql2date( $date, $signup_object->registered ) . "</td>"; 628 } 629 630 /** 631 * Display the last time an activation email has been sent. 632 * 633 * @since BuddyPress (2.0.0) 634 */ 635 public function column_date_sent( $signup_object = null ) { 636 global $mode; 637 638 if ( 'list' == $mode ) { 639 $date = 'Y/m/d'; 640 } else { 641 $date = 'Y/m/d \<\b\r \/\> g:i:s a'; 642 } 643 644 echo mysql2date( $date, $signup_object->date_sent ); 645 } 646 647 /** 648 * Display number of time an activation email has been sent. 649 * 650 * @since BuddyPress (2.0.0) 651 */ 652 public function column_count_sent( $signup_object = null ) { 653 echo absint( $signup_object->count_sent ); 654 } 655 } 656 657 endif; -
bp-members/bp-members-admin.php
diff --git bp-members/bp-members-admin.php bp-members/bp-members-admin.php index bbbc927..9b4c129 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 } 181 208 182 209 } 183 210 184 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 } 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' ); 242 } 243 244 /** Community Profile ************************************************/ 245 246 /** 185 247 * Add some specific styling to the Edit User and Edit User's Profile page. 186 248 * 187 249 * @access public … … 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( $_GET['allsignups'] ) ) { 1288 $ids = wp_parse_id_list( $_GET['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 <li><?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?></li> 1352 <?php endforeach; ?> 1353 </ol> 1354 1355 <?php if ( 'resend' != $action ) : ?> 1356 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p> 1357 <?php endif ; ?> 1358 1359 <a class="button-primary" href="<?php echo esc_url( $action_url ); ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a> 1360 <a class="button" href="<?php echo esc_url( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a> 1361 </div> 1362 1363 <?php 1364 } 694 1365 } 695 1366 endif; // class_exists check 696 1367 -
new file p-members/bp-members-classes.php
diff --git bp-members/bp-members-classes.php bp-members/bp-members-classes.php new file mode 100644 index 0000000..0d4661c
- + 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 foreach ( (array) $paged_signups as $key => $signup ) { 186 187 $signup->id = intval( $signup->signup_id ); 188 189 $signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false; 190 191 $signup->user_name = ''; 192 if ( ! empty( $signup->meta['field_1'] ) ) { 193 $signup->user_name = wp_unslash( $signup->meta['field_1'] ); 194 } 195 196 // Sent date defaults to date of registration 197 if ( ! empty( $signup->meta['sent_date'] ) ) { 198 $signup->date_sent = $signup->meta['sent_date']; 199 } else { 200 $signup->date_sent = $signup->registered; 201 } 202 203 if ( ! empty( $signup->meta['count_sent'] ) ) { 204 $signup->count_sent = absint( $signup->meta['count_sent'] ); 205 } else { 206 $signup->count_sent = 1; 207 } 208 209 $paged_signups[ $key ] = $signup; 210 } 211 212 unset( $sql['limit'] ); 213 $sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] ); 214 $total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) ); 215 216 return array( 'signups' => $paged_signups, 'total' => $total_signups ); 217 } 218 219 /** 220 * Add a signup. 221 * 222 * @since BuddyPress (2.0.0) 223 * 224 * @param array $args 225 * @return int|bool ID of newly created signup on success, false on 226 * failure. 227 */ 228 public static function add( $args = array() ) { 229 global $wpdb; 230 231 $r = bp_parse_args( $args, 232 array( 233 'domain' => '', 234 'path' => '', 235 'title' => '', 236 'user_login' => '', 237 'user_email' => '', 238 'registered' => current_time( 'mysql', true ), 239 'activation_key' => '', 240 'meta' => '', 241 ), 242 'bp_core_signups_add_args' 243 ); 244 245 $r['meta'] = maybe_serialize( $r['meta'] ); 246 247 $inserted = $wpdb->insert( 248 buddypress()->members->table_name_signups, 249 $r, 250 array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) 251 ); 252 253 if ( $inserted ) { 254 $retval = $wpdb->insert_id; 255 } else { 256 $retval = false; 257 } 258 259 return apply_filters( 'bp_core_signups_add', $retval ); 260 } 261 262 /** 263 * Create a WP user at signup. 264 * 265 * Since BP 2.0, non-multisite configurations have stored signups in 266 * the same way as Multisite configs traditionally have: in the 267 * wp_signups table. However, because some plugins may be looking 268 * directly in the wp_users table for non-activated signups, we 269 * mirror signups there by creating "phantom" users, mimicking WP's 270 * default behavior. 271 * 272 * @since BuddyPress (2.0.0) 273 * 274 * @param string $user_login User login string. 275 * @param string $user_password User password. 276 * @param string $user_email User email address. 277 * @param array $usermeta Metadata associated with the signup. 278 * @return int User id. 279 */ 280 public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) { 281 global $wpdb; 282 283 $errors = new WP_Error(); 284 285 $user_id = wp_insert_user( array( 286 'user_login' => $user_login, 287 'user_pass' => $user_password, 288 'display_name' => sanitize_title( $user_login ), 289 'user_email' => $user_email 290 ) ); 291 292 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 293 $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' ) ) ); 294 return $errors; 295 } 296 297 // Update the user status to '2', ie "not activated" 298 // (0 = active, 1 = spam, 2 = not active) 299 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) ); 300 301 // WordPress creates these options automatically on 302 // wp_insert_user(), but we delete them so that inactive 303 // signups don't appear in various user counts. 304 delete_user_option( $user_id, 'capabilities' ); 305 delete_user_option( $user_id, 'user_level' ); 306 307 // Set any profile data 308 if ( bp_is_active( 'xprofile' ) ) { 309 if ( ! empty( $usermeta['profile_field_ids'] ) ) { 310 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); 311 312 foreach ( (array) $profile_field_ids as $field_id ) { 313 if ( empty( $usermeta["field_{$field_id}"] ) ) { 314 continue; 315 } 316 317 $current_field = $usermeta["field_{$field_id}"]; 318 xprofile_set_field_data( $field_id, $user_id, $current_field ); 319 320 // Save the visibility level 321 $visibility_level = ! empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public'; 322 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 323 } 324 } 325 } 326 327 return apply_filters( 'bp_core_signups_add_backcompat', $user_id ); 328 } 329 330 /** 331 * Check a user status (from wp_users) on a non-multisite config. 332 * 333 * @since BuddyPress (2.0.0) 334 * 335 * @param int $user_id ID of the user being checked. 336 * @return int|bool The status if found, otherwise false. 337 */ 338 public static function check_user_status( $user_id = 0 ) { 339 global $wpdb; 340 341 if ( empty( $user_id ) ) 342 return false; 343 344 $user_status = $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id ) ); 345 346 return apply_filters( 'bp_core_signups_check_user_status', intval( $user_status ) ); 347 } 348 349 /** 350 * Activate a signup. 351 * 352 * @since BuddyPress (2.0.0) 353 * 354 * @param string $key Activation key. 355 * @return bool True on success, false on failure. 356 */ 357 public static function validate( $key = '' ) { 358 global $wpdb; 359 360 if ( empty( $key ) ) { 361 return; 362 } 363 364 $activated = $wpdb->update( 365 // Signups table 366 buddypress()->members->table_name_signups, 367 array( 368 'active' => 1, 369 'activated' => current_time( 'mysql', true ), 370 ), 371 array( 372 'activation_key' => $key, 373 ), 374 // Data sanitization format 375 array( 376 '%d', 377 '%s', 378 ), 379 // WHERE sanitization format 380 array( 381 '%s', 382 ) 383 ); 384 385 return apply_filters( 'bp_core_signups_validate', $activated ); 386 } 387 388 /** 389 * How many inactive signups do we have? 390 * 391 * @since BuddyPress (2.0.0) 392 * 393 * @return int the number of signups 394 */ 395 public static function count_signups() { 396 global $wpdb; 397 398 $signups_table = buddypress()->members->table_name_signups; 399 $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) ); 400 401 return apply_filters( 'bp_core_signups_count', (int) $count_signups ); 402 } 403 404 /** 405 * Update the meta for a signup. 406 * 407 * This is the way we use to "trace" the last date an activation 408 * email was sent and how many times activation was sent. 409 * 410 * @since BuddyPress (2.0.0) 411 * 412 * @param array $args 413 * @return int the signup id 414 */ 415 public static function update( $args = array() ) { 416 global $wpdb; 417 418 $r = bp_parse_args( $args, 419 array( 420 'signup_id' => 0, 421 'meta' => array(), 422 ), 423 'bp_core_signups_update_args' 424 ); 425 426 if ( empty( $r['signup_id'] ) || empty( $r['meta'] ) ) { 427 return false; 428 } 429 430 $wpdb->update( 431 // Signups table 432 buddypress()->members->table_name_signups, 433 // Data to update 434 array( 435 'meta' => serialize( $r['meta'] ), 436 ), 437 // WHERE 438 array( 439 'signup_id' => $r['signup_id'], 440 ), 441 // Data sanitization format 442 array( 443 '%s', 444 ), 445 // WHERE sanitization format 446 array( 447 '%d', 448 ) 449 ); 450 451 return apply_filters( 'bp_core_signups_update', $r['signup_id'] ); 452 } 453 454 /** 455 * Resend an activation email. 456 * 457 * @since BuddyPress (2.0.0) 458 * 459 * @param array $signup_ids single id or list of ids to resend 460 * @return array the results 461 */ 462 public static function resend( $signup_ids = array() ) { 463 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) { 464 return false; 465 } 466 467 $to_resend = self::get( array( 468 'include' => $signup_ids, 469 ) ); 470 471 if ( ! $signups = $to_resend['signups'] ) { 472 return false; 473 } 474 475 $now = current_time( 'timestamp', true ); 476 $result = array(); 477 478 do_action( 'bp_core_signup_before_resend', $signup_ids ); 479 480 foreach ( $signups as $signup ) { 481 $sent_at = mysql2date( 'U', $signup->date_sent ); 482 $diff = $now - $sent_at; 483 484 // If a previous resent happened less than a day ago, skip. 485 if ( $diff < 1 * DAY_IN_SECONDS ) { 486 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'Received an activation email in the last 24 hours.', 'buddypress' ) );; 487 continue; 488 } 489 490 $meta['sent_date'] = current_time( 'mysql', true ); 491 $meta['count_sent'] = $signup->count_sent + 1; 492 493 // Send activation email 494 if ( is_multisite() ) { 495 wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) ); 496 } else { 497 498 // Check user status before sending email 499 $user_id = email_exists( $signup->user_email ); 500 501 if ( ! empty( $user_id ) && 2 != self::check_user_status( $user_id ) ) { 502 // Status is not 2, so user's account has been activated 503 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );; 504 // repare signups table 505 self::validate( $signup->activation_key ); 506 continue; 507 508 // Send the validation email 509 } else { 510 bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key ); 511 } 512 } 513 514 // Update metas 515 $result['resent'][] = self::update( array( 516 'signup_id' => $signup->signup_id, 517 'meta' => $meta, 518 ) ); 519 } 520 521 do_action( 'bp_core_signup_after_resend', $signup_ids, $result ); 522 523 return apply_filters( 'bp_core_signup_resend', $result ); 524 } 525 526 /** 527 * Activate a pending account. 528 * 529 * @since BuddyPress (2.0.0) 530 * 531 * @param array $signup_ids Single id or list of ids to resend. 532 * @return array the results 533 */ 534 public static function activate( $signup_ids = array() ) { 535 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) { 536 return false; 537 } 538 539 $to_activate = self::get( array( 540 'include' => $signup_ids, 541 ) ); 542 543 if ( ! $signups = $to_activate['signups'] ) { 544 return false; 545 } 546 547 $result = array(); 548 549 do_action( 'bp_core_signup_before_activate', $signup_ids ); 550 551 foreach ( $signups as $signup ) { 552 553 $user = bp_core_activate_signup( $signup->activation_key ); 554 555 if ( ! empty( $user->errors ) ) { 556 557 if ( $user_id = username_exists( $signup->user_login ) && 2 != self::check_user_status( $user_id ) ) { 558 // Status is not 2, so user's account has been activated 559 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) ); 560 // repare signups table 561 self::validate( $signup->activation_key ); 562 563 // we have a user id, account is not active, let's delete it 564 } else { 565 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() ); 566 } 567 568 } else { 569 $result['activated'][] = $user; 570 } 571 } 572 573 do_action( 'bp_core_signup_after_activate', $signup_ids, $result ); 574 575 return apply_filters( 'bp_core_signup_activate', $result ); 576 } 577 578 /** 579 * Delete a pending account. 580 * 581 * @since BuddyPress (2.0.0) 582 * 583 * @param array $signup_ids single id or list of ids to resend 584 * @return array the results 585 */ 586 public static function delete( $signup_ids = array() ) { 587 global $wpdb; 588 589 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) { 590 return false; 591 } 592 593 $to_delete = self::get( array( 594 'include' => $signup_ids, 595 ) ); 596 597 if ( ! $signups = $to_delete['signups'] ) { 598 return false; 599 } 600 601 $result = array(); 602 603 do_action( 'bp_core_signup_before_delete', $signup_ids ); 604 605 foreach ( $signups as $signup ) { 606 $user_id = username_exists( $signup->user_login ); 607 608 if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) { 609 610 if ( 2 != self::check_user_status( $user_id ) ) { 611 // Status is not 2, so user's account has been activated 612 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) ); 613 // repare signups table 614 self::validate( $signup->activation_key ); 615 616 // we have a user id, account is not active, let's delete it 617 } else { 618 bp_core_delete_account( $user_id ); 619 } 620 } 621 622 if ( empty( $result['errors'][ $signup->signup_id ] ) ) { 623 $wpdb->delete( 624 // Signups table 625 buddypress()->members->table_name_signups, 626 // Where 627 array( 'signup_id' => $signup->signup_id, ), 628 // WHERE sanitization format 629 array( '%d', ) 630 ); 631 632 $result['deleted'][] = $signup->signup_id; 633 } 634 } 635 636 do_action( 'bp_core_signup_after_delete', $signup_ids, $result ); 637 638 return apply_filters( 'bp_core_signup_delete', $result ); 639 } 640 } -
bp-members/bp-members-functions.php
diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php index 9212f9b..8a873cc 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( $signup['signups'] ) && ! empty( $signups['signups'][0] ) ? $signup['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'; -
new file tests/testcases/members/class-bp-signup.php
diff --git tests/testcases/members/class-bp-signup.php tests/testcases/members/class-bp-signup.php new file mode 100644 index 0000000..c66e2dd
- + 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 }