__( 'Start here', 'aiolos-checkout-for-woocommerce' ), 'callback' => array( self::class, 'render' ), 'group' => 'setup', ); return $tabs; } /** * Where the checkout stands: off, test (shop managers only) or live. */ public static function state(): string { if ( ! Settings::enabled( 'checkout_enabled' ) ) { return 'off'; } return Settings::enabled( 'checkout_admins_only' ) ? 'test' : 'live'; } /** * A sentence about the state. * * @param string $state State. */ private static function state_text( string $state ): string { switch ( $state ) { case 'off': return __( 'The checkout is off: customers see WooCommerce\'s own checkout page.', 'aiolos-checkout-for-woocommerce' ); case 'test': return __( 'Test mode: only you and other shop managers see the new checkout. Customers keep the old one until you go live.', 'aiolos-checkout-for-woocommerce' ); default: return __( 'Live: customers see the new checkout.', 'aiolos-checkout-for-woocommerce' ); } } /** * WCAG contrast ratio of two colors (1–21). * * @param string $a Hex color. * @param string $b Hex color. */ public static function contrast( string $a, string $b ): float { $luminance = static function ( string $hex ): float { $hex = ltrim( $hex, '#' ); if ( 3 === strlen( $hex ) ) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } if ( ! preg_match( '/^[0-9a-f]{6}$/i', $hex ) ) { return 1.0; } $channel = static function ( string $part ): float { $c = hexdec( $part ) / 255; return $c <= 0.03928 ? $c / 12.92 : ( ( $c + 0.055 ) / 1.055 ) ** 2.4; }; return 0.2126 * $channel( substr( $hex, 0, 2 ) ) + 0.7152 * $channel( substr( $hex, 2, 2 ) ) + 0.0722 * $channel( substr( $hex, 4, 2 ) ); }; $l1 = $luminance( $a ); $l2 = $luminance( $b ); return round( ( max( $l1, $l2 ) + 0.05 ) / ( min( $l1, $l2 ) + 0.05 ), 2 ); } /** * The screen. */ public static function render(): void { $state = self::state(); $primary = (string) Settings::get( 'color_primary', '#2b4bff' ); $text = (string) Settings::get( 'color_button_text', '#ffffff' ); $ratio = self::contrast( $primary, $text ); $has_logo = absint( Settings::get( 'logo_id' ) ) > 0; $mode_url = admin_url( 'admin-post.php' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. $failed = isset( $_GET['aiolos-preview-failed'] ); ?>
id ) { return; } $state = self::state(); $class = 'live' === $state ? 'notice-success' : 'notice-info'; ?>