Added function to clear shortcode cache.
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 23 May 2017 19:19:20 +0000 (15:19 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 23 May 2017 19:19:20 +0000 (15:19 -0400)
Placed that function in all models that add, delete, or update member data.

classes/glmPluginSupport.php
controllers/front.php
models/admin/member/index.php
models/admin/member/memberEdit.php
models/admin/member/memberInfo.php
setup/shortcodes.php

index 873022f..3b4a525 100644 (file)
@@ -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;
+}
index ea329d5..3eb19ab 100644 (file)
@@ -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']) {
 
index 3b82cad..0122b76 100644 (file)
@@ -309,6 +309,8 @@ class GlmMembersAdmin_member_index extends GlmDataMembers
                      ;";
                      $this->wpdb->query($sql);
 
+                     glmClearShortcodeCache();
+
                 }
 
 
index b84d11f..d9b043a 100644 (file)
@@ -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;
 
index fe893f1..bc7411b 100644 (file)
@@ -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;
 
index 61a247d..c091a6c 100644 (file)
@@ -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,