'defer', 'in_footer' => true, ] ); $color = (string) Plugin::opt( 'color' ); if ( preg_match( '/^#[0-9a-fA-F]{6}$/', $color ) ) { wp_add_inline_style( 'admirly', ':root{--admirly-color:' . $color . ';--admirly-dark:' . self::mix( $color, '#000000', 0.28 ) . ';--admirly-light:' . self::mix( $color, '#ffffff', 0.9 ) . ';--admirly-line:' . self::mix( $color, '#e6e6e6', 0.82 ) . '}' ); } } public function enqueueIfNeeded(): void { if ( self::$needed ) { self::enqueue(); } } /** Mixes $hex with $with by $ratio (0 = hex, 1 = with). */ public static function mix( string $hex, string $with, float $ratio ): string { $h = sscanf( ltrim( $hex, '#' ), '%02x%02x%02x' ); $w = sscanf( ltrim( $with, '#' ), '%02x%02x%02x' ); if ( ! $h || ! $w ) { return $hex; } $out = '#'; for ( $i = 0; $i < 3; $i++ ) { $out .= str_pad( dechex( (int) round( $h[ $i ] * ( 1 - $ratio ) + $w[ $i ] * $ratio ) ), 2, '0', STR_PAD_LEFT ); } return $out; } private static function enqueue(): void { wp_enqueue_style( 'admirly' ); if ( is_rtl() ) { wp_enqueue_style( 'admirly-rtl' ); } wp_enqueue_script( 'admirly' ); /** Fires once the plugin's front-end assets are enqueued; extensions enqueue theirs here. */ do_action( 'admirly_enqueue_assets' ); } }