Auto page-creation on first activate
authorLaury GvR <laury@gaslightmedia.com>
Fri, 22 Apr 2016 19:21:34 +0000 (15:21 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 22 Apr 2016 19:21:34 +0000 (15:21 -0400)
activate.php
index.php

index a9d8ed7..4d0e1ba 100644 (file)
@@ -75,7 +75,7 @@ class glmMembersPluginActivate extends glmPluginSupport
 
         // Save plugin configuration object
         $this->config = $config;
-
+        
         if (!$noDatabaseCheck) {
 
             // Check the database  - allow installation of tables for a new add-on
@@ -93,6 +93,12 @@ class glmMembersPluginActivate extends glmPluginSupport
             update_option('glmMembersDatabasePluginVersion', GLM_MEMBERS_PLUGIN_VERSION);
 
         }
+        
+        if (get_option('glm_members_database_first_activation') == true) {
+            //update_option('glm_members_database_first_activation',false);
+                $this->createPages();
+        }
+
     }
 
     /*
@@ -196,5 +202,33 @@ class glmMembersPluginActivate extends glmPluginSupport
         }
 
     }
-
+    
+    /*
+     * Create new pages containing the member DB shortcodes
+     * 
+     * 
+     * @return void
+     * @access private
+     */
+    private function createPages() 
+    {
+        $member_pages = array(
+            'Members Page' => '[glm-members-list]',
+            'Member Detail' => '[glm-member-detail]'
+        );
+        foreach($member_pages as $pageName => $shortCode) {
+            $trimmedName = 'glm_members_database_'.str_replace(' ','_',strtolower($pageName));
+            if ( !get_post(get_option($trimmedName))) {
+                $new_page = array(
+                    'post_title' => $pageName,
+                    'post_content' => $shortCode,
+                    'post_status' => 'publish',
+                    'post_type' => 'page',
+                    'post_author' => '1'
+                );
+                $new_id = wp_insert_post($new_page);
+                update_option($trimmedName, $new_id);
+            }
+        }
+    }
 }
index b9ccc3d..96431a9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -213,6 +213,7 @@ 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