From d609ceaa850daa597dcfbd88e815e1741bc96a01 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 26 Oct 2015 16:20:14 -0400 Subject: [PATCH] Fixed issues with deactivate/reactivate and crases on some searches --- activate.php | 12 ++++++++++-- classes/glmPluginSupport.php | 20 ++++++++++++-------- controllers/admin.php | 2 +- controllers/front.php | 4 +++- deactivate.php | 11 +++++++++++ defines.php | 5 ++--- glm-member-db.php | 5 +++++ lib/smartyTemplateSupport.php | 1 + uninstall.php | 14 ++++++++++---- 9 files changed, 55 insertions(+), 19 deletions(-) diff --git a/activate.php b/activate.php index db1fa886..21f340a1 100644 --- a/activate.php +++ b/activate.php @@ -14,6 +14,11 @@ * @link http://dev.gaslightmedia.com/ */ +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + // Load glmPluginSupport class require_once (GLM_MEMBERS_PLUGIN_PATH . '/classes/glmPluginSupport.php'); @@ -55,6 +60,11 @@ class glmMembersPluginActivate extends glmPluginSupport // This line is for dropping the currrent database version for testing // delete_option('glmMembersDatabaseDbVersion'); + // Check if there was an error and WP is calling us again + if ($this->checkErrorScrape()) { + exit; + } + // Make sure the current user has this capability if (! current_user_can('activate_plugins')) { $this->addNotice("Interesting, you don't have permission to activate plugins."); @@ -69,8 +79,6 @@ class glmMembersPluginActivate extends glmPluginSupport if (!$noDatabaseCheck) { - $this->checkErrorScrape(); - // Check the database and permit installation of a new database if it doesn't exist; if (!$this->checkDatabase('install')) { diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index a1d0c9b5..50cf02e3 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -164,15 +164,19 @@ class GlmPluginSupport } else { $installErrors = get_option('glmMembersInstallErrors'); - echo 'There has been an unknown error installing the Gaslight Media Members Database plugin.

'.$installErrors; + echo 'There has been an unknown error with the Gaslight Media Members Database plugin.

