Repository navigation
Persist existing translations when introducing new helper text in emails #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4488787
Append the new warning to preserve the existing translations
kasparsd 5a3f5d5
Per linter
kasparsd 1b57aa7
Move into own helper for context
kasparsd 0e1e449
One more linter warning
kasparsd 760b968
Merge remote-tracking branch 'origin/master' into fix-email-format
kasparsd a32355a
Keep the original translation
kasparsd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,6 +234,22 @@ public function delete_token( $user_id ) { | |
| delete_user_meta( $user_id, self::TOKEN_META_KEY ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the client IP address for the current request. | ||
| * | ||
| * Note that the IP address is used only for information purposes | ||
| * and is expected to be configured correctly, if behind proxy. | ||
| * | ||
| * @return string|null | ||
| */ | ||
| private function get_client_ip() { | ||
| if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { // phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders -- don't have more reliable option for now. | ||
| return preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__ -- we're limit the allowed characters. | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Generate and email the user token. | ||
| * | ||
|
|
@@ -244,28 +260,32 @@ public function delete_token( $user_id ) { | |
| */ | ||
| public function generate_and_email_token( $user ) { | ||
| $token = $this->generate_token( $user->ID ); | ||
| $remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); | ||
| $remote_ip = $this->get_client_ip(); | ||
|
|
||
| /* translators: %s: site name */ | ||
| $subject = wp_strip_all_tags( sprintf( __( 'Your login confirmation code for %s', 'two-factor' ), wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); | ||
| $subject = wp_strip_all_tags( | ||
| sprintf( | ||
| /* translators: %s: site name */ | ||
| __( 'Your login confirmation code for %s', 'two-factor' ), | ||
| wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) | ||
| ) | ||
| ); | ||
|
|
||
| $message = wp_strip_all_tags( | ||
| $message_parts = array( | ||
| sprintf( | ||
| /* translators: %1$s: token, $2$s: IP address of user, %3$s: `user_login` of authenticated user */ | ||
| __( | ||
| 'Enter %1$s to log in. | ||
|
|
||
| Didn\'t expect this? | ||
| A user from %2$s has successfully authenticated as %3$s. | ||
| If this wasn\'t you, please change your password.', | ||
| 'two-factor' | ||
| ), | ||
| $token, | ||
| /* translators: %s: token */ | ||
| __( 'Enter %s to log in.', 'two-factor' ), | ||
| $token | ||
| ), | ||
| sprintf( | ||
| /* translators: $1$s: IP address of user, %2$s: `user_login` of authenticated user */ | ||
| __( 'Didn\'t expect this? A user from %1$s has successfully authenticated as %2$s. If this wasn\'t you, please change your password.', 'two-factor' ), | ||
| $remote_ip, | ||
| $user->user_login | ||
| ) | ||
| ), | ||
| ); | ||
|
|
||
| $message = wp_strip_all_tags( implode( "\n\n", $message_parts ) ); | ||
|
|
||
| /** | ||
| * Filter the token email subject. | ||
| * | ||
|
|
@@ -337,7 +357,7 @@ public function authentication_page( $user ) { | |
| * @return boolean | ||
| */ | ||
| public function pre_process_authentication( $user ) { | ||
| if ( isset( $user->ID ) && isset( $_REQUEST[ self::INPUT_NAME_RESEND_CODE ] ) ) { | ||
| if ( isset( $user->ID ) && isset( $_REQUEST[ self::INPUT_NAME_RESEND_CODE ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- non-distructive option that relies on user state. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed the rest of PHPCS warnings for the file. |
||
| $this->generate_and_email_token( $user ); | ||
| return true; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain the expected setup for this and known limitations.