1 | <?php |
---|
2 | /** |
---|
3 | * The new registration Template |
---|
4 | * |
---|
5 | * @package wporg-login |
---|
6 | */ |
---|
7 | |
---|
8 | $user_login = isset( $_POST['user_login'] ) ? trim( wp_unslash( $_POST['user_login'] ) ) : ''; |
---|
9 | $user_email = isset( $_POST['user_email'] ) ? trim( wp_unslash( $_POST['user_email'] ) ) : ''; |
---|
10 | $user_mailinglist = isset( $_POST['user_mailinglist'] ) && 'true' == $_POST['user_mailinglist']; |
---|
11 | $terms_of_service = isset( $_POST['terms_of_service'] ) ? $_POST['terms_of_service'] : false; |
---|
12 | |
---|
13 | if ( ! $user_login && ! empty( WP_WPOrg_SSO::$matched_route_params['user'] ) ) { |
---|
14 | $user_login = trim( WP_WPOrg_SSO::$matched_route_params['user'] ); |
---|
15 | } |
---|
16 | |
---|
17 | // Already logged in.. Warn about duplicate accounts, etc. |
---|
18 | if ( is_user_logged_in() ) { |
---|
19 | wp_safe_redirect( home_url( '/linkexpired/register-logged-in' ) ); |
---|
20 | exit; |
---|
21 | } |
---|
22 | |
---|
23 | $error_user_login = $error_user_email = $error_recapcha_status = $terms_of_service_error = false; |
---|
24 | if ( $_POST ) { |
---|
25 | |
---|
26 | /** This filter is documented in wp-includes/user.php */ |
---|
27 | $user_login = apply_filters( 'pre_user_login', $user_login ); |
---|
28 | |
---|
29 | /** This filter is documented in wp-includes/user.php */ |
---|
30 | $user_email = apply_filters( 'pre_user_email', $user_email ); |
---|
31 | |
---|
32 | $error_user_login = rest_do_request( new WP_REST_Request( 'GET', '/wporg/v1/username-available/' . urlencode( $user_login ) ) ); |
---|
33 | if ( $error_user_login->get_data()['available'] ) { |
---|
34 | $error_user_login = false; |
---|
35 | } |
---|
36 | |
---|
37 | $error_user_email = rest_do_request( new WP_REST_Request( 'GET', '/wporg/v1/email-in-use/' . urlencode( $user_email ) ) ); |
---|
38 | if ( $error_user_email->get_data()['available'] ) { |
---|
39 | $error_user_email = false; |
---|
40 | } |
---|
41 | |
---|
42 | // Don't validate that it's equal to the current revision, just that they've agreed to one. |
---|
43 | // Let the post-login interstitial handle TOS updates at time of registration. |
---|
44 | $terms_of_service_error = ! $terms_of_service || $terms_of_service > TOS_REVISION; |
---|
45 | |
---|
46 | // handle user registrations. |
---|
47 | if ( ! $error_user_login && ! $error_user_email && ! $terms_of_service_error ) { |
---|
48 | |
---|
49 | $recaptcha = wporg_login_check_recapcha_status( 'register', false /* Allow low scores to pass through */ ); |
---|
50 | |
---|
51 | if ( ! $recaptcha ) { |
---|
52 | $error_recapcha_status = true; |
---|
53 | } else { |
---|
54 | $tos_meta_key = WPOrg_SSO::TOS_USER_META_KEY; |
---|
55 | $meta = [ |
---|
56 | 'user_mailinglist' => $user_mailinglist, |
---|
57 | $tos_meta_key => $terms_of_service, |
---|
58 | ]; |
---|
59 | |
---|
60 | wporg_login_create_pending_user( $user_login, $user_email, $meta ); |
---|
61 | die(); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | wp_enqueue_script( 'wporg-registration' ); |
---|
68 | |
---|
69 | get_header(); |
---|
70 | ?> |
---|
71 | |
---|
72 | <p class="intro"><?php _e( 'Create a WordPress.org account to start contributing to WordPress, get help in the support forums, or rate and review themes and plugins.', 'wporg' ); ?></p> |
---|
73 | |
---|
74 | <form name="registerform" id="registerform" action="/register" method="post"> |
---|
75 | |
---|
76 | <p class="login-username"> |
---|
77 | <label for="user_login"><?php _e( 'Username', 'wporg' ); ?></label> |
---|
78 | <input type="text" name="user_login" id="user_login" class="input <?php if ( $error_user_login ) echo 'error'; ?>" value="<?php echo esc_attr( $user_login ) ?>" size="20" maxlength="60" /> |
---|
79 | <span class="small"><?php _e( 'Only lower case letters (a-z) and numbers (0-9) are allowed.', 'wporg' ); ?></span> |
---|
80 | </p> |
---|
81 | <?php |
---|
82 | if ( $error_user_login ) { |
---|
83 | printf( |
---|
84 | '<div class="message error%s"><p>%s<span>%s</span></p></div>', |
---|
85 | $error_user_login->get_data()['avatar'] ? ' with-avatar' : '', |
---|
86 | $error_user_login->get_data()['avatar'], |
---|
87 | $error_user_login->get_data()['error'] |
---|
88 | ); |
---|
89 | } |
---|
90 | ?> |
---|
91 | |
---|
92 | <p class="login-email"> |
---|
93 | <label for="user_email"><?php _e( 'Email', 'wporg' ); ?></label> |
---|
94 | <input type="email" name="user_email" id="user_email" class="input <?php if ( $error_user_email ) echo 'error'; ?>" value="<?php echo esc_attr( $user_email ) ?>" size="20" maxlength="100" /> |
---|
95 | <span class="small"><?php _e( 'A link to set your password will be sent here.', 'wporg' ); ?></span> |
---|
96 | </p> |
---|
97 | <?php |
---|
98 | if ( $error_user_email ) { |
---|
99 | printf( |
---|
100 | '<div class="message error%s"><p>%s<span>%s</span></p></div>', |
---|
101 | $error_user_email->get_data()['avatar'] ? ' with-avatar' : '', |
---|
102 | $error_user_email->get_data()['avatar'], |
---|
103 | $error_user_email->get_data()['error'] |
---|
104 | ); |
---|
105 | } |
---|
106 | ?> |
---|
107 | |
---|
108 | <p class="login-tos checkbox <?php if ( $terms_of_service_error ) { echo 'message error'; } ?>"> |
---|
109 | <label for="terms_of_service"> |
---|
110 | <input name="terms_of_service" type="checkbox" id="terms_of_service" value="<?php echo esc_attr( TOS_REVISION ); ?>" <?php checked( $terms_of_service, TOS_REVISION ); ?> required="required"> |
---|
111 | <?php |
---|
112 | $localised_domain = parse_url( wporg_login_wordpress_url(), PHP_URL_HOST ); |
---|
113 | printf( |
---|
114 | /* translators: %s: List of linked policies, for example: <a>Privacy Policy</a> and <a>Terms of Service</a> */ |
---|
115 | _n( 'I have read and accept the %s.', 'I have read and accept the %s.', 1, 'wporg' ), |
---|
116 | wp_sprintf_l( '%l', [ |
---|
117 | "<a href='https://{$localised_domain}/about/privacy/'>" . __( 'Privacy Policy', 'wporg' ) . '</a>', |
---|
118 | // "<a href='https://{$localised_domain}/about/terms-of-service/'>" . __( 'Terms of Service', 'wporg' ) . '</a>', |
---|
119 | // "<a href='https://{$localised_domain}/about/code-of-conduct/'>" . __( 'Code of Conduct', 'wporg' ) . '</a>', |
---|
120 | ] ) |
---|
121 | ) |
---|
122 | ?> |
---|
123 | </label> |
---|
124 | </p> |
---|
125 | |
---|
126 | <p class="login-mailinglist checkbox"> |
---|
127 | <label for="user_mailinglist"> |
---|
128 | <input name="user_mailinglist" type="checkbox" id="user_mailinglist" value="true" <?php checked( $user_mailinglist, true ); ?>> |
---|
129 | <?php _e( 'Subscribe to WordPress Announcements mailing list (a few messages a year)', 'wporg' ); ?> |
---|
130 | </label> |
---|
131 | </p> |
---|
132 | <?php |
---|
133 | if ( $error_recapcha_status ) { |
---|
134 | echo '<div class="message error"><p>' . __( 'Please try again.', 'wporg' ) . '</p></div>'; |
---|
135 | } |
---|
136 | ?> |
---|
137 | |
---|
138 | <p class="login-submit"> |
---|
139 | <input data-sitekey="<?php echo esc_attr( RECAPTCHA_INVIS_PUBKEY ); ?>" data-callback='onSubmit' type="submit" name="wp-submit" id="wp-submit" class="g-recaptcha button button-primary button-large" value="<?php esc_attr_e( 'Create Account', 'wporg' ); ?>" /> |
---|
140 | </p> |
---|
141 | |
---|
142 | </form> |
---|
143 | |
---|
144 | <p id="nav"> |
---|
145 | <a href="/" title="<?php esc_attr_e( 'Already have an account?', 'wporg' ); ?>"><?php _e( 'Already have an account?', 'wporg' ); ?></a> • |
---|
146 | <a href="<?php echo wporg_login_wordpress_url(); ?>"><?php _e( 'WordPress.org', 'wporg' ); ?></a> |
---|
147 | </p> |
---|
148 | |
---|
149 | <?php get_footer(); |
---|