add_action( 'after_uninstall', 'vizyt_fs_uninstall_cleanup' ); $fs->add_filter( 'plugin_icon', [ self::class, 'icon' ] ); } /** * Icon of the opt-in and account screens. Without it the SDK looks for * vendor/freemius/assets/img/vizyt.* and, on a local site, downloads one there. */ public static function icon(): string { return VIZYT_PLUGIN_DIR . 'assets/images/vizyt-symbol.svg'; } /** * Undo register()'s filters (tests). */ public static function unregister(): void { self::$fs = null; remove_filter( 'vizyt_pro_upgrade_url', [ self::class, 'upgrade_url' ] ); remove_filter( 'vizyt_pro_price', [ self::class, 'price' ] ); } /** * Without the SDK: the uninstall hook and the redirect of the add-on's * old address (register_fallback_uninstall(), redirect_pro_page()). */ public static function register_fallback(): void { self::register_fallback_uninstall(); add_action( 'admin_page_access_denied', [ self::class, 'redirect_pro_page' ] ); } /** * Without the SDK, WordPress calls the cleanup on plugin deletion through * the uninstall hook (there is no uninstall.php: Freemius needs its own * hook, which it registers when the plugin is deactivated). */ public static function register_fallback_uninstall(): void { register_uninstall_hook( VIZYT_PLUGIN_FILE, 'vizyt_fs_uninstall_cleanup' ); } /** * "Upgrade to Pro" → the Vizyt Pro add-on on Freemius's Add-Ons page * (its dialog leads to the checkout). * * @param string $url Default (the information page). */ public static function upgrade_url( $url ): string { if ( ! is_object( self::$fs ) ) { return (string) $url; } $addon = (string) self::$fs->addon_url( self::PRO_SLUG ); return '' !== $addon ? $addon : (string) $url; } /** * Price line of the add-on card. The plans themselves are set in the * Freemius dashboard ($39 a year for 1 site, $99 for 3 sites). * * @param string $price Default (empty). */ public static function price( $price ): string { unset( $price ); return sprintf( /* translators: %s: lowest Vizyt Pro price with its currency, e.g. "$39" (not translatable: the price is set in US dollars) */ __( 'from %s / year', 'vizyt' ), '$39' ); } /** * Where admin.php?page=vizyt-pro should lead when nothing answers it. * With Freemius it is the add-on's licence activation screen; without * it (the free "Vizyt Pro" page moved to ProPage::SLUG in 1.8.0) old * bookmarks and links get the free page instead of "not allowed" — * or the dashboard when Pro runs and there is no free page. */ public static function pro_page_redirect(): ?string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only reads which admin page was asked for. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( self::PRO_SLUG !== $page || is_object( self::$fs ) || ! current_user_can( 'manage_vizyt' ) ) { return null; } return admin_url( 'admin.php?page=' . ( vizyt_is_pro() ? 'vizyt' : \Vizyt\Admin\ProPage::SLUG ) ); } /** * admin_page_access_denied: follow pro_page_redirect(). */ public static function redirect_pro_page(): void { $url = self::pro_page_redirect(); if ( null !== $url ) { wp_safe_redirect( $url ); exit; } } }