Implement management option for having multiple active profiles
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Apr 2017 12:26:54 +0000 (08:26 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Apr 2017 12:26:54 +0000 (08:26 -0400)
Adding enable_multiple_profiles to data abstract for settingsGeneral.
Updating the database version number to 1.1.30
Add check for enable_multiple_profile to be off before trying to reset
all other member profiles for the member to inactive.
Adding new rewrite rule for appending the member info id to the member
detail url's.

classes/data/settings/dataSettingsGeneral.php
index.php
models/admin/member/index.php
models/admin/member/memberInfo.php
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V1.1.30.sql
setup/frontHooks.php
views/admin/management/index.html

index f5ab9bc..005c735 100644 (file)
@@ -233,6 +233,13 @@ class GlmDataSettingsGeneral extends GlmDataAbstract
                 'use' => 'a'
             ),
 
+            // Enable Multiple Active Profiles
+            'enable_multiple_profiles' => array(
+                'field' => 'enable_multiple_profiles',
+                'type' => 'checkbox',
+                'use' => 'a'
+            ),
+
             /*
              * Member Info edit tab selection
              */
index d6ccbed..e5abbec 100644 (file)
--- a/index.php
+++ b/index.php
@@ -39,7 +39,7 @@
  */
 
 define('GLM_MEMBERS_PLUGIN_VERSION', '2.9.14');
-define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.1.29');
+define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.1.30');
 
 // Check if plugin version is not current in WordPress option and if needed updated it
 if (GLM_MEMBERS_PLUGIN_VERSION != get_option('glmMembersDatabasePluginVersion')) {
index 562d295..3b82cad 100644 (file)
@@ -292,13 +292,15 @@ class GlmMembersAdmin_member_index extends GlmDataMembers
                 // If we do, then activate it
                 if($idTest != null) {
 
-                     $sql = "
-                         UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info
-                            SET status = ".$this->config['status_numb']['Inactive']."
-                          WHERE member = $memberID
-                            AND status = ".$this->config['status_numb']['Active']."
-                     ;";
-                     $this->wpdb->query($sql);
+                    if ( !$this->config['settings']['enable_multiple_profiles'] ) {
+                         $sql = "
+                             UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info
+                                SET status = ".$this->config['status_numb']['Inactive']."
+                              WHERE member = $memberID
+                                AND status = ".$this->config['status_numb']['Active']."
+                         ;";
+                         $this->wpdb->query($sql);
+                    }
 
                      $sql = "
                          UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info
index 38f99bb..a9a2dad 100644 (file)
@@ -215,7 +215,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo
         $memberUpdated                     = false;
         $memberUpdateError                 = false;
         $categories                        = false;
-        $multipleProfileEnabeled           = true;
+        $multipleProfileEnabeled           = $this->config['settings']['enable_multiple_profiles'];
 
         // Check for action option - Should be one of the values in the "switch" statement below
         $option = false;
index 1da40a3..de82af3 100644 (file)
@@ -60,7 +60,8 @@ $glmMembersDbVersions = array(
     '1.1.26' => array('version' => '1.1.26', 'tables' => 18, 'date' => '03/08/17'),
     '1.1.27' => array('version' => '1.1.27', 'tables' => 19, 'date' => '03/29/17'),
     '1.1.28' => array('version' => '1.1.28', 'tables' => 19, 'date' => '04/04/17'),
-    '1.1.29' => array('version' => '1.1.29', 'tables' => 19, 'date' => '04/10/17')
+    '1.1.29' => array('version' => '1.1.29', 'tables' => 19, 'date' => '04/10/17'),
+    '1.1.30' => array('version' => '1.1.30', 'tables' => 19, 'date' => '04/12/17')
 );
 
 
index 599cf05..e113e3d 100644 (file)
@@ -1,6 +1,6 @@
 -- Gaslight Media Members Database
--- File Created: 03/29/17
--- Database Version: 1.1.29
+-- File Created: 04/12/17
+-- Database Version: 1.1.30
 -- Database Update From Previous Version Script
 --
 -- To permit each query below to be executed separately,
index 7f80dde..3ee03cb 100644 (file)
 add_filter( 'rewrite_rules_array', function($rules) {
     $newrules = array();
     $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)/([^/]*)$']='index.php?pagename=$matches[1]&memberslug=$matches[2]&profile=$matches[3]';
-    $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$']='index.php?pagename=$matches[1]&memberslug=$matches[2]';
+    if ( isset( $this->config['settings']['enable_multiple_profiles'] ) && $this->config['settings']['enable_multiple_profiles'] ) {
+        $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$']='index.php?pagename=$matches[1]&memberslug=$matches[2]';
+    }
     return $newrules + $rules;
 });
 add_filter( 'query_vars', function($vars) {
     array_push($vars, 'memberslug');
-    array_push($vars, 'profile');
+    if ( isset( $this->config['settings']['enable_multiple_profiles'] ) && $this->config['settings']['enable_multiple_profiles'] ) {
+        array_push($vars, 'profile');
+    }
     return $vars;
 });
 add_action('wp_loaded', function() {
@@ -45,7 +49,7 @@ add_action('wp_loaded', function() {
         global $wp_rewrite;
         $wp_rewrite->flush_rules();
     }
-    if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)/([^/]*)$'] ) ) {
+    if ( isset( $this->config['settings']['enable_multiple_profiles'] ) && $this->config['settings']['enable_multiple_profiles'] && ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)/([^/]*)$'] ) ) {
         trigger_error('Doing rewrite flush - Member detail page', E_USER_NOTICE); // Logging that this is happening so we can track when that happens.
         global $wp_rewrite;
         $wp_rewrite->flush_rules();
index d8806fe..2ca5d40 100644 (file)
                     <input type="checkbox" name="enable_counties"{if $genSettings.fieldData.enable_counties.value} checked="checked"{/if}>
                 </td>
             </tr>
+            <tr>
+                <th>Enable Multiple Active Member Profiles:</th>
+                <td>
+                    <input type="checkbox" name="enable_multiple_profiles"{if $genSettings.fieldData.enable_multiple_profiles.value} checked="checked"{/if}>
+                </td>
+            </tr>
             <tr>
                 <th>Member Info Tabs Selection:</th>
                 <td>
                     </table>
                 </td>
             </tr>
-            
+
             <tr><td colspan="2"><h2>Misc. Settings</h2></td></tr>
             <tr>
                 <th {if $genSettings.fieldRequired.google_maps_api_key}class="glm-required"{/if}>Google Maps API Key:</th>