Req. Page auto-creation config and function
authorLaury GvR <laury@gaslightmedia.com>
Thu, 28 Apr 2016 19:15:02 +0000 (15:15 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 28 Apr 2016 19:15:02 +0000 (15:15 -0400)
controllers/admin.php
index.php

index 1169539..df662f6 100644 (file)
@@ -209,6 +209,30 @@ class glmMembersAdmin extends GlmPluginSupport
 
 
     }
+    /*
+     * Create new pages containing the member DB shortcodes
+     * @return void
+     */
+    public function createPages($requiredPages) 
+    {
+        foreach($requiredPages as $requiredPage => $requiredPageInfo) {
+            //foreach($requiredPageInfo as $key => $value) {
+            $trimmedName = 'glm_members_database_'.str_replace(' ','_',strtolower($requiredPage)).'_id';
+            if ( !get_post(get_option($trimmedName))) {
+                $new_page = array(
+                    'post_title' => $requiredPage,
+                    'post_content' => $requiredPageInfo['content'],
+                    'post_status' => 'publish',
+                    'post_type' => 'page',
+                    'post_author' => '1',
+                    'page_template' => isset($requiredPageInfo['template']) ? $requiredPageInfo['template'] : 'index.php' ,
+                    'post_parent' => $requiredPageInfo['parent'] !== '0' ? get_option('glm_members_database_glm_associate_id') : '0'
+                );
+                $new_id = wp_insert_post($new_page);
+                update_option($trimmedName, $new_id);
+            }
+        }
+    }
 
 
     /**
@@ -684,6 +708,13 @@ class glmMembersAdmin extends GlmPluginSupport
             }
         }
 
+        foreach ($this->config['addOns'] as $a) {
+            //
+            if (isset($a['required_pages'])) {
+                $this->createPages($a['required_pages']);
+            }
+        }
+        
         // Loop till we have a final action
         $loopCheck = 0;
         $loopTracking = "<p>Menu: $menuItem, Action = $action</p>";
index 96431a9..3f53a72 100644 (file)
--- a/index.php
+++ b/index.php
@@ -213,7 +213,6 @@ require_once('config.php');
 // Try to set the DB version option to false (new plugin) - If it's already set this won't do anything.
 add_option('glmMembersDatabaseDbVersion', false);
 
-add_option('glm_members_database_first_activation', true);
 /*
  *
  * Hook in add-ons and integrate their actions
@@ -289,6 +288,27 @@ $config['addOns'] = array(
             'dbActiveVersionOption' => GLM_MEMBERS_PLUGIN_ACTIVE_DB_OPTION,
             'dbScriptPath' => GLM_MEMBERS_PLUGIN_DB_SCRIPTS,
             'dbVersions' => $glmMembersDbVersions
+        ),
+        'required_pages' => array(
+            // These should be in GLM Associate
+            'GLM Associate' => array(
+                'content' => '',
+                'parent' => '0'
+            ),
+            // These should be in GLM Members
+            'Members Only' => array(
+                'content' => 'This page and any child beneath it will automatically be locked to Members Only with the members-only-template.',
+                'parent' => '0',
+                'template' => 'glm-members-only-template.php'
+            ),
+            'Members List' => array(
+                'content' => '[glm-members-list]',
+                'parent' => 'GLM Associate'
+            ),
+            'Member Detail' => array(
+                'content' => '[glm-member-detail]',
+                'parent' => 'GLM Associate'
+            )
         )
     )
 );
@@ -318,7 +338,7 @@ if (count($config['addOns']) > 0) {
         if (isset($a['config'])) {
             $config = array_merge_recursive($config, $a['config']);
         }
-
+        
         // If the add-on has additional config parameters in a plugin.ini file
         $iniFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.'/'.$a['slug'].'/config/plugin.ini';
         if (isset($iniFile)) {