public function activate() { global $wpdb; ob_start(); $error = ""; if ($this->createDBCache()) { if ($this->updateMemberMouseClass()) { // reset minor version if this is a major version upgrade $crntMajorVersion = MemberMouse::getPluginVersion(); $lastMajorVersion = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_MAJOR_VERSION); if (!empty($lastMajorVersion) && version_compare($lastMajorVersion, $crntMajorVersion) < 0) { MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_MINOR_VERSION, MM_MemberMouseService::$DEFAULT_MINOR_VERSION); } if ($this->authenticateWithMM() !== false) { if ($this->alterMMTables()) { $this->temporaryRestoreOrderItemAccessPatch(); $this->temporaryPendingOverdueSubscriptionPatch(); $this->populateOriginAffiliateIds(); if ($this->insertMMDefaultData()) { // set new major version $crntMajorVersion = MemberMouse::getPluginVersion(); MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_MAJOR_VERSION, $crntMajorVersion); //update version history $versionDescription = $crntMajorVersion; $minorVersion = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_MINOR_VERSION); if ($minorVersion !== false && intval($minorVersion) > 0) { $versionDescription .= "-" . $minorVersion; } else { $versionDescription .= "-" . MM_MemberMouseService::$DEFAULT_MINOR_VERSION; } $versionRelease = MM_VersionRelease::findByVersion($versionDescription); $versionRelease->setVersion($versionDescription); $versionRelease->commitData(); MM_MemberMouseService::activatePlugin(); // clear major version notice $crntMajorVersion = MemberMouse::getPluginVersion(); $upgradeVersion = MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_UPGRADE_NOTICE); if (!empty($upgradeVersion) && version_compare($crntMajorVersion, $upgradeVersion, ">=")) { MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_UPGRADE_NOTICE, ""); } ob_end_clean(); return true; } else { $error = "Could not install default data."; } } else { $error = "Could not alter MemberMouse tables."; } } else { $error = "<div style='font-family: sans-serif; font-size: 13px;'>"; $error .= "<h3 style='color:#BC0B0B; margin-top:0px; margin-bottom:5px; font-size: 14px;'>This site is not authorized to use the MemberMouse plugin</h3>"; $error .= "<p style='margin-top:0px; margin-bottom:5px;'>In order to use the MemberMouse plugin you need to <a href=\"https://membermouse.uservoice.com/knowledgebase/articles/319186-installing-membermouse\" target=\\_blank\">register your site with membermouse.com</a>.</p>"; $error .= "</div>"; } } else { $error = "Could not insert MM_MemberMouseService into DB cache"; } } else { $error = "Could not create DB cache"; } ob_end_clean(); // an error occurred so deactivate the plugin $this->showError($error); exit; }