*/ private static $hooks = array(); /** * Hook the menu, the files, and the downloads. * * @return void */ public static function init() { add_action( 'admin_menu', array( self::class, 'menu' ) ); add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue' ) ); // Marking products and categories on their own screens (P6). Woo_Admin::init(); // The CSV of the checks (P9). Export::init(); // "Not now" on the update card (UPD1). Updates::init(); } /** * Who may open the Agevow menu: the settings are the site's, so the default is * an administrator's capability (`agevow_capability_screen`). Each action checks * its own (§S-LESSONS row 30: the capability is chosen per ACTION, each * filterable — Security::capability()). * * @return string */ public static function capability() { return Security::capability( 'screen' ); } /** * The one menu item — no submenu: the three tabs inside our screens are the way * between them, and the Checks and the Settings are pages of their own that the * menu does not list. Measured 2026-10-14: with the tabs as submenu entries, a * phone's first tap on "Agevow" only unfolds the submenu, and Turn on took 4 taps * from the Plugins screen. Each page keeps the capability for its action; someone * who may read the record but not change the settings (a shop manager) finds the * menu opening on the Checks. * * @return void */ public static function menu() { $records_only = ! current_user_can( Security::capability( 'settings' ) ) && current_user_can( Security::capability( 'records' ) ); $top = $records_only ? self::CHECKS : self::PAGE; self::$hooks[ $top ] = (string) add_menu_page( __( 'Agevow', 'agevow-age-verification-age-gate' ), __( 'Agevow', 'agevow-age-verification-age-gate' ), $records_only ? Security::capability( 'records' ) : self::capability(), $top, $records_only ? array( self::class, 'render_checks' ) : array( self::class, 'render' ), 'dashicons-shield-alt', 58 ); // The pages the menu does not list: each gets its title on its own load- hook. $hidden = array(); if ( ! $records_only ) { self::$hooks[ self::CHECKS ] = (string) add_submenu_page( '', __( 'Agevow – Checks', 'agevow-age-verification-age-gate' ), __( 'Checks', 'agevow-age-verification-age-gate' ), Security::capability( 'records' ), self::CHECKS, array( self::class, 'render_checks' ) ); $hidden[] = self::$hooks[ self::CHECKS ]; } self::$hooks[ self::SETTINGS ] = (string) add_submenu_page( '', __( 'Agevow – Settings', 'agevow-age-verification-age-gate' ), __( 'Settings', 'agevow-age-verification-age-gate' ), Security::capability( 'settings' ), self::SETTINGS, array( self::class, 'render_settings' ) ); $hidden[] = self::$hooks[ self::SETTINGS ]; // "More plugins" (1.1.2): a page the menu does not list either, reached by the // LAST tab, for whoever may install plugins (its buttons need it). Its one // request to WordPress.org runs only while that page is drawn // (More_Plugins::render), never here. Not in self::$hooks: Agevow's own // stylesheet and script stay off that screen. $more = add_submenu_page( '', __( 'More plugins', 'agevow-age-verification-age-gate' ), __( 'More plugins', 'agevow-age-verification-age-gate' ), 'install_plugins', self::MORE, array( self::class, 'render_more_plugins' ) ); if ( is_string( $more ) && '' !== $more ) { add_action( 'load-' . $more, array( self::class, 'load_more_plugins' ) ); $hidden[] = $more; } // A page the menu does not list has no title WordPress can find, and on PHP 8.1+ // the admin header then logs "strip_tags(): Passing null" on every visit // (§S-LESSONS row 101, BUG1 (1)): each one gets its title as it loads. foreach ( $hidden as $hook ) { if ( '' !== $hook ) { add_action( 'load-' . $hook, array( self::class, 'title' ) ); } } add_filter( 'parent_file', array( self::class, 'parent_file' ) ); } /** * The title of the page being loaded, when it is one the menu does not list (the * Checks, the Settings, More plugins): WordPress finds titles in the menu only, and * the admin header prints this one in the browser tab. * * @return void */ public static function title() { global $plugin_page; $titles = array( self::CHECKS => __( 'Agevow – Checks', 'agevow-age-verification-age-gate' ), self::SETTINGS => __( 'Agevow – Settings', 'agevow-age-verification-age-gate' ), self::MORE => __( 'More plugins', 'agevow-age-verification-age-gate' ), ); if ( is_string( $plugin_page ) && isset( $titles[ $plugin_page ] ) ) { $GLOBALS['title'] = $titles[ $plugin_page ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- core's admin header reads the screen's title from this global, and finds none for a page the menu does not list (§S-LESSONS row 101). } } /** * On the Checks, the Settings and More plugins, the "Agevow" menu item stays * marked as the current one (the pages are not in the menu, so WordPress would * mark none). * * @param string $parent_file The menu item WordPress marks. * @return string */ public static function parent_file( $parent_file ) { global $plugin_page; if ( ! in_array( $plugin_page, array( self::CHECKS, self::SETTINGS, self::MORE ), true ) ) { return $parent_file; } return current_user_can( Security::capability( 'settings' ) ) ? self::PAGE : self::CHECKS; } /** * Which of our pages a screen is, or ''. * * @param string $hook_suffix The screen being loaded. * @return string */ public static function page_of( $hook_suffix ) { foreach ( array( self::PAGE, self::CHECKS, self::SETTINGS ) as $page ) { $hook = isset( self::$hooks[ $page ] ) && '' !== self::$hooks[ $page ] ? self::$hooks[ $page ] : get_plugin_page_hookname( $page, '' ); if ( '' !== (string) $hook_suffix && $hook_suffix === $hook ) { return $page; } } return ''; } /** * Our files, on our screens only: the stylesheet everywhere of ours; the script * with what it needs; on the Gate, the gate's own stylesheet for the preview; on * the Settings, the media library for the logo. * * @param string $hook_suffix The screen being loaded. * @return void */ public static function enqueue( $hook_suffix ) { $page = self::page_of( $hook_suffix ); if ( '' === $page ) { return; } wp_enqueue_style( 'agevow-admin', AGEVOW_URL . 'admin/css/admin.css', array(), AGEVOW_VERSION ); $settings = Settings::get(); if ( self::PAGE === $page ) { wp_enqueue_style( 'agevow-gate', AGEVOW_URL . 'public/css/gate.css', array(), AGEVOW_VERSION ); wp_add_inline_style( 'agevow-gate', Gate::looks_css( $settings ) ); } if ( self::SETTINGS === $page && current_user_can( 'upload_files' ) ) { wp_enqueue_media(); } wp_enqueue_script( 'agevow-admin', AGEVOW_URL . 'admin/js/admin.js', array(), AGEVOW_VERSION, array( 'in_footer' => true ) ); wp_localize_script( 'agevow-admin', 'agevowAdmin', self::config( $page, $settings ) ); } /** * What the screens' script needs. * * @param string $page Our page. * @param array $settings The settings. * @return array */ public static function config( $page, array $settings ) { $fields = array(); foreach ( Gate::field_order( get_locale() ) as $part ) { $fields[] = array_merge( array( 'part' => $part ), Gate::field( $part ) ); } $suggest = array(); foreach ( self::SELLS as $sells ) { $suggest[ $sells ] = self::suggest( $sells, self::country() ); } return array( 'root' => esc_url_raw( rest_url( Rest_Admin::NS . '/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'screen' => $page, 'settings' => $settings, 'woo' => self::woo(), 'today' => Dates::today(), 'monthAgo' => Dates::days_ago( 29 ), 'exportUrl' => Export::url(), 'printUrl' => wp_nonce_url( add_query_arg( array( 'page' => self::CHECKS ), admin_url( 'admin.php' ) ), self::SUMMARY ), 'orderUrl' => current_user_can( 'edit_shop_orders' ) ? self::order_url_template() : '', 'fields' => $fields, 'colors' => Gate::colors( Settings::defaults() ), 'suggest' => $suggest, 'words' => self::words(), ); } /** * Whether WooCommerce is active. * * @return bool */ public static function woo() { return class_exists( 'WooCommerce' ); } /** * The shop's country (WooCommerce's store address), or '' when it is not known. * * @return string */ public static function country() { $base = (string) get_option( 'woocommerce_default_country', '' ); return '' !== $base ? strtoupper( (string) strtok( $base, ':' ) ) : ''; } /** * The minimum age to suggest for what a shop sells, with the fact behind it — a * fact about a law only with its date, its source in words and "This is not legal * advice." (§S-LEGAL). The owner chooses the age; this only fills the field in. * * @param string $sells One of SELLS. * @param string $country The shop's country ('' = unknown). * @return array{age: int, fact: string} */ public static function suggest( $sells, $country ) { $us = 'US' === $country; $advice = __( 'This is not legal advice.', 'agevow-age-verification-age-gate' ); $check = __( 'Check the minimum age where you sell.', 'agevow-age-verification-age-gate' ); $us_alcohol = __( 'United States: 21 is the minimum age for alcohol in every state (the National Minimum Drinking Age Act of 1984; read 13 October 2026).', 'agevow-age-verification-age-gate' ); $us_tobacco = __( 'United States: 21 is the federal minimum age for tobacco and vapes, since 20 December 2019 (the US Food and Drug Administration; read 13 October 2026).', 'agevow-age-verification-age-gate' ); switch ( $sells ) { case 'alcohol': return array( 'age' => $us ? 21 : 18, 'fact' => ( $us ? $us_alcohol : __( 'Suggested: 18; 21 in the United States.', 'agevow-age-verification-age-gate' ) . ' ' . $us_alcohol ) . ' ' . $check . ' ' . $advice, ); case 'tobacco': return array( 'age' => $us ? 21 : 18, 'fact' => ( $us ? $us_tobacco : __( 'Suggested: 18; 21 in the United States.', 'agevow-age-verification-age-gate' ) . ' ' . $us_tobacco ) . ' ' . $check . ' ' . $advice, ); case 'cbd': return array( 'age' => $us ? 21 : 18, 'fact' => __( 'Suggested: 21 in the United States, 18 elsewhere — there is no one minimum age for CBD.', 'agevow-age-verification-age-gate' ) . ' ' . $check . ' ' . $advice, ); case 'knives': return array( 'age' => 18, 'fact' => __( 'Suggested: 18.', 'agevow-age-verification-age-gate' ) . ' ' . $check . ' ' . $advice, ); } return array( 'age' => 18, 'fact' => __( 'Suggested: 18.', 'agevow-age-verification-age-gate' ) . ' ' . $check . ' ' . $advice, ); } /** * An order's edit address with %d for its id: WooCommerce's own order screen, with * the order tables on or off. * * @return string */ public static function order_url_template() { $hpos = class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled(); return $hpos ? admin_url( 'admin.php?page=wc-orders&action=edit&id=%d' ) : admin_url( 'post.php?post=%d&action=edit' ); } /** * Every word the script shows (the server's words, so they are translated once). * * @return array */ public static function words() { return array( 'saving' => __( 'Saving…', 'agevow-age-verification-age-gate' ), 'saved' => __( 'Saved.', 'agevow-age-verification-age-gate' ), 'turnedOn' => __( 'The age gate is on.', 'agevow-age-verification-age-gate' ), 'turnedOff' => __( 'The age gate is off.', 'agevow-age-verification-age-gate' ), /* translators: %s: what went wrong, in plain words. */ 'failed' => __( 'Not saved: %s', 'agevow-age-verification-age-gate' ), 'offline' => __( 'The site could not be reached. Check the connection and try again.', 'agevow-age-verification-age-gate' ), /* translators: %d: the HTTP status the site answered with. */ 'blocked' => __( 'The site refused the request (HTTP %d). A security plugin or firewall may be blocking it.', 'agevow-age-verification-age-gate' ), 'loading' => __( 'Loading…', 'agevow-age-verification-age-gate' ), 'none' => __( 'Nothing in these days.', 'agevow-age-verification-age-gate' ), /* translators: %s: how many checks. */ 'checksCount' => __( 'Checks in these days: %s', 'agevow-age-verification-age-gate' ), 'prev' => __( 'Previous', 'agevow-age-verification-age-gate' ), 'next' => __( 'Next', 'agevow-age-verification-age-gate' ), /* translators: 1: this page, 2: how many pages. */ 'pageOf' => __( 'Page %1$s of %2$s', 'agevow-age-verification-age-gate' ), 'colWhen' => __( 'Date', 'agevow-age-verification-age-gate' ), 'colOrder' => __( 'Order', 'agevow-age-verification-age-gate' ), 'colWhere' => __( 'Where', 'agevow-age-verification-age-gate' ), 'colHow' => __( 'How', 'agevow-age-verification-age-gate' ), 'colAge' => __( 'Minimum age', 'agevow-age-verification-age-gate' ), 'colResult' => __( 'Result', 'agevow-age-verification-age-gate' ), 'colDay' => __( 'Day', 'agevow-age-verification-age-gate' ), 'colAsked' => __( 'Asked', 'agevow-age-verification-age-gate' ), 'colPassed' => __( 'Passed', 'agevow-age-verification-age-gate' ), 'colUnder' => __( 'Under the minimum age', 'agevow-age-verification-age-gate' ), 'colLeft' => __( 'Left', 'agevow-age-verification-age-gate' ), 'colShare' => __( 'Passed of asked', 'agevow-age-verification-age-gate' ), 'colWho' => __( 'Who', 'agevow-age-verification-age-gate' ), 'colChange' => __( 'What changed', 'agevow-age-verification-age-gate' ), 'total' => __( 'Total', 'agevow-age-verification-age-gate' ), 'noOrder' => __( 'no order placed', 'agevow-age-verification-age-gate' ), /* translators: %s: an order number. */ 'orderNo' => __( 'Order #%s', 'agevow-age-verification-age-gate' ), 'badRange' => __( 'The first day comes after the last one.', 'agevow-age-verification-age-gate' ), /* translators: %d: the minimum age, 18 to 25. */ 'yes' => __( 'Yes, I am %d or older', 'agevow-age-verification-age-gate' ), 'no' => __( 'No', 'agevow-age-verification-age-gate' ), 'askTap' => __( 'Are you old enough to enter?', 'agevow-age-verification-age-gate' ), 'askDob' => __( 'Please enter your date of birth', 'agevow-age-verification-age-gate' ), /* translators: %d: the minimum age, 18 to 25. */ 'message' => __( 'You must be %d or older to see this page.', 'agevow-age-verification-age-gate' ), 'yourDob' => __( 'Your date of birth', 'agevow-age-verification-age-gate' ), 'dobHint' => __( 'Your date of birth is not sent or saved.', 'agevow-age-verification-age-gate' ), 'continue' => __( 'Continue', 'agevow-age-verification-age-gate' ), /* translators: %s: a contrast ratio such as 3.2. */ 'lowText' => __( 'The text colour is hard to read on the background colour (contrast %s to 1; at least 4.5 to 1 is needed).', 'agevow-age-verification-age-gate' ), /* translators: %s: a contrast ratio such as 3.2. */ 'lowButton' => __( 'The words on the button are hard to read on the button colour (contrast %s to 1; at least 4.5 to 1 is needed).', 'agevow-age-verification-age-gate' ), 'chooseLogo' => __( 'Choose a logo', 'agevow-age-verification-age-gate' ), 'useLogo' => __( 'Use this logo', 'agevow-age-verification-age-gate' ), ); } // ── the pages ──────────────────────────────────────────────────────────── /** * Refuse a page to someone without the capability for it. * * @param string $action screen · settings · records. * @return void */ private static function guard( $action ) { if ( ! current_user_can( Security::capability( $action ) ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to open this page.', 'agevow-age-verification-age-gate' ), 403 ); } } /** * The heading and the tabs the user may open. * * @param string $current Our page being shown. * @return void */ private static function head( $current ) { // Each tab with the capability that opens it; More plugins is LAST and plain // (no count, no badge), for whoever may install plugins. $tabs = array( self::PAGE => array( __( 'Gate', 'agevow-age-verification-age-gate' ), Security::capability( 'settings' ) ), self::CHECKS => array( __( 'Checks', 'agevow-age-verification-age-gate' ), Security::capability( 'records' ) ), self::SETTINGS => array( __( 'Settings', 'agevow-age-verification-age-gate' ), Security::capability( 'settings' ) ), self::MORE => array( __( 'More plugins', 'agevow-age-verification-age-gate' ), 'install_plugins' ), ); ?>

__( 'Wine, beer & spirits', 'agevow-age-verification-age-gate' ), 'tobacco' => __( 'Vapes & tobacco', 'agevow-age-verification-age-gate' ), 'cbd' => __( 'CBD', 'agevow-age-verification-age-gate' ), 'knives' => __( 'Knives & blades', 'agevow-age-verification-age-gate' ), 'other' => __( 'Something else', 'agevow-age-verification-age-gate' ), ); foreach ( $sells as $value => $label ) { self::choice( 'sells', $value, '', $label ); } ?>

' . esc_html( sprintf( _n( '%d product or category is marked.', '%d products and categories are marked.', $marked, 'agevow-age-verification-age-gate' ), $marked ) ) . ''; ?>

>

aria-describedby=""> >

$items id → title. * @param int[] $chosen The ids ticked. * @return void */ private static function id_list( $name, $legend, array $items, array $chosen ) { ?>

$title ) : ?>

>

*/ public static function pages() { $out = array(); $pages = get_pages( array( 'number' => Settings::MAX_IDS, 'post_status' => 'publish,private,draft', ) ); foreach ( is_array( $pages ) ? $pages : array() as $page ) { $out[ (int) $page->ID ] = (string) $page->post_title; } return $out; } /** * The post categories, id → name. * * @return array */ public static function categories() { $out = array(); $terms = get_terms( array( 'taxonomy' => 'category', 'hide_empty' => false, 'number' => Settings::MAX_IDS, ) ); foreach ( is_array( $terms ) ? $terms : array() as $term ) { $out[ (int) $term->term_id ] = (string) $term->name; } return $out; } /** * The Checks (P9): the list, the counts, the history — or, from its own link, the * printable summary of a range of days. * * @return void */ public static function render_checks() { self::guard( 'records' ); $nonce = isset( $_GET['_wpnonce'] ) && is_string( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : ''; if ( '' !== $nonce && false !== wp_verify_nonce( $nonce, self::SUMMARY ) ) { $from = isset( $_GET['from'] ) && is_string( $_GET['from'] ) ? sanitize_text_field( wp_unslash( $_GET['from'] ) ) : ''; $to = isset( $_GET['to'] ) && is_string( $_GET['to'] ) ? sanitize_text_field( wp_unslash( $_GET['to'] ) ) : ''; self::render_summary( Dates::is_day( $from ) ? $from : Dates::days_ago( 29 ), Dates::is_day( $to ) ? $to : Dates::today() ); return; } $woo = self::woo(); ?>

$to ) { list( $from, $to ) = array( $to, $from ); } $sum = Record::summary( $from, $to ); $label = function ( $day ) { return wp_date( (string) get_option( 'date_format', 'j F Y' ), ( new \DateTimeImmutable( $day . ' 12:00:00', wp_timezone() ) )->getTimestamp() ); }; ?>

$counts ) : ?>

0 ? wp_get_attachment_image( (int) $s['logo'], 'thumbnail', false, array( 'alt' => '' ) ) : ''; ?>

>

>

>

__( 'More plugins', 'agevow-age-verification-age-gate' ), 'source' => __( 'This list comes from the WordPress.org plugin directory.', 'agevow-age-verification-age-gate' ), 'privacy' => __( 'WordPress.org\'s privacy policy', 'agevow-age-verification-age-gate' ), 'related' => __( 'Related to Agevow', 'agevow-age-verification-age-gate' ), 'others' => __( 'More from us', 'agevow-age-verification-age-gate' ), 'unreachable' => __( 'WordPress.org could not be reached just now, so only the plugins\' names are shown. Try again in a few minutes.', 'agevow-age-verification-age-gate' ), 'install' => __( 'Install Now', 'agevow-age-verification-age-gate' ), /* translators: %s: a plugin's name. */ 'install_label' => __( 'Install %s now', 'agevow-age-verification-age-gate' ), 'activate' => __( 'Activate', 'agevow-age-verification-age-gate' ), /* translators: %s: a plugin's name. */ 'activate_label' => __( 'Activate %s', 'agevow-age-verification-age-gate' ), 'update' => __( 'Update now', 'agevow-age-verification-age-gate' ), /* translators: %s: a plugin's name. */ 'update_label' => __( 'Update %s now', 'agevow-age-verification-age-gate' ), 'update_available' => __( 'Update available', 'agevow-age-verification-age-gate' ), 'active' => __( 'Active', 'agevow-age-verification-age-gate' ), 'installed' => __( 'Installed', 'agevow-age-verification-age-gate' ), 'details' => __( 'More Details', 'agevow-age-verification-age-gate' ), /* translators: %s: a plugin's name. */ 'details_label' => __( 'More information about %s', 'agevow-age-verification-age-gate' ), ) ); } /** * A text field with its label. * * @param string $name The setting. * @param string $label Its name. * @param string $value Its value. * @param string $placeholder The default, shown when empty. * @param string $type text · url. * @return void */ private static function text( $name, $label, $value, $placeholder, $type = 'text' ) { $id = 'agevow-' . str_replace( '_', '-', $name ); ?>