` tag on `login_head` and always overrides the * link/title with no way to turn either off), this adds the logo CSS as * a proper inline style on core's own `login` stylesheet handle, and * lets the link/title overrides be switched off independently of the * logo image itself. */ final class Feature { /** * Hook everything. * * @return void */ public function register(): void { add_action( 'login_enqueue_scripts', array( $this, 'maybe_enqueue_logo_style' ) ); add_filter( 'login_headerurl', array( $this, 'maybe_filter_header_url' ) ); add_filter( 'login_headertext', array( $this, 'maybe_filter_header_text' ) ); } /** * Add the logo's background-image/height as an inline style on core's * own `login` stylesheet handle. * * @return void */ public function maybe_enqueue_logo_style(): void { if ( ! $this->is_enabled() ) { return; } $image_id = absint( aiou_get_setting( 'login', 'login_logo', 'image_id', 0 ) ); if ( ! $image_id ) { return; } $url = wp_get_attachment_image_url( $image_id, 'full' ); if ( ! $url ) { return; } $height = absint( aiou_get_setting( 'login', 'login_logo', 'height', 84 ) ); $height = $height > 0 ? $height : 84; wp_add_inline_style( 'login', sprintf( '.login h1.wp-login-logo a { background-image: url("%s"); background-size: contain; width: 100%%; height: %dpx; }', esc_url( $url ), $height ) ); } /** * Point the logo link at this site instead of WordPress.org. * * @param string $url Login header URL. * @return string */ public function maybe_filter_header_url( string $url ): string { if ( ! $this->is_enabled() || ! aiou_get_setting( 'login', 'login_logo', 'link_url', 0 ) ) { return $url; } return home_url( '/' ); } /** * Use the site's name as the logo's title text instead of "Powered by * WordPress". * * @param string $text Login header text. * @return string */ public function maybe_filter_header_text( string $text ): string { if ( ! $this->is_enabled() || ! aiou_get_setting( 'login', 'login_logo', 'link_title', 0 ) ) { return $text; } return get_bloginfo( 'name' ); } /** * Whether the feature is on at all. * * @return bool */ private function is_enabled(): bool { return (bool) aiou_get_setting( 'login', 'login_logo', 'enabled', 0 ); } }