field id => [ original string, gettext context|null, label ]. * `screens` lists which wp-login.php screens a section applies to. * * @return array}> */ public static function definitions(): array { return array( 'login_texts' => array( 'label' => __( 'Login Form Texts', 'all-in-one-utilities' ), 'description' => __( 'The main "Log In" screen. Leave a field empty to keep WordPress\'s wording.', 'all-in-one-utilities' ), 'screens' => array( 'login' ), 'fields' => array( 'username_label' => array( 'Username or Email Address', null, __( 'Username label', 'all-in-one-utilities' ) ), 'password_label' => array( 'Password', null, __( 'Password label', 'all-in-one-utilities' ) ), 'remember_label' => array( 'Remember Me', null, __( '"Remember Me" label', 'all-in-one-utilities' ) ), 'login_button' => array( 'Log In', null, __( 'Log in button', 'all-in-one-utilities' ) ), 'register_link' => array( 'Register', null, __( '"Register" link', 'all-in-one-utilities' ) ), ), ), 'register_texts' => array( 'label' => __( 'Registration Form Texts', 'all-in-one-utilities' ), 'description' => __( 'The "Register" screen, shown when Settings → General → Membership allows anyone to register.', 'all-in-one-utilities' ), 'screens' => array( 'register' ), 'fields' => array( 'register_message' => array( 'Register For This Site', null, __( 'Message above the form', 'all-in-one-utilities' ) ), 'username_label' => array( 'Username', null, __( 'Username label', 'all-in-one-utilities' ) ), 'email_label' => array( 'Email', null, __( 'Email label', 'all-in-one-utilities' ) ), 'confirmation' => array( 'Registration confirmation will be emailed to you.', null, __( 'Confirmation note', 'all-in-one-utilities' ) ), 'register_button' => array( 'Register', null, __( 'Register button', 'all-in-one-utilities' ) ), ), ), 'lostpassword_texts' => array( 'label' => __( 'Lost Password Form Texts', 'all-in-one-utilities' ), 'description' => __( 'The screen where users ask for a password reset link.', 'all-in-one-utilities' ), 'screens' => array( 'lostpassword' ), 'fields' => array( 'instructions' => array( 'Please enter your username or email address. You will receive an email message with instructions on how to reset your password.', null, __( 'Instructions', 'all-in-one-utilities' ) ), 'username_label' => array( 'Username or Email Address', null, __( 'Username label', 'all-in-one-utilities' ) ), 'submit_button' => array( 'Get New Password', null, __( 'Submit button', 'all-in-one-utilities' ) ), 'register_link' => array( 'Register', null, __( '"Register" link', 'all-in-one-utilities' ) ), ), ), 'resetpass_texts' => array( 'label' => __( 'Reset Password Form Texts', 'all-in-one-utilities' ), 'description' => __( 'The screen reached from the reset link in the email, where users choose a new password.', 'all-in-one-utilities' ), 'screens' => array( 'resetpass' ), 'fields' => array( 'instructions' => array( 'Enter your new password below or generate one.', null, __( 'Instructions', 'all-in-one-utilities' ) ), 'password_label' => array( 'New password', null, __( 'New password label', 'all-in-one-utilities' ) ), 'generate_button' => array( 'Generate Password', null, __( 'Generate button', 'all-in-one-utilities' ) ), 'save_button' => array( 'Save Password', null, __( 'Save button', 'all-in-one-utilities' ) ), 'register_link' => array( 'Register', null, __( '"Register" link', 'all-in-one-utilities' ) ), ), ), 'shared_texts' => array( 'label' => __( 'Texts on Every Screen', 'all-in-one-utilities' ), 'description' => __( 'Links shown below the form on all of the screens above.', 'all-in-one-utilities' ), 'screens' => array( 'login', 'register', 'lostpassword', 'resetpass' ), 'fields' => array( 'back_to_site' => array( '← Go to %s', 'site', __( '"Go to site" link', 'all-in-one-utilities' ) ), 'login_link' => array( 'Log in', null, __( '"Log in" link (on the other screens)', 'all-in-one-utilities' ) ), 'lost_link' => array( 'Lost your password?', null, __( '"Lost your password?" link', 'all-in-one-utilities' ) ), ), ), ); } /** * Replacements for this request, keyed "context|original". * * @var array */ private array $map = array(); /** * Hook the replacement for the current wp-login.php screen. * * @return void */ public function register(): void { add_action( 'login_init', array( $this, 'boot' ) ); } /** * Build this screen's map and start filtering. * * @return void */ public function boot(): void { $screen = self::current_screen(); foreach ( self::definitions() as $section => $definition ) { if ( ! in_array( $screen, $definition['screens'], true ) ) { continue; } foreach ( $definition['fields'] as $field_id => $field ) { $custom = trim( (string) aiou_get_setting( 'login', $section, $field_id, '' ) ); if ( '' === $custom ) { continue; } if ( 'back_to_site' === $field_id ) { // Core runs this through sprintf() with the site name. $custom = str_replace( array( '%', '{site_name}' ), array( '%%', '%s' ), $custom ); } $this->map[ (string) $field[1] . '|' . $field[0] ] = $custom; } } if ( $this->map ) { add_filter( 'gettext', array( $this, 'filter' ), 10, 3 ); add_filter( 'gettext_with_context', array( $this, 'filter_with_context' ), 10, 4 ); } } /** * Replace a core string. * * @param string $translation Translated text. * @param string $text Original text. * @param string $domain Text domain. * @return string */ public function filter( $translation, $text, $domain ) { return 'default' === $domain ? ( $this->map[ '|' . $text ] ?? $translation ) : $translation; } /** * Replace a core string that has a context. * * @param string $translation Translated text. * @param string $text Original text. * @param string $context Context. * @param string $domain Text domain. * @return string */ public function filter_with_context( $translation, $text, $context, $domain ) { return 'default' === $domain ? ( $this->map[ $context . '|' . $text ] ?? $translation ) : $translation; } /** * Which wp-login.php screen this is: login, register, lostpassword, or resetpass. * * @return string */ public static function current_screen(): string { $action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : 'login'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen detection, same as wp-login.php itself. $aliases = array( 'retrievepassword' => 'lostpassword', 'rp' => 'resetpass', ); $action = $aliases[ $action ] ?? $action; return in_array( $action, array( 'register', 'lostpassword', 'resetpass' ), true ) ? $action : 'login'; } }