From: Chuck Scott Date: Tue, 23 May 2017 19:19:20 +0000 (-0400) Subject: Added function to clear shortcode cache. X-Git-Tag: v2.9.16^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=cf461db18388a87439e5c984e782d0a1f1964d6a;p=WP-Plugins%2Fglm-member-db.git Added function to clear shortcode cache. Placed that function in all models that add, delete, or update member data. --- diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 873022ff..3b4a525b 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -571,6 +571,7 @@ function glmMembersFilterPhone( $config, $phone ) return $filteredNumber; } + /** * glmIsMemberModerated * @@ -598,3 +599,24 @@ function glmIsMemberModerated( $config, $wpdb, $memberID ) return false; } } + +/** + * glmClearShortcodeCache + * + * Clears all shortcode caching. Used by admin updates to force front-end output to be up-to-date. + * See caching code in front controller. + * + * @access public + * @return void + */ +function glmClearShortcodeCache() +{ + + global $wpdb; + + // Remove all cache entries from the database + $sql = "DELETE from ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cache;"; + $wpdb->query($sql); + + return; +} diff --git a/controllers/front.php b/controllers/front.php index ea329d5f..3eb19ab1 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -285,6 +285,18 @@ class glmMembersFront extends GlmPluginSupport // Enqueue all css here so that only happens when we're doing something $this->glmMembersFrontCSS(); + /* + * Shortcode Caching + * + * This feature saves all output from a shortcode into a single entry in the cache table. + * + * Caching is enabled/disabled on a shortcode by shortcode basis by setting the cacheControl array + * parameters in the shortcode definition array in "setup/shortcdes.php" for the related add-on. + * + * The glmClearShortcodeCache() function is used to clear all shortcode caching. This should normally + * be used when add, update, delete actions occur on information that could be cached. + */ + // If cache control not active, this must be the top-level page content request if (!$GLOBALS['cache_control']['active']) { diff --git a/models/admin/member/index.php b/models/admin/member/index.php index 3b82cad1..0122b769 100644 --- a/models/admin/member/index.php +++ b/models/admin/member/index.php @@ -309,6 +309,8 @@ class GlmMembersAdmin_member_index extends GlmDataMembers ;"; $this->wpdb->query($sql); + glmClearShortcodeCache(); + } diff --git a/models/admin/member/memberEdit.php b/models/admin/member/memberEdit.php index b84d11fd..d9b043a0 100644 --- a/models/admin/member/memberEdit.php +++ b/models/admin/member/memberEdit.php @@ -232,37 +232,41 @@ class GlmMembersAdmin_member_memberEdit extends GlmDataMembers $haveMember = true; + glmClearShortcodeCache(); + break; // Add the new member case 'addNew': - $memberData = $this->insertEntry(); + $memberData = $this->insertEntry(); - // If update was successful then use editEntry() to setup for the edit again. - if ($memberData['status']) { + // If update was successful then use editEntry() to setup for the edit again. + if ($memberData['status']) { - $this->memberID = $memberData['fieldData']['id']; + $this->memberID = $memberData['fieldData']['id']; - $slug = $this->updateSlug($this->memberID); + $slug = $this->updateSlug($this->memberID); - $memberData = $this->editEntry($this->memberID); - $memberUpdated = true; - $haveMember = true; + $memberData = $this->editEntry($this->memberID); + $memberUpdated = true; + $haveMember = true; - // Also update all member info records with any possible name change - $sql = " - UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info - SET member_name = '".addslashes($memberData['fieldData']['name'])."' - WHERE member = $this->memberID - ;"; - $this->wpdb->query($sql); + // Also update all member info records with any possible name change + $sql = " + UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info + SET member_name = '".addslashes($memberData['fieldData']['name'])."' + WHERE member = $this->memberID + ;"; + $this->wpdb->query($sql); - $memberName = $memberData['fieldData']['name']; + $memberName = $memberData['fieldData']['name']; + + } else { + $memberUpdateError = true; + } - } else { - $memberUpdateError = true; - } + glmClearShortcodeCache(); break; diff --git a/models/admin/member/memberInfo.php b/models/admin/member/memberInfo.php index fe893f1b..bc7411be 100644 --- a/models/admin/member/memberInfo.php +++ b/models/admin/member/memberInfo.php @@ -303,12 +303,12 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo $categories2[$k]['selected'] = false; } } - + // Check for action option - Should be one of the values in the "switch" statement below if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { $option = $_REQUEST['option']; } - + /* * Perform requested action */ @@ -371,6 +371,8 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo } + glmClearShortcodeCache(); + break; // Add the new member information record @@ -406,6 +408,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo do_action( 'glm-member-db-member-info-save-custom-fields', $this->memberInfoID ); } + glmClearShortcodeCache(); break; diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 61a247dc..c091a6c5 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -53,7 +53,7 @@ * 'menu' => '{menu name}', // Menu name in this context is simply where to find the action * 'action' => '{shortcode action name}, // Action used to execute this shortcode * 'table' => '{table prefix}{table name}', // Database table where default attribute values are stored - * 'cacheControl' => array( // Short code output cache control + * 'cacheControl' => array( // Short code output cache control - Most code for this is in front controller * 'active' => true, // Enable cache for this shortcode * 'cacheTime' => '1 HOUR' // Cache refresh time - MySQL "DATE_ADD" time interval - see https://www.w3schools.com/sql/func_date_add.asp * ), @@ -75,7 +75,7 @@ if ( isset( $config['settings'] ) && $config['settings']['enable_members'] ) { 'table' => GLM_MEMBERS_PLUGIN_DB_PREFIX.'settings_general', 'cacheControl' => array( 'active' => true, - 'cacheTime' => '30 DAYS' // MySQL "DATE_ADD" time interval - see https://www.w3schools.com/sql/func_date_add.asp + 'cacheTime' => '2 WEEK' // MySQL "DATE_ADD" time interval - see https://www.w3schools.com/sql/func_date_add.asp ), 'attributes' => array( 'type' => false,