proUpsell ??= new ProUpsell(); } /** * The settings page / option-group slug. * * Exposed so PRO add-ons can register their own settings against the same * options.php group and render under the same WooCommerce submenu. */ public static function pageSlug(): string { return self::PAGE; } public function registerHooks(): void { add_action('admin_menu', [$this, 'addMenuPage']); add_action('admin_init', [$this, 'registerSettings']); add_action('admin_enqueue_scripts', [$this, 'enqueueAssets']); $this->proUpsell()->registerHooks(); } public function enqueueAssets(string $hook): void { if ($hook !== 'woocommerce_page_' . self::PAGE) { return; } wp_enqueue_style( 'tipping-admin', \TIPPING_URL . 'assets/css/admin.css', [], \Tipping\VERSION, ); } public function addMenuPage(): void { add_submenu_page( 'woocommerce', __('Dankon Tips', 'dankon'), __('Dankon Tips', 'dankon'), 'manage_woocommerce', self::PAGE, [$this, 'renderPage'], ); } public function registerSettings(): void { register_setting( self::PAGE, Options::OPTION, [ 'type' => 'array', 'sanitize_callback' => [$this, 'sanitize'], ], ); // The menu uses manage_woocommerce; align the options.php save capability. add_filter( 'option_page_capability_' . self::PAGE, static fn (): string => 'manage_woocommerce', ); } public function renderPage(): void { if (! current_user_can('manage_woocommerce')) { return; } // Deliberately the RAW settings, never Options::resolved(): an empty text // field must stay empty here. Rendering the resolved default into the // input would save the merchant's current language back into the option // on the next submit and freeze it there. $settings = $this->options->all(); $type = $this->options->type(); $presets = $this->options->presets(); // Shown as placeholders instead, so the merchant can read the default // they get when they leave a field empty, in their own language. $textDefaults = Texts::defaults(); ?>