tabs from the settings schema; the Pro add-on adds its tabs (License, * Rewards…) through `aiolos_settings_fields` and `aiolos_admin_tabs`. */ final class Admin { public const PAGE = 'aiolos-checkout'; public const CAPABILITY = 'manage_woocommerce'; /** * Hooks. */ public static function init(): void { add_action( 'admin_menu', array( self::class, 'menu' ) ); add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue' ) ); add_action( 'admin_post_aiolos_save_settings', array( self::class, 'save' ) ); add_action( 'admin_post_aiolos_use_classic_checkout', array( self::class, 'use_classic_checkout' ) ); add_action( 'admin_notices', array( self::class, 'notices' ) ); add_filter( 'plugin_action_links_' . plugin_basename( AIOLOS_CHECKOUT_FILE ), array( self::class, 'action_links' ) ); add_filter( 'admin_footer_text', array( self::class, 'footer_credit' ) ); Onboarding::init(); } /** * "Aiolos Checkout by AiolosWeb" at the bottom of this screen (admin only). * * @param string $text Footer text. */ public static function footer_credit( $text ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || 'toplevel_page_' . self::PAGE !== $screen->id ) { return $text; } return sprintf( /* translators: %s: link to AiolosWeb */ esc_html__( 'Aiolos Checkout by %s', 'aiolos-checkout-for-woocommerce' ), 'AiolosWeb' ); } /** * URL of the screen. * * @param string $tab Tab. */ public static function url( string $tab = '' ): string { return admin_url( 'admin.php?page=' . self::PAGE . ( '' !== $tab ? '&tab=' . rawurlencode( $tab ) : '' ) ); } /** * Menu entry. */ public static function menu(): void { add_menu_page( __( 'Aiolos Checkout', 'aiolos-checkout-for-woocommerce' ), __( 'Aiolos Checkout', 'aiolos-checkout-for-woocommerce' ), self::CAPABILITY, self::PAGE, array( self::class, 'render' ), 'data:image/svg+xml;base64,' . base64_encode( self::menu_icon() ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 56 ); } /** * The menu icon: the brand's bag with the check cut out, in one colour, so WordPress paints it * in the admin colour scheme (grey, white on hover, the scheme's accent when current). */ public static function menu_icon(): string { return ''; } /** * The brand mark in the screen's header: a white bag with a check on the brand gradient. */ private static function mark(): string { return ''; } /** * Settings link on the Plugins screen. * * @param array $links Links. */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'aiolos-checkout-for-woocommerce' ) . '' ); return $links; } /** * The tabs: key => [ label, callback or null for schema tabs ]. * * @return array */ public static function tabs(): array { $tabs = array(); foreach ( Settings::fields() as $key => $tab ) { $tabs[ $key ] = array( 'label' => (string) ( $tab['label'] ?? $key ), 'callback' => null, ); // A tab may name its navigation group (see groups()). if ( ! empty( $tab['group'] ) && is_string( $tab['group'] ) ) { $tabs[ $key ]['group'] = $tab['group']; } } // Without Pro: what it adds, as tabs that describe it (the Pro tabs take their place once it is active). if ( ! defined( 'ACWP_VERSION' ) ) { foreach ( self::pro_features() as $key => $feature ) { if ( ! isset( $tabs[ $key ] ) ) { $tabs[ $key ] = array( 'label' => $feature['label'], 'callback' => static function () use ( $feature ) { self::render_pro_feature( $feature ); }, 'pro' => true, ); } } } /** * Filters the tabs of the settings screen. A tab with a callback prints its own content. * * @since 1.0.0 * * @param array $tabs key => [ 'label' => string, 'callback' => callable|null, 'group' => string (optional) ]. */ return (array) apply_filters( 'aiolos_admin_tabs', $tabs ); } /** * The current tab. */ private static function current_tab(): string { $tabs = self::tabs(); $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- navigation only. return isset( $tabs[ $tab ] ) ? $tab : (string) key( $tabs ); } /** * Admin assets, on this screen only. * * @param string $hook Screen hook. */ public static function enqueue( $hook ): void { if ( 'toplevel_page_' . self::PAGE !== $hook ) { return; } wp_enqueue_media(); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'aiolos-admin', Plugin::asset( 'css/admin.css' ), array(), Plugin::asset_version( 'css/admin.css' ) ); wp_enqueue_script( 'aiolos-admin', Plugin::asset( 'js/admin.js' ), array( 'jquery', 'wp-color-picker' ), Plugin::asset_version( 'js/admin.js' ), true ); wp_localize_script( 'aiolos-admin', 'aiolosAdmin', array( 'chooseLogo' => __( 'Choose a logo', 'aiolos-checkout-for-woocommerce' ), 'useImage' => __( 'Use this image', 'aiolos-checkout-for-woocommerce' ), // The fallback without a chosen logo: the site's logo or name. 'siteLogo' => wp_kses( \AiolosCheckout\Checkout\Checkout::logo_html( false ), \AiolosCheckout\Checkout\Checkout::logo_allowed_html() ), 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'search' => self::search_index(), 'i18n' => array( 'noResults' => __( 'No setting matches.', 'aiolos-checkout-for-woocommerce' ), /* translators: %d: number of settings found */ 'results' => __( 'Settings found: %d', 'aiolos-checkout-for-woocommerce' ), 'copied' => __( 'Copied.', 'aiolos-checkout-for-woocommerce' ), 'copyFailed' => __( 'Select the text and copy it yourself (Ctrl+C).', 'aiolos-checkout-for-woocommerce' ), /* translators: %s: tab name */ 'confirmReset' => __( 'Put every setting of "%s" back to its default? This cannot be undone.', 'aiolos-checkout-for-woocommerce' ), 'confirmImport' => __( 'Import these settings? The tabs in the file replace the same tabs here.', 'aiolos-checkout-for-woocommerce' ), ), ) ); } /** * What the settings search looks through: every tab and every field, with its tab and section. * * @return array */ private static function search_index(): array { $index = array(); $tabs = self::tabs(); foreach ( $tabs as $key => $tab ) { $index[] = array( 'tab' => (string) $key, 'tabLabel' => (string) ( $tab['label'] ?? $key ), 'section' => '', 'label' => (string) ( $tab['label'] ?? $key ), 'text' => '', 'url' => self::url( (string) $key ), ); } foreach ( Settings::fields() as $tab_key => $tab ) { if ( ! isset( $tabs[ $tab_key ] ) ) { continue; } foreach ( (array) ( $tab['sections'] ?? array() ) as $section ) { foreach ( (array) ( $section['fields'] ?? array() ) as $key => $field ) { $index[] = array( 'tab' => (string) $tab_key, 'tabLabel' => (string) ( $tabs[ $tab_key ]['label'] ?? $tab_key ), 'section' => (string) ( $section['label'] ?? '' ), 'label' => (string) ( $field['label'] ?? $key ), // Descriptions are searched too, cut short to keep the page light. 'text' => wp_html_excerpt( (string) ( $field['description'] ?? '' ), 220 ), 'url' => self::url( (string) $tab_key ) . '#acw-row-' . rawurlencode( (string) $key ), ); } } } return $index; } /** * The screen. */ public static function render(): void { if ( ! current_user_can( self::CAPABILITY ) ) { wp_die( esc_html__( 'You are not allowed to change these settings.', 'aiolos-checkout-for-woocommerce' ) ); } $tabs = self::tabs(); $current = self::current_tab(); $schema = Settings::fields(); $state = Onboarding::state(); $problems = \AiolosCheckout\Tools\Health::problems(); $status = array( 'live' => __( 'Checkout is live', 'aiolos-checkout-for-woocommerce' ), 'test' => __( 'Test mode', 'aiolos-checkout-for-woocommerce' ), 'off' => __( 'Checkout is off', 'aiolos-checkout-for-woocommerce' ), ); ?>


$field ) : ?>
*/ private static function pro_features(): array { return array( 'invoices' => array( 'label' => __( 'Invoices', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Invoices with tax number checks', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'An "I need an invoice" choice, with the tax number named as each country names it and confirmed by its register.', 'aiolos-checkout-for-woocommerce' ), 'points' => array( __( 'VIES for the EU, AADE for Greece, HMRC, the UID and Brønnøysund registers', 'aiolos-checkout-for-woocommerce' ), __( 'Company name and registered office filled in from the register', 'aiolos-checkout-for-woocommerce' ), __( 'Optional EU reverse charge', 'aiolos-checkout-for-woocommerce' ), ), ), 'rules' => array( 'label' => __( 'Payment & shipping', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Payment and shipping rules', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'A fee or a discount per payment method, and methods hidden by cart value, country, shipping method or category.', 'aiolos-checkout-for-woocommerce' ), 'points' => array( __( 'Cash on delivery fee, bank transfer discount', 'aiolos-checkout-for-woocommerce' ), __( 'Hide payment or shipping methods by rule', 'aiolos-checkout-for-woocommerce' ), ), ), 'delivery' => array( 'label' => __( 'Delivery date', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Delivery date and time slots', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'Customers pick a day and a time slot under the shipping methods.', 'aiolos-checkout-for-woocommerce' ), 'points' => array( __( 'Preparation days, cut-off time and closed dates', 'aiolos-checkout-for-woocommerce' ), __( 'A limit of orders per day or slot', 'aiolos-checkout-for-woocommerce' ), ), ), 'bumps' => array( 'label' => __( 'Order bumps', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Order bumps', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'One-click offers before payment, at a special price, shown only when the cart matches.', 'aiolos-checkout-for-woocommerce' ), 'points' => array( __( 'Conditions by product, category and cart value', 'aiolos-checkout-for-woocommerce' ), __( 'Their revenue in the checkout analytics', 'aiolos-checkout-for-woocommerce' ), ), ), 'post_purchase' => array( 'label' => __( 'After purchase', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Offers after the order', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'One click on the thank-you page adds a product at a special price.', 'aiolos-checkout-for-woocommerce' ), 'points' => array( __( 'Into the same order with cash on delivery or bank transfer', 'aiolos-checkout-for-woocommerce' ), __( 'A linked order to pay with other methods', 'aiolos-checkout-for-woocommerce' ), ), ), 'recovery' => array( 'label' => __( 'Cart recovery', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Cart recovery', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'Reminder emails with a link that puts the cart back, with consent and unsubscribe.', 'aiolos-checkout-for-woocommerce' ), 'points' => array( __( 'Up to three emails and a single-use discount code', 'aiolos-checkout-for-woocommerce' ), __( 'A "Save your cart" window and one SMS or WhatsApp reminder', 'aiolos-checkout-for-woocommerce' ), ), ), 'analytics' => array( 'label' => __( 'Analytics', 'aiolos-checkout-for-woocommerce' ), 'title' => __( 'Checkout analytics', 'aiolos-checkout-for-woocommerce' ), 'text' => __( 'Where customers drop off, and what bumps, reminders and offers bring in.', 'aiolos-checkout-for-woocommerce' ), 'points' => array(), ), ); } /** * A Pro feature's tab without Pro: what it does, and where to get it. * * @param array $feature Feature. */ private static function render_pro_feature( array $feature ): void { $url = add_query_arg( array( 'utm_source' => 'aiolos-checkout', 'utm_medium' => 'settings', 'utm_campaign' => 'pro-tab', ), 'https://aiolosweb.com/aiolos-checkout-pro/' ); echo '
'; echo '' . esc_html__( 'PRO', 'aiolos-checkout-for-woocommerce' ) . ''; echo '

' . esc_html( $feature['title'] ) . '

'; echo '

' . esc_html( $feature['text'] ) . '

'; if ( $feature['points'] ) { echo ''; } echo '

' . esc_html__( 'Part of Aiolos Checkout Pro, a separate plugin installed next to this one.', 'aiolos-checkout-for-woocommerce' ) . '

'; echo '' . esc_html__( 'See Aiolos Checkout Pro', 'aiolos-checkout-for-woocommerce' ) . ''; echo '
'; } /** * The navigation groups, in order. A tab goes in the group it names ('group' in its schema tab * or in `aiolos_admin_tabs`), else in the group that lists it, else in the group its key * suggests; anything left goes under "More". * * @param array $tabs Tabs. * @return array */ private static function groups( array $tabs ): array { $groups = array( 'setup' => array( __( 'Setup', 'aiolos-checkout-for-woocommerce' ), array( Onboarding::TAB, 'general', 'design', 'license' ) ), 'checkout' => array( __( 'Checkout', 'aiolos-checkout-for-woocommerce' ), array( 'checkout', 'fields', 'address', 'pickup', 'rules', 'delivery', 'invoices', 'badges', 'accounts', 'thankyou' ) ), 'sales' => array( __( 'Sell more', 'aiolos-checkout-for-woocommerce' ), array( 'side_cart', 'rewards', 'upsells', 'bumps', 'post_purchase' ) ), 'recovery' => array( __( 'Cart recovery', 'aiolos-checkout-for-woocommerce' ), array( 'recovery', 'carts' ) ), 'reports' => array( __( 'Reports', 'aiolos-checkout-for-woocommerce' ), array( 'analytics' ) ), 'system' => array( __( 'System', 'aiolos-checkout-for-woocommerce' ), array( 'compatibility', 'tools' ) ), ); /** * Filters the groups of the settings navigation. * * @since 1.4.0 * * @param array $groups key => [ label, tab keys ]. */ $groups = (array) apply_filters( 'aiolos_admin_groups', $groups ); // Where each tab goes. $where = array(); foreach ( $groups as $group_key => $group ) { foreach ( (array) ( $group[1] ?? array() ) as $key ) { if ( is_string( $key ) && isset( $tabs[ $key ] ) && ! isset( $where[ $key ] ) ) { $where[ $key ] = (string) $group_key; } } } foreach ( $tabs as $key => $tab ) { $named = is_array( $tab ) && isset( $tab['group'] ) && is_string( $tab['group'] ) ? $tab['group'] : ''; if ( '' !== $named && isset( $groups[ $named ] ) ) { $where[ $key ] = $named; } elseif ( ! isset( $where[ $key ] ) ) { $guess = self::guess_group( (string) $key ); if ( '' !== $guess && isset( $groups[ $guess ] ) ) { $where[ $key ] = $guess; } } } $out = array(); foreach ( $groups as $group_key => $group ) { // Listed tabs in their listed order, then the others of this group in the order they came. $keys = array(); foreach ( (array) ( $group[1] ?? array() ) as $key ) { if ( is_string( $key ) && ( $where[ $key ] ?? '' ) === (string) $group_key ) { $keys[] = $key; } } foreach ( array_keys( $tabs ) as $key ) { if ( ( $where[ $key ] ?? '' ) === (string) $group_key && ! in_array( $key, $keys, true ) ) { $keys[] = (string) $key; } } if ( $keys ) { $out[] = array( 'label' => (string) ( $group[0] ?? $group_key ), 'tabs' => array_values( array_unique( $keys ) ), ); } } $rest = array_values( array_filter( array_map( 'strval', array_keys( $tabs ) ), static fn( $key ) => ! isset( $where[ $key ] ) ) ); if ( $rest ) { $out[] = array( 'label' => __( 'More', 'aiolos-checkout-for-woocommerce' ), 'tabs' => $rest, ); } return $out; } /** * The group a tab from an add-on most likely belongs to, by words in its key. * * @param string $key Tab key. */ private static function guess_group( string $key ): string { // The more specific words first: "abandoned_carts" is recovery, not the side cart. $words = array( 'recovery' => '/recover|abandon|remind/', 'reports' => '/analytic|report|stat|insight/', 'system' => '/tool|compat|log|debug|status|system|import|export|integration/', 'checkout' => '/pickup|shipping|payment|field|address|invoice|delivery|account|thank|checkout|badge|trust|order_?pay|rule/', 'sales' => '/cart|bump|upsell|cross|offer|reward|discount|coupon|gift|loyal/', 'setup' => '/general|design|style|brand|licen/', ); foreach ( $words as $group => $pattern ) { if ( preg_match( $pattern, $key ) ) { return $group; } } return ''; } /** * A Dashicons class for a tab. * * @param string $tab Tab key. */ private static function icon( string $tab ): string { $icons = array( 'general' => 'dashicons-admin-settings', 'design' => 'dashicons-art', 'license' => 'dashicons-admin-network', 'checkout' => 'dashicons-cart', 'fields' => 'dashicons-list-view', 'address' => 'dashicons-location', 'rules' => 'dashicons-randomize', 'delivery' => 'dashicons-calendar-alt', 'invoices' => 'dashicons-media-text', 'badges' => 'dashicons-shield', 'thankyou' => 'dashicons-heart', 'side_cart' => 'dashicons-archive', 'rewards' => 'dashicons-awards', 'upsells' => 'dashicons-lightbulb', 'bumps' => 'dashicons-plus-alt', 'post_purchase' => 'dashicons-tag', 'recovery' => 'dashicons-email-alt', 'carts' => 'dashicons-backup', 'analytics' => 'dashicons-chart-bar', 'start' => 'dashicons-flag', 'tools' => 'dashicons-admin-tools', 'compatibility' => 'dashicons-admin-plugins', 'pickup' => 'dashicons-store', 'accounts' => 'dashicons-admin-users', 'express' => 'dashicons-performance', ); /** * Filters the Dashicons class of a tab in the navigation. * * @since 1.6.0 * * @param string $icon Dashicons class. * @param string $tab Tab key. */ $icons[ $tab ] = (string) apply_filters( 'aiolos_admin_tab_icon', $icons[ $tab ] ?? 'dashicons-admin-generic', $tab ); return $icons[ $tab ] ?? 'dashicons-admin-generic'; } /** * A small checkout drawn with the Design settings, redrawn as they change (admin.js). */ private static function render_preview(): void { $money = static function ( float $amount ): string { return wp_strip_all_tags( wc_price( $amount ) ); }; ?> step="">
>
' . esc_html( (string) $field['description'] ) . '

'; } } /** * Saves one tab. */ public static function save(): void { if ( ! current_user_can( self::CAPABILITY ) ) { wp_die( esc_html__( 'You are not allowed to change these settings.', 'aiolos-checkout-for-woocommerce' ), 403 ); } $tab = isset( $_POST['tab'] ) ? sanitize_key( wp_unslash( $_POST['tab'] ) ) : ''; check_admin_referer( 'aiolos_save_settings_' . $tab ); $submitted = isset( $_POST['acw'] ) && is_array( $_POST['acw'] ) ? wp_unslash( $_POST['acw'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- each value is sanitized by its field type in Settings::sanitize_tab(). update_option( Settings::OPTION, Settings::sanitize_tab( $tab, $submitted ), true ); Settings::flush(); /** * Fires after a settings tab is saved. * * @since 1.4.0 * * @param string $tab Tab. */ do_action( 'aiolos_settings_saved', $tab ); wp_safe_redirect( add_query_arg( 'aiolos-saved', '1', self::url( $tab ) ) ); exit; } /** * Notices: a checkout page built with the Checkout block. */ public static function notices(): void { if ( ! current_user_can( self::CAPABILITY ) || ! Settings::enabled( 'checkout_enabled' ) || ! self::checkout_uses_block() ) { return; } $url = wp_nonce_url( admin_url( 'admin-post.php?action=aiolos_use_classic_checkout' ), 'aiolos_use_classic_checkout' ); ?>

:

0 && current_user_can( 'edit_post', $page_id ) && self::checkout_uses_block() ) { \AiolosCheckout\Checkout\PageMode::switch_to_shortcode( $page_id, (string) get_post_field( 'post_content', $page_id ) ); } wp_safe_redirect( add_query_arg( 'aiolos-saved', '1', self::url() ) ); exit; } }