Settings -> Products and are linked here. */ final class AdminPage { const SLUG = 'strikewise'; /** Right below WooCommerce and Products. */ const POSITION = '55.8'; /** User meta: the premium banner was hidden. */ const META_PROMO_HIDDEN = 'strikewise_promo_hidden'; /** Action of admin-post.php that hides the premium banner. */ const ACTION_HIDE_PROMO = 'strikewise_hide_promo'; /** @var string Hook suffix of the overview page. */ private static $hook = ''; public function register(): void { add_action( 'admin_menu', array( $this, 'add_page' ), 60 ); add_action( 'admin_menu', array( $this, 'add_settings_link' ), 70 ); add_filter( 'submenu_file', array( $this, 'highlight_settings' ), 99 ); add_action( 'admin_post_' . self::ACTION_HIDE_PROMO, array( $this, 'hide_promo' ) ); } /** * Hides the premium banner for the current user. */ public function hide_promo(): void { check_admin_referer( self::ACTION_HIDE_PROMO ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'strikewise' ), '', array( 'response' => 403 ) ); } update_user_meta( get_current_user_id(), self::META_PROMO_HIDDEN, time() ); wp_safe_redirect( admin_url( 'admin.php?page=' . self::SLUG ) ); exit; } public function add_page(): void { self::$hook = (string) add_menu_page( __( 'Strikewise', 'strikewise' ), __( 'Strikewise', 'strikewise' ), 'manage_woocommerce', self::SLUG, array( $this, 'render' ), self::menu_icon(), self::POSITION ); add_submenu_page( self::SLUG, __( 'Strikewise', 'strikewise' ), __( 'Overview', 'strikewise' ), 'manage_woocommerce', self::SLUG, array( $this, 'render' ) ); } /** * Hook suffix of the overview page, for screen checks. */ public static function hook(): string { return '' !== self::$hook ? self::$hook : 'toplevel_page_' . self::SLUG; } public function add_settings_link(): void { add_submenu_page( self::SLUG, __( 'Settings', 'strikewise' ), __( 'Settings', 'strikewise' ), 'manage_woocommerce', self::settings_path() ); } /** * Marks "Settings" in the Strikewise menu while its section in WooCommerce is shown. * WordPress keeps the WooCommerce menu open on that page; assets/settings.js moves it. * * @param string|null $submenu_file * @return string|null */ public function highlight_settings( $submenu_file ) { return self::on_settings() ? self::settings_path() : $submenu_file; } private static function on_settings(): bool { // phpcs:ignore WordPress.Security.NonceVerification -- only decides which menu entry is highlighted. return isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && Settings::SECTION === $_GET['section']; } private static function settings_path(): string { return 'admin.php?page=wc-settings&tab=products§ion=' . Settings::SECTION; } /** * Price tag as menu icon; WordPress colours it like the other menu icons. */ private static function menu_icon(): string { $svg = ''; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- data URI of the menu icon. } public function render(): void { $tracked = Stats::collect()['tracked']; $premium = Licensing::can_use_premium(); $settings = self::settings_url(); echo '
' . esc_html__( 'Show discounts the way the law requires, automatically.', 'strikewise' ) . '
' . esc_html( $protection['reduced'] > 0 /* translators: %d: number of products */ ? sprintf( _n( 'Strikewise shows the lowest price of the 30 days before for %d reduced product and corrects strike-through prices automatically.', 'Strikewise shows the lowest price of the 30 days before for %d reduced products and corrects strike-through prices automatically.', $protection['reduced'], 'strikewise' ), $protection['reduced'] ) : __( 'As soon as you reduce a product, Strikewise shows the lowest price of the 30 days before and corrects the strike-through price.', 'strikewise' ) ) . '
'; } else { echo '' . esc_html( $value ) . '
'; echo '' . esc_html( $label ) . '
'; echo '' . esc_html( $hint ) . '
'; echo '' . esc_html( $reduced > 0 /* translators: %d: number of products */ ? sprintf( _n( '%d product in your shop is reduced right now. Premium checks it every week and reports problems by e-mail, before a warning letter does.', '%d products in your shop are reduced right now. Premium checks them every week and reports problems by e-mail, before a warning letter does.', $reduced, 'strikewise' ), $reduced ) : __( 'Premium checks every reduced product every week and reports problems by e-mail.', 'strikewise' ) ) . '
'; echo '' . esc_html__( 'Also included: price log per product as CSV, as evidence for your lawyer, and the agency cockpit for licenses with 5 or more shops.', 'strikewise' ) . '
'; echo '