proUpsell ??= new ProUpsell(); } 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 addMenuPage(): void { $this->hookSuffix = add_submenu_page( 'woocommerce', __('Bundaro: product bundles', 'bundaro'), __('Bundle', 'bundaro'), 'manage_woocommerce', self::PAGE, [$this, 'renderPage'], ) ?: null; } /** * Enqueue the settings-page polish (card styling + accessible help bubbles). * Loaded only on this plugin's settings screen. */ public function enqueueAssets(string $hook): void { if ($this->hookSuffix === null || $hook !== $this->hookSuffix) { return; } wp_enqueue_style( 'bundle-admin', BUNDLE_URL . 'assets/css/admin.css', [], \Bundle\VERSION, ); wp_enqueue_script( 'bundle-admin', BUNDLE_URL . 'assets/js/admin.js', [], \Bundle\VERSION, ['in_footer' => true], ); } /** * Render a "?" help affordance and the accessible popover bubble it controls. * The bubble is a native [popover] wired via aria-describedby, so the help * text is always reachable by keyboard and screen readers. */ private function help(string $id, string $text): string { return sprintf( '' . '%3$s', esc_attr($id), esc_attr__('More information', 'bundaro'), esc_html($text), ); } public function registerSettings(): void { register_setting( self::PAGE, self::OPTION, [ 'type' => 'array', 'sanitize_callback' => [$this, 'sanitize'], ], ); // The menu uses manage_woocommerce; align the options.php save capability // so shop managers (not just admins with manage_options) can save. add_filter( 'option_page_capability_' . self::PAGE, static fn (): string => 'manage_woocommerce', ); } public function renderPage(): void { if (! current_user_can('manage_woocommerce')) { return; } $settings = $this->settings(); $mode = (string) ($settings['discount_mode'] ?? 'fee'); $option = self::OPTION; // Allowed HTML for the help affordances (button + popover span). $help_html = [ 'button' => [ 'type' => true, 'class' => true, 'aria-describedby' => true, 'aria-label' => true, ], 'span' => [ 'id' => true, 'class' => true, 'popover' => true, 'role' => true, ], ]; ?>
[bundle]',
'[bundle id="123"]'
);
?>