cache->get( 'pro_just_deactivated_lite' ); if ( ! $proDeactivatedLite ) { // Also check for the old transient in the options table (because a user might switch from an older Lite version that lacks the Cache class). $proDeactivatedLite = (bool) get_option( '_aioseo_cache_pro_just_deactivated_lite' ); } if ( $proDeactivatedLite ) { aioseo()->cache->delete( 'pro_just_deactivated_lite', true ); $this->activate( false ); } } /** * Runs on activation. * * @since 4.0.17 * * @param bool $networkWide Whether or not this is a network wide activation. * @return void */ public function activate( $networkWide ) { aioseo()->access->addCapabilities(); // Make sure our tables exist. aioseo()->updates->addInitialCustomTablesForV4(); // Set the activation timestamps. $time = time(); aioseo()->internalOptions->internal->activated = $time; if ( ! aioseo()->internalOptions->internal->firstActivated ) { aioseo()->internalOptions->internal->firstActivated = $time; } aioseo()->cache->clear(); $this->maybeRunSetupWizard(); } /** * Runs on deactivation. * * @since 4.0.0 * * @return void */ public function deactivate() { aioseo()->access->removeCapabilities(); \AIOSEO\Plugin\Common\Sitemap\Rewrite::removeRewriteRules( [], true ); } /** * Check if we should redirect on activation. * * @since 4.1.2 * * @return void */ private function maybeRunSetupWizard() { if ( '0.0' !== aioseo()->internalOptions->internal->lastActiveVersion ) { return; } $oldOptions = get_option( 'aioseop_options' ); if ( ! empty( $oldOptions ) ) { return; } if ( is_network_admin() ) { return; } if ( isset( $_GET['activate-multi'] ) ) { return; } // Sets 30 second transient for welcome screen redirect on activation. aioseo()->cache->update( 'activation_redirect', true, 30 ); } /** * Adds our capabilities to all roles on the next request and the installing user on the current request after upgrading to Pro. * * * @since 4.1.4.4 * * @return void */ public function addCapabilitiesOnUpgrade() { // In case the user is switching to Pro via the AIOSEO Connect feature, // we need to set this transient here as the regular activation hooks won't run and Pro otherwise won't clear the cache and add the required capabilities. aioseo()->cache->update( 'pro_just_deactivated_lite', true ); // Doing the above isn't sufficient because the current user will be lacking the capabilities on the first request. Therefore, we add them manually just for him. $userId = function_exists( 'get_current_user_id' ) && get_current_user_id() ? get_current_user_id() // If there is a logged in user, the user is switching from Lite to Pro via the Plugins menu. : aioseo()->cache->get( 'connect_active_user' ); // If there is no logged in user, we're upgrading via AIOSEO Connect. $user = get_userdata( $userId ); if ( is_object( $user ) ) { $capabilities = aioseo()->access->getCapabilityList(); foreach ( $capabilities as $capability ) { $user->add_cap( $capability ); } } aioseo()->cache->delete( 'connect_active_user' ); } }