addAdminMenu( __('Site Assistant', 'extendify-local'), $assist->slug, [$assist, 'pageContent'] ); // If they finish launch then stop here (devmode gets through). if (!Config::$showLaunch) { return; } $launch = new LaunchAdminPage(); $this->addSubMenu( // translators: Launch is a noun. __('Launch', 'extendify-local'), $launch->slug, [$launch, 'pageContent'] ); }); // If the user is redirected to this while visiting our url, intercept it. \add_filter('wp_redirect', function ($url) { if (PartnerData::$id === 'no-partner') { return $url; } // Check for extendify-launch-success as other plugins will not override // this as they intercept the request. // phpcs:ignore WordPress.Security.NonceVerification if (isset($_GET['extendify-launch-success'])) { return \admin_url() . $this->getRoute(); } // Special treatment for Yoast to disable their redirect when installing. if ($url === \admin_url() . 'admin.php?page=wpseo_installation_successful_free') { return \admin_url() . $this->getRoute(); } // Special treatment for Germanized for WooCommerce to disable their redirect when installing. if ($url === \admin_url() . 'admin.php?page=wc-gzd-setup') { return \admin_url() . $this->getRoute(); } return $url; }, 9999); } /** * A helper for handling sub menus * * @param string $name - The menu name. * @param string $slug - The menu slug. * @param callable $callback - The callback to render the page. * * @return void */ public function addSubMenu($name, $slug, $callback = '') { \add_submenu_page( // Uses a "dummy" page for adding pages without a menu. (constant('EXTENDIFY_DEVMODE') ? 'extendify-assist' : 'extendify-page'), $name, $name, Config::$requiredCapability, $slug, $callback ); } /** * Adds Extendify top menu * * @param string $label - The menu label. * @param string $slug - The menu slug. * @param string|callable $callback - The callback to render the page. * @return void */ public function addAdminMenu($label, $slug, $callback) { $menuLabel = sprintf('%1$s ', $label); \add_menu_page( 'Extendify', $menuLabel, Config::$requiredCapability, $slug, $callback, // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 'data:image/svg+xml;base64,' . base64_encode(''), PartnerData::$id !== 'no-partner' ? 0 : null ); } /** * Routes pages accordingly * * @return string */ public function getRoute() { // This router use to handle more cases but now everyone goes to Assist. return 'admin.php?page=extendify-assist'; } /** * Redirect once to Launch, only once (at least once) when * the email matches the entry in WP Admin > Settings > General. * * @return void */ public function redirectOnce() { if (\get_option('extendify_launch_loaded', false) || !Config::$showLaunch) { return; } // Only redirect if we aren't already on the page. // phpcs:ignore WordPress.Security.NonceVerification.Recommended if (isset($_GET['page']) && $_GET['page'] === 'extendify-launch') { return; } $user = \wp_get_current_user(); if ($user // Check the main admin email, and they have an admin role. // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps && \get_option('admin_email') === $user->user_email && in_array('administrator', $user->roles, true) ) { // Only redirect 3 times. $currentCount = \get_option('extendify_attempted_redirect_count', 0); if ($currentCount >= 3) { return; } \update_option('extendify_attempted_redirect_count', ($currentCount + 1)); \update_option('extendify_attempted_redirect', gmdate('Y-m-d H:i:s')); \wp_safe_redirect(\admin_url() . 'admin.php?page=extendify-launch'); } } }