'.$installErrors; + delete_option('glmMembersInstallErrors'); + } // Quit here so Wordpress doesn't mark plugin as activated or deactivated - exit; + return true; } + return false; + } /* @@ -187,7 +191,6 @@ class GlmPluginSupport public function checkDatabase ($option = false) { - $dbVersion = get_option('glmMembersDatabaseDbVersion'); $db_setup_status = false; @@ -207,7 +210,8 @@ class GlmPluginSupport $existingTables = $this->wpdb->get_var(" SELECT COUNT(*) FROM information_schema.tables - WHERE table_name like '".GLM_MEMBERS_PLUGIN_DB_PREFIX."%'; + WHERE table_schema = 'explorewesternup' + AND table_name like '".GLM_MEMBERS_PLUGIN_DB_PREFIX."%'; "); // If there's no tables, just assume we need to install all new ones. @@ -226,7 +230,7 @@ class GlmPluginSupport // If glmMembersDatabaseDbVersion is not set, install current version if (!$dbVersion) { - +echo "111"; // If $option is not 'install', then don't do it; if ($option != 'install') { return false; @@ -273,7 +277,7 @@ class GlmPluginSupport // Otherwise, check if we need to update the database } elseif ($dbVersion != GLM_MEMBERS_PLUGIN_DB_VERSION) { - +echo "222"; // Include an admin message that we're updating the database $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' database tables require updating...'); @@ -361,8 +365,8 @@ class GlmPluginSupport } } else { -// $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' has been reactivated using the existing database tables.'); -// $db_setup_status = true; + $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' has been reactivated using the existing database tables.'); + $db_setup_status = true; } return $db_setup_status; diff --git a/controllers/admin.php b/controllers/admin.php index ca31c6bb..b5fa09a0 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -74,7 +74,7 @@ $GLOBALS['glmMembersAdminValidActions'] = array( require_once (GLM_MEMBERS_PLUGIN_PATH . '/classes/glmPluginSupport.php'); // Load Smarty Template Support -require (GLM_MEMBERS_PLUGIN_PATH . '/lib/smartyTemplateSupport.php'); +require_once (GLM_MEMBERS_PLUGIN_PATH . '/lib/smartyTemplateSupport.php'); /** * Admin Controller Class diff --git a/controllers/front.php b/controllers/front.php index 68cc9a7f..3bab226a 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -41,6 +41,9 @@ $GLOBALS['glmMembersFrontValidActions'] = array( // Load glmPluginSupport class require_once (GLM_MEMBERS_PLUGIN_PATH . '/classes/glmPluginSupport.php'); +// Load Smarty Template Support +require_once (GLM_MEMBERS_PLUGIN_PATH . '/lib/smartyTemplateSupport.php'); + /* * This class controls which models are use for front-end functionality * of this plugin. @@ -453,7 +456,6 @@ class glmMembersFront extends GlmPluginSupport */ // Load Smarty Template support - require (GLM_MEMBERS_PLUGIN_PATH . '/lib/smartyTemplateSupport.php'); $smarty = new smartyTemplateSupport(); // Add standard parameters diff --git a/deactivate.php b/deactivate.php index ed147704..6d62b89b 100644 --- a/deactivate.php +++ b/deactivate.php @@ -14,6 +14,11 @@ * @link http://dev.gaslightmedia.com/ */ +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + // Load glmPluginSupport class require_once (GLM_MEMBERS_PLUGIN_PATH . '/classes/glmPluginSupport.php'); @@ -52,6 +57,12 @@ class glmMembersPluginDeactivate extends glmPluginSupport die(); } + // Check if there was an error and WP is calling us again + if ($this->checkErrorScrape()) { + exit; + } + + // Save WordPress Database object $this->wpdb = $wpdb; diff --git a/defines.php b/defines.php index 6ae62067..714cd302 100644 --- a/defines.php +++ b/defines.php @@ -28,13 +28,12 @@ define('GLM_MEMBERS_PLUGIN_HTTP_PROTOCOL', $pageProtocol); $urlParts = parse_url(get_bloginfo('url')); $pageUri = explode('?', $_SERVER['REQUEST_URI']); // Bust this up to access URL path and script name only -$adminURL = admin_url('admin.php'); $WPUploadDir = wp_upload_dir(); // URLs -define('GLM_MEMBERS_SITE_BASE_URL', $pageProtocol.'://'.$urlParts['host'].$urlParts['path'].'/'); -define('GLM_MEMBERS_PLUGIN_ADMIN_URL', $adminURL); +define('GLM_MEMBERS_SITE_BASE_URL', home_url('/') ); define('GLM_MEMBERS_PLUGIN_URL', plugin_dir_url(__FILE__)); +define('GLM_MEMBERS_PLUGIN_ADMIN_URL', admin_url('admin.php')); define('GLM_MEMBERS_PLUGIN_BASE_URL', WP_PLUGIN_URL.'/'.GLM_MEMBERS_PLUGIN_DIR); define('GLM_MEMBERS_PLUGIN_CURRENT_URL', $urlParts['scheme'].'://'.$urlParts['host'].$pageUri[0]); define('GLM_MEMBERS_PLUGIN_MEDIA_URL', $WPUploadDir['baseurl'].'/'.GLM_MEMBERS_PLUGIN_DIR); diff --git a/glm-member-db.php b/glm-member-db.php index abbee61e..2e5871a1 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -181,6 +181,11 @@ define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.0.30'); * ******************************************************************************** */ +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + /* * Some initial setup and tests */ diff --git a/lib/smartyTemplateSupport.php b/lib/smartyTemplateSupport.php index e4e926f6..5163c4be 100644 --- a/lib/smartyTemplateSupport.php +++ b/lib/smartyTemplateSupport.php @@ -29,6 +29,7 @@ * new smartyTemplateSupport(); * */ + class smartyTemplateSupport { /** diff --git a/uninstall.php b/uninstall.php index a18599ff..49ffa279 100644 --- a/uninstall.php +++ b/uninstall.php @@ -14,12 +14,18 @@ * @link http://dev.gaslightmedia.com/ */ -// Get setup and configuration -require_once('defines.php'); +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} //if uninstall not called from WordPress exit -if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) - exit(); +if (!defined('WP_UNINSTALL_PLUGIN')) { + die("Sorry, uninstall must be called by WordPress!"); +} + +// Get setup and configuration +require_once('defines.php'); // Delete options delete_option('glmMembersDatabasePluginVersion'); -- 2.17.1