'askshelf', 'title' => __( 'Askshelf', 'askshelf' ), 'path' => self::PATH, 'capability' => 'view_woocommerce_reports', 'icon' => 'data:image/svg+xml;base64,' . self::ICON, 'position' => 56, ) ); wc_admin_register_page( array( 'id' => 'askshelf-ask', 'parent' => 'askshelf', 'title' => __( 'Ask', 'askshelf' ), 'path' => self::PATH, 'capability' => 'view_woocommerce_reports', ) ); wc_admin_register_page( array( 'id' => 'askshelf-settings', 'parent' => 'askshelf', 'title' => __( 'Settings', 'askshelf' ), 'path' => self::PATH . '&settings=open', 'capability' => 'manage_woocommerce', ) ); } /** * Output for the fallback page. */ public static function render_analytics_disabled(): void { printf( '
', esc_html__( 'Askshelf', 'askshelf' ), esc_html__( 'Askshelf answers questions from WooCommerce Analytics, which is turned off on this store. Turn it on to use Askshelf.', 'askshelf' ), esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=features' ) ), esc_html__( 'Open WooCommerce features', 'askshelf' ) ); } /** * Whether WooCommerce Analytics is on. */ public static function analytics_enabled(): bool { return 'no' !== get_option( 'woocommerce_analytics_enabled', 'yes' ); } /** * Loads the app on WooCommerce admin (React) pages for users who can view reports. */ public static function enqueue(): void { if ( ! current_user_can( 'view_woocommerce_reports' ) || ! self::analytics_enabled() ) { return; } if ( ! class_exists( \Automattic\WooCommerce\Admin\PageController::class ) || ! \Automattic\WooCommerce\Admin\PageController::is_admin_page() ) { return; } $asset_file = ASKSHELF_DIR . 'build/index.asset.php'; if ( ! is_readable( $asset_file ) ) { return; } $asset = require $asset_file; wp_enqueue_script( self::SCRIPT_HANDLE, ASKSHELF_URL . 'build/index.js', $asset['dependencies'], $asset['version'], array( 'in_footer' => true ) ); wp_enqueue_style( self::SCRIPT_HANDLE, ASKSHELF_URL . 'build/index.css', array( 'wp-components' ), $asset['version'] ); wp_style_add_data( self::SCRIPT_HANDLE, 'rtl', 'replace' ); wp_set_script_translations( self::SCRIPT_HANDLE, 'askshelf', ASKSHELF_DIR . 'languages' ); $config = array( 'version' => ASKSHELF_VERSION, 'serviceUrl' => Connection::service_url(), 'pricingUrl' => self::PRICING_URL, 'accountUrl' => (string) ASKSHELF_ACCOUNT_URL, 'canManage' => current_user_can( 'manage_woocommerce' ), 'store' => Store::context(), ); wp_add_inline_script( self::SCRIPT_HANDLE, 'window.askshelfConfig = ' . wp_json_encode( $config ) . ';', 'before' ); } }