Changeset 10029 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-restapi.php
- Timestamp:
- 07/07/2020 08:02:03 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions-restapi.php
r9146 r10029 19 19 'callback' => 'wporg_login_rest_email_in_use' 20 20 ) ); 21 22 register_rest_route( 'wporg/v1', '/resend-confirmation-email/?', array( 23 'methods' => WP_REST_Server::EDITABLE, 24 'callback' => 'wporg_login_rest_resend_confirmation_email' 25 ) ); 21 26 } 22 27 add_action( 'rest_api_init', 'wporg_login_rest_routes' ); … … 31 36 return [ 32 37 'available' => false, 33 'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' . __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ), 38 'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' . 39 __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ), 34 40 'avatar' => get_avatar( $user, 64 ), 35 41 ]; … … 40 46 return [ 41 47 'available' => false, 42 'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' . __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ), 48 'error' => __( 'That username is already in use.', 'wporg' ) . '<br>' . 49 __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ) . '<br>' . 50 '<a href="#" class="resend">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>', 43 51 'avatar' => get_avatar( $pending->user_email, 64 ), 44 52 ]; … … 65 73 return [ 66 74 'available' => false, 67 'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' . __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ), 75 'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' . 76 __( 'Is it yours? <a href="/lostpassword">Reset your password</a>.', 'wporg' ), 68 77 'avatar' => get_avatar( $user, 64 ), 69 78 ]; … … 74 83 return [ 75 84 'available' => false, 76 'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' . __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ), 85 'error' => __( 'That email address already has an account.', 'wporg' ) . '<br>' . 86 __( 'The registration is still pending, please check your email for the confirmation link.', 'wporg' ) . '<br>' . 87 '<a href="#" class="resend">' . __( 'Resend confirmation email.', 'wporg' ) . '</a>', 77 88 'avatar' => get_avatar( $email, 64 ), 78 89 ]; … … 91 102 return [ 'available' => true ]; 92 103 } 104 105 /* 106 * Resend a confirmation email to create an account. 107 * 108 * This API intentionally doesn't report if it performs the action, always returning the success message. 109 */ 110 function wporg_login_rest_resend_confirmation_email( $request ) { 111 $account = $request['account']; 112 113 $success_message = sprintf( 114 __( 'Please check your email %s for a confirmation link to set your password.', 'wporg' ), 115 '<code>' . esc_html( $account ) . '</code>' 116 ); 117 118 $pending_user = wporg_get_pending_user( $request['account'] ); 119 if ( ! $pending_user || $pending_user['created'] ) { 120 return $success_message; 121 } 122 123 // Allow for w.org plugins to block the action. 124 if ( null !== ( $pre_register_error = apply_filters( 'wporg_login_pre_registration', null, $pending_user['user_login'], $pending_user['user_email'], $pending_user['meta']['user_mailinglist'] ) ) ) { 125 return $success_message; 126 } 127 128 // Only one email per.. 129 // - 1 minute for brand new accounts (<15min) 130 // - 5 minutes for new accounts (<1hr) 131 // - 3 hours there after 132 list( $requested_time, ) = explode( ':', $pending_user['user_activation_key'] ); 133 $time_limit = 3 * HOUR_IN_SECONDS; 134 135 if ( time() - strtotime( $pending_user['user_registered'] ) < HOUR_IN_SECONDS ) { 136 $time_limit = 5 * MINUTE_IN_SECONDS; 137 } 138 139 if ( time() - strtotime( $pending_user['user_registered'] ) < 15 * MINUTE_IN_SECONDS ) { 140 $time_limit = MINUTE_IN_SECONDS; 141 } 142 143 if ( ( time() - $requested_time ) < $time_limit ) { 144 return $success_message; 145 } 146 147 wporg_login_send_confirmation_email( $pending_user ); 148 149 return $success_message; 150 }
Note: See TracChangeset
for help on using the changeset viewer.