From 5ec34a3d3be8430997b65eb2a83cca52615dcaf5 Mon Sep 17 00:00:00 2001 From: Anthony Grullon Date: Thu, 1 Feb 2024 10:21:22 -0500 Subject: [PATCH 1/8] Add additional email comment textarea to new user form --- projects/plugins/jetpack/modules/sso.php | 60 +++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index a23cd4a5cfc55..e53ebfefc7e11 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -55,11 +55,13 @@ private function __construct() { add_action( 'jetpack_site_before_disconnected', array( static::class, 'disconnect' ) ); add_action( 'wp_login', array( 'Jetpack_SSO', 'clear_cookies_after_login' ) ); + add_action( 'admin_print_styles-user-new.php', array( $this, 'jetpack_users_new_form_styles' ) ); // If the user has no errors on creation, send an invite to WordPress.com. add_filter( 'user_profile_update_errors', array( $this, 'send_wpcom_mail_user_invite' ), 10, 3 ); // Don't send core invitation email when SSO is activated. They will get an email from WP.com. add_filter( 'wp_send_new_user_notification_to_user', '__return_false' ); add_action( 'user_new_form', array( $this, 'render_invitation_email_message' ) ); + add_action( 'user_new_form', array( $this, 'render_custom_email_message_form_field' ), 1 ); // Adding this action so that on login_init, the action won't be sanitized out of the $action global. add_action( 'login_form_jetpack-sso', '__return_true' ); @@ -367,6 +369,30 @@ public function render_invitation_email_message() { ); } + /** + * Render the custom email message form field for new user registration. + * + * @param string $type The type of new user form the hook follows. + */ + public function render_custom_email_message_form_field( $type ) { + if ( $type === 'add-new-user' ) { + ?> + + + + + +
+ + + +
+ 500 ) { + $errors->add( 'custom_email_message', __( 'Error: The additional email message is too long. Please keep it under 500 characters.', 'jetpack' ) ); + } if ( $errors->has_errors() ) { return $errors; @@ -388,6 +419,15 @@ public function send_wpcom_mail_user_invite( $errors, $update, $user ) { $url = '/sites/' . $blog_id . '/invites/new'; $url = add_query_arg( 'locale', $locale, $url ); + $new_user_request = array( + 'email_or_username' => $email, + 'role' => $role, + ); + + if ( $valid_nonce && isset( $_POST['custom_email_message'] ) ) { + $new_user_request['message'] = sanitize_text_field( wp_unslash( $_POST['custom_email_message'] ) ); + } + $response = Client::wpcom_json_api_request_as_user( $url, '2', // Api version @@ -395,12 +435,7 @@ public function send_wpcom_mail_user_invite( $errors, $update, $user ) { 'method' => 'POST', ), array( - 'invitees' => array( - array( - 'email_or_username' => $email, - 'role' => $role, - ), - ), + 'invitees' => array( $new_user_request ), ) ); @@ -563,6 +598,19 @@ public function jetpack_user_table_styles() { + + Date: Thu, 1 Feb 2024 10:31:53 -0500 Subject: [PATCH 2/8] Update custom message label and rows attribute --- projects/plugins/jetpack/modules/sso.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index e53ebfefc7e11..a5f0c7819351a 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -380,11 +380,11 @@ public function render_custom_email_message_form_field( $type ) { @@ -405,7 +405,7 @@ public function send_wpcom_mail_user_invite( $errors, $update, $user ) { $valid_nonce = isset( $_POST['_wpnonce_create-user'] ) ? wp_verify_nonce( $_POST['_wpnonce_create-user'], 'create-user' ) : false; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WP core doesn't pre-sanitize nonces either. if ( $valid_nonce && ! empty( $_POST['custom_email_message'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['custom_email_message'] ) ) ) > 500 ) { - $errors->add( 'custom_email_message', __( 'Error: The additional email message is too long. Please keep it under 500 characters.', 'jetpack' ) ); + $errors->add( 'custom_email_message', __( 'Error: The custom message is too long. Please keep it under 500 characters.', 'jetpack' ) ); } if ( $errors->has_errors() ) { From ce354013e0d6c9c85c3b5cfd488d0b6c3ac1a0bf Mon Sep 17 00:00:00 2001 From: Anthony Grullon Date: Thu, 1 Feb 2024 10:35:42 -0500 Subject: [PATCH 3/8] Send message if length is greater than 0 --- projects/plugins/jetpack/modules/sso.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index a5f0c7819351a..5719003f744be 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -424,7 +424,7 @@ public function send_wpcom_mail_user_invite( $errors, $update, $user ) { 'role' => $role, ); - if ( $valid_nonce && isset( $_POST['custom_email_message'] ) ) { + if ( $valid_nonce && isset( $_POST['custom_email_message'] ) && strlen( sanitize_text_field( wp_unslash( $_POST['custom_email_message'] ) ) > 0 ) ) { $new_user_request['message'] = sanitize_text_field( wp_unslash( $_POST['custom_email_message'] ) ); } From 2b4bc74b054c413bf00e7816572263238464db0e Mon Sep 17 00:00:00 2001 From: Anthony Grullon Date: Fri, 2 Feb 2024 10:38:26 -0500 Subject: [PATCH 4/8] Reuse jetpack-sso-admin-create-user.css for new user custom message text area --- projects/plugins/jetpack/modules/sso.php | 14 -------------- .../modules/sso/jetpack-sso-admin-create-user.css | 4 ++++ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index 5719003f744be..33ef8aac48f5b 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -55,7 +55,6 @@ private function __construct() { add_action( 'jetpack_site_before_disconnected', array( static::class, 'disconnect' ) ); add_action( 'wp_login', array( 'Jetpack_SSO', 'clear_cookies_after_login' ) ); - add_action( 'admin_print_styles-user-new.php', array( $this, 'jetpack_users_new_form_styles' ) ); // If the user has no errors on creation, send an invite to WordPress.com. add_filter( 'user_profile_update_errors', array( $this, 'send_wpcom_mail_user_invite' ), 10, 3 ); // Don't send core invitation email when SSO is activated. They will get an email from WP.com. @@ -598,19 +597,6 @@ public function jetpack_user_table_styles() { - - Date: Fri, 2 Feb 2024 10:43:54 -0500 Subject: [PATCH 5/8] add changelog --- .../jetpack/changelog/add-new-user-additional-email-message | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/add-new-user-additional-email-message diff --git a/projects/plugins/jetpack/changelog/add-new-user-additional-email-message b/projects/plugins/jetpack/changelog/add-new-user-additional-email-message new file mode 100644 index 0000000000000..88b9200284912 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-new-user-additional-email-message @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Added custom message textarea to send a message via email when adding new users From 49d437c945ac46dcff3bb80d7d75910c32a866b8 Mon Sep 17 00:00:00 2001 From: Anthony Grullon Date: Fri, 2 Feb 2024 11:14:27 -0500 Subject: [PATCH 6/8] Enqueue user-new styling in admin_print_styles-user-new.php hook --- projects/plugins/jetpack/modules/sso.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index 33ef8aac48f5b..bb147383abd8c 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -91,6 +91,7 @@ private function __construct() { } add_filter( 'manage_users_columns', array( $this, 'jetpack_user_connected_th' ) ); add_action( 'admin_print_styles-users.php', array( $this, 'jetpack_user_table_styles' ) ); + add_action( 'admin_print_styles-user-new.php', array( $this, 'jetpack_user_new_form_styles' ) ); add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_connection_status' ), 10, 3 ); add_action( 'admin_post_jetpack_invite_user_to_wpcom', array( $this, 'invite_user_to_wpcom' ) ); add_action( 'admin_post_jetpack_revoke_invite_user_to_wpcom', array( $this, 'revoke_user_invite_to_wpcom' ) ); @@ -340,9 +341,6 @@ public function jetpack_user_table_row_actions( $actions, $user_object ) { * Render the invitation email message. */ public function render_invitation_email_message() { - // Enqueue the CSS for the admin create user page. - wp_enqueue_style( 'jetpack-sso-admin-create-user', plugins_url( 'modules/sso/jetpack-sso-admin-create-user.css', JETPACK__PLUGIN_FILE ), array(), time() ); - $message = wp_kses( __( 'New users will receive an invite to join WordPress.com, so they can log in securely using Secure Sign On.', @@ -597,6 +595,14 @@ public function jetpack_user_table_styles() { Date: Fri, 2 Feb 2024 12:25:21 -0500 Subject: [PATCH 7/8] Add placeholder for custom message field --- projects/plugins/jetpack/modules/sso.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index bb147383abd8c..fbefe3d26ed09 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -381,7 +381,12 @@ public function render_custom_email_message_form_field( $type ) { From 52f8a2b169eeb6198a60bd3dcd5601728d138cf8 Mon Sep 17 00:00:00 2001 From: Omar Alshaker Date: Mon, 5 Feb 2024 13:30:37 +0100 Subject: [PATCH 8/8] Move out of the placeholder --- projects/plugins/jetpack/modules/sso.php | 7 +++---- .../jetpack/modules/sso/jetpack-sso-admin-create-user.css | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/projects/plugins/jetpack/modules/sso.php b/projects/plugins/jetpack/modules/sso.php index fbefe3d26ed09..5b56617e5ac6b 100644 --- a/projects/plugins/jetpack/modules/sso.php +++ b/projects/plugins/jetpack/modules/sso.php @@ -381,11 +381,10 @@ public function render_custom_email_message_form_field( $type ) { diff --git a/projects/plugins/jetpack/modules/sso/jetpack-sso-admin-create-user.css b/projects/plugins/jetpack/modules/sso/jetpack-sso-admin-create-user.css index 6bf9645457506..48fb994f2328d 100644 --- a/projects/plugins/jetpack/modules/sso/jetpack-sso-admin-create-user.css +++ b/projects/plugins/jetpack/modules/sso/jetpack-sso-admin-create-user.css @@ -13,3 +13,9 @@ #createuser .form-field textarea { width: 25em; } + +#custom_email_message_description { + max-width: 25rem; + color: #646970; + font-size: 12px; +} \ No newline at end of file
- +