settings(); self::register_tab( $settings ); $this->register_preview( $settings ); $this->register_background( $settings ); $this->register_elements( $settings ); $this->register_texts( $settings ); ( new Background() )->register(); ( new Texts() )->register(); ( new Elements() )->register(); } /** * Register the tab (first registration wins, so the Login Logo module * can call this too, whichever boots first). * * @param SettingsRegistry $settings The settings registry. * @return void */ public static function register_tab( SettingsRegistry $settings ): void { $settings->add_tab( self::TAB, __( 'Login Page', 'all-in-one-utilities' ), __( 'Customize wp-login.php: the logo, background, every label, button, and message on the login, registration, and password screens, and which links are shown.', 'all-in-one-utilities' ), 27 ); } /** * The "Preview login page" button. * * @param SettingsRegistry $settings The settings registry. * @return void */ private function register_preview( SettingsRegistry $settings ): void { $settings->add_section( self::TAB, 'login_preview', __( 'Preview', 'all-in-one-utilities' ), __( 'Save your changes, then open the login page in a new tab to see them. You stay logged in -- WordPress still shows the login form.', 'all-in-one-utilities' ), 1 ); $screens = array( 'login' => __( 'Login', 'all-in-one-utilities' ), 'register' => __( 'Registration', 'all-in-one-utilities' ), 'lostpassword' => __( 'Lost password', 'all-in-one-utilities' ), ); $priority = 10; foreach ( $screens as $action => $label ) { $settings->add_field( self::TAB, 'login_preview', new Field( id: 'preview_' . $action, label: $label, type: 'button_link', default: '', args: array( 'url' => 'login' === $action ? wp_login_url() : add_query_arg( 'action', $action, wp_login_url() ), 'button_label' => __( 'Open preview', 'all-in-one-utilities' ), 'new_tab' => true, ), priority: $priority ) ); $priority += 10; } } /** * Background. * * @param SettingsRegistry $settings The settings registry. * @return void */ private function register_background( SettingsRegistry $settings ): void { $settings->add_section( self::TAB, Background::SECTION, __( 'Background', 'all-in-one-utilities' ), __( 'Give the login page your own background color or image.', 'all-in-one-utilities' ), 12 ); $settings->add_field( self::TAB, Background::SECTION, new Field( id: 'color', label: __( 'Background color', 'all-in-one-utilities' ), type: 'color', default: '', args: array( 'description' => __( 'Leave empty for WordPress\'s light gray.', 'all-in-one-utilities' ) ), priority: 10 ) ); $settings->add_field( self::TAB, Background::SECTION, new Field( id: 'image', label: __( 'Background image', 'all-in-one-utilities' ), type: 'media', default: 0, args: array( 'description' => __( 'Shown behind the login form. A large, calm image (1920 pixels wide or more) works best.', 'all-in-one-utilities' ) ), priority: 20 ) ); $settings->add_field( self::TAB, Background::SECTION, new Field( id: 'style', label: __( 'Image layout', 'all-in-one-utilities' ), type: 'select', default: 'cover', args: array( 'choices' => Background::style_choices() ), priority: 30 ) ); } /** * Elements & Behavior. * * @param SettingsRegistry $settings The settings registry. * @return void */ private function register_elements( SettingsRegistry $settings ): void { $section = 'login_elements'; $settings->add_section( self::TAB, $section, __( 'Elements & Behavior', 'all-in-one-utilities' ), __( 'Choose what the login page shows and where users go after logging in or out.', 'all-in-one-utilities' ), 20 ); $fields = array( new Field( id: 'page_title', label: __( 'Browser tab title', 'all-in-one-utilities' ), type: 'text', default: '', args: array( 'placeholder' => __( 'Log In ‹ {site_name} — WordPress', 'all-in-one-utilities' ), 'description' => __( 'Leave empty for WordPress\'s own title. {site_name} is replaced with your site name.', 'all-in-one-utilities' ), ), priority: 10 ), new Field( id: 'login_message', label: __( 'Message above the login form', 'all-in-one-utilities' ), type: 'textarea', default: '', args: array( 'rows' => 3, 'description' => __( 'For example, a welcome note or support contact. Shown on the login screen only; leave empty for none.', 'all-in-one-utilities' ), ), priority: 20 ), new Field( id: 'hide_back_to_site', label: __( '"Go to site" link', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Hide the "← Go to site" link', 'all-in-one-utilities' ) ), priority: 30 ), new Field( id: 'hide_lost_password_link', label: __( '"Lost your password?" link', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Hide the "Lost your password?" link', 'all-in-one-utilities' ) ), priority: 40 ), new Field( id: 'hide_register_link', label: __( '"Register" link', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Hide the "Register" link', 'all-in-one-utilities' ) ), doc: new Doc( title: __( 'Hiding the "Register" link', 'all-in-one-utilities' ), short: __( 'Only hides the link. To stop people registering, untick "Anyone can register" in Settings → General.', 'all-in-one-utilities' ) ), priority: 50 ), new Field( id: 'hide_privacy_link', label: __( 'Privacy policy link', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Hide the privacy policy link', 'all-in-one-utilities' ) ), priority: 60 ), new Field( id: 'hide_language_switcher', label: __( 'Language switcher', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Hide the language dropdown', 'all-in-one-utilities' ) ), priority: 70 ), new Field( id: 'remember_me_checked', label: __( '"Remember Me"', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Tick "Remember Me" by default', 'all-in-one-utilities' ) ), priority: 80 ), new Field( id: 'login_redirect', label: __( 'After logging in, go to', 'all-in-one-utilities' ), type: 'text', default: '', args: array( 'placeholder' => admin_url(), 'description' => __( 'A page on this site. Leave empty for WordPress\'s default (the dashboard, or the page the user was trying to open).', 'all-in-one-utilities' ), ), sanitize: static fn( $value ): string => esc_url_raw( trim( (string) $value ) ), priority: 90 ), new Field( id: 'logout_redirect', label: __( 'After logging out, go to', 'all-in-one-utilities' ), type: 'text', default: '', args: array( 'placeholder' => home_url( '/' ), 'description' => __( 'A page on this site. Leave empty to show the login page again.', 'all-in-one-utilities' ), ), sanitize: static fn( $value ): string => esc_url_raw( trim( (string) $value ) ), priority: 100 ), ); foreach ( $fields as $field ) { $settings->add_field( self::TAB, $section, $field ); } } /** * One section per wp-login.php screen, plus the shared links. * * @param SettingsRegistry $settings The settings registry. * @return void */ private function register_texts( SettingsRegistry $settings ): void { $priority = 30; foreach ( Texts::definitions() as $section => $definition ) { $settings->add_section( self::TAB, $section, $definition['label'], $definition['description'], $priority ); $priority += 10; $field_priority = 10; foreach ( $definition['fields'] as $field_id => $field ) { $settings->add_field( self::TAB, $section, new Field( id: $field_id, label: $field[2], type: 'text', default: '', args: array( 'placeholder' => self::wordpress_default( $field[0], $field[1] ), 'description' => 'back_to_site' === $field_id ? __( 'Use {site_name} for your site name.', 'all-in-one-utilities' ) : '', ), priority: $field_priority ) ); $field_priority += 10; } } } /** * WordPress's own wording for a string, in the site's language, for * use as a field placeholder. * * @param string $text Original English string. * @param string|null $context Gettext context. * @return string */ private static function wordpress_default( string $text, ?string $context ): string { // phpcs:disable WordPress.WP.I18n -- deliberately looking up core's own strings (domain 'default') by their msgid, to show what each field replaces. $translated = null === $context ? translate( $text, 'default' ) : translate_with_gettext_context( $text, $context, 'default' ); // phpcs:enable return str_replace( '%s', '{site_name}', html_entity_decode( $translated, ENT_QUOTES, 'UTF-8' ) ); } }