report_page_hook = $hook; $this->maybe_register_freemius_activation_placeholder(); // Fires early enough to send file-download headers or redirect, before any admin page HTML is output. add_action( "load-{$hook}", array($this, 'maybe_export_csv') ); add_action( "load-{$hook}", array($this, 'maybe_recalculate_cogs') ); add_action( "load-{$hook}", array($this, 'maybe_save_settings') ); add_action( 'admin_enqueue_scripts', array($this, 'enqueue_report_scripts') ); } /** * Freemius's Account page is configured (see a1-woocog.php's * fs_dynamic_init 'menu' config) to nest under WooCommerce's top-level * menu at its own raw slug, 'a1woocog-account'. Freemius's SDK treats * that raw slug as this plugin's permanent "default page": it's what * override_submenu_action() looks for during the pre-connection * activation flow (the "Opt In" banner/link on the Plugins page), AND * it's what get_after_activation_url() (via _get_admin_page_url( '' )) * redirects back to immediately after "Allow & Continue" or "Skip" * complete. Unlike its top-level-menu code path (see A1-WooBay, which * owns its own top-level page at the exact slug Freemius uses there), * the submenu code path has no fallback to create this page from * scratch if it doesn't already exist - so with nothing in this plugin * ever registering that slug, every one of those transitions landed on * a page WordPress had never heard of, producing its generic "Sorry, * you are not allowed to access this page" error. Confirmed live on * wp.org for both the very first "Opt In" click (1.2.9) and again * immediately after "Allow & Continue" finishes connecting (this fix). * * Fix: register this page unconditionally (default priority, so it * exists before Freemius's own admin_menu hook, which runs at * WP_FS__LOWEST_PRIORITY) so the raw slug always resolves to something, * in every connection state. Only shown as a visible WooCommerce * submenu item while Freemius's own real Account page - a different, * suffixed slug, 'a1woocog-account-account', built via its own * get_slug( 'account' ) - doesn't exist yet (i.e. while !is_registered()). * Once connected, this re-registers with an empty parent slug instead: * WordPress still fully registers and dispatches it (the same "hidden * but functional" pattern Freemius's own SDK uses for its activation * override - see override_plugin_menu_with_activation() passing '' as * the parent for its own fallback page), it just isn't shown in any * menu, so there's no second, duplicate "A1 Profit" item alongside the * real one. */ private function maybe_register_freemius_activation_placeholder() { $is_registered = a1woocog_fs()->is_registered(); add_submenu_page( ( $is_registered ? '' : 'woocommerce' ), __( 'A1 Profit', 'a1-profit-reports-for-woocommerce' ), __( 'A1 Profit', 'a1-profit-reports-for-woocommerce' ), 'manage_woocommerce', 'a1woocog-account', array($this, 'render_account_placeholder') ); } /** * Only reachable when Freemius doesn't hijack this page itself - either * pre-connection if its activation-mode override didn't fire for some * reason, or post-connection where it's just a safety-net redirect to * the real Account page (see maybe_register_freemius_activation_placeholder()). */ public function render_account_placeholder() { if ( !current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'Permission denied.', 'a1-profit-reports-for-woocommerce' ) ); } $target = ( a1woocog_fs()->is_registered() ? a1woocog_fs()->get_account_url() : admin_url( 'admin.php?page=a1woocog-reports' ) ); wp_safe_redirect( $target ); exit; } /** * The date-preset