adjust_brightness( $btn_color, -20 ); $text_contrast = $this->get_contrast_color( $bg_color ); // Build the CSS string $custom_css = " /* Custom Background */ body.login { background-color: {$bg_color} !important; } /* Dynamic Text Contrast for Footer Links */ .login #nav a, .login #backtoblog a, .login .privacy-policy-page-link > a { color: {$text_contrast} !important; text-shadow: none !important; transition: opacity 0.3s ease; } .login #nav a:hover, .login #backtoblog a:hover, .login .privacy-policy-page-link > a:hover { opacity: 0.7; color: {$text_contrast} !important; } /* Adjust text color for the separator bullets between links */ .login #nav, .login #backtoblog { color: {$text_contrast} !important; opacity: 0.8; } /* Custom Button */ body.login #wp-submit { background-color: {$btn_color} !important; border-color: {$btn_color} !important; color: #ffffff !important; text-shadow: none !important; box-shadow: none !important; transition: background-color 0.3s ease; } body.login #wp-submit:hover { background-color: {$btn_hover} !important; border-color: {$btn_hover} !important; } /* Clean up the form styling for an agency-grade look */ #loginform { border-radius: 8px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); border: 1px solid #e2e8f0; } "; // Append logo CSS if a custom logo is set if ( $logo_url ) { $custom_css .= " /* Custom Logo */ #login h1 a, .login h1 a { background-image: url({$logo_url}); height: 85px; width: 320px; background-size: contain; background-repeat: no-repeat; background-position: center center; padding-bottom: 30px; } "; } // Securely attach our inline CSS to the native WP login stylesheet handle wp_add_inline_style( 'login', $custom_css ); } /** * Change the logo URL from wordpress.org to the site's home page. * * @return string The home URL. */ public function custom_logo_url() { return home_url(); } /** * Change the logo title attribute from "Powered by WordPress" to the Site Name. * * @return string The site name. */ public function custom_logo_title() { return get_bloginfo( 'name' ); } /** * Calculate whether text should be black or white based on background brightness. * Uses the YIQ formula for visual accessibility. * * @param string $hex The background color. * @return string Hex color for the text (#ffffff or #2c3338). */ private function get_contrast_color( $hex ) { $hex = str_replace( '#', '', $hex ); if ( strlen( $hex ) == 3 ) { $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 ); } if ( ! ctype_xdigit( $hex ) || strlen( $hex ) !== 6 ) { return '#2c3338'; } $r = hexdec( substr( $hex, 0, 2 ) ); $g = hexdec( substr( $hex, 2, 2 ) ); $b = hexdec( substr( $hex, 4, 2 ) ); // YIQ formula based on human eye perception $yiq = ( ( $r * 299 ) + ( $g * 587 ) + ( $b * 114 ) ) / 1000; return ( $yiq >= 128 ) ? '#2c3338' : '#ffffff'; } /** * Utility function to darken or lighten a hex color for hover states dynamically. * * @param string $hex The original hex color. * @param int $steps The amount to adjust (-255 to 255). * @return string The adjusted hex color. */ private function adjust_brightness( $hex, $steps ) { $hex = str_replace( '#', '', $hex ); if ( strlen( $hex ) == 3 ) { $hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 ); } if ( ! ctype_xdigit( $hex ) || strlen( $hex ) !== 6 ) { return '#000000'; } $r = hexdec( substr( $hex, 0, 2 ) ); $g = hexdec( substr( $hex, 2, 2 ) ); $b = hexdec( substr( $hex, 4, 2 ) ); $r = max( 0, min( 255, $r + $steps ) ); $g = max( 0, min( 255, $g + $steps ) ); $b = max( 0, min( 255, $b + $steps ) ); return '#' . str_pad( dechex( $r ), 2, '0', STR_PAD_LEFT ) . str_pad( dechex( $g ), 2, '0', STR_PAD_LEFT ) . str_pad( dechex( $b ), 2, '0', STR_PAD_LEFT ); } }