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' ),
);
?>
*/
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 '