// Required to be able to get user capabilities when being called as a filter from the main plugin
require_once(ABSPATH . 'wp-includes/pluggable.php');
+// Include defines to tell if a plugin is active
+include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
+
/*
- * Do some checks to make sure the main GLM Member DB is active and of a recceint enough version
+ * Do some preliminary sanity checks
*/
-// Function to generate message regarding main GLM Member DB plugin not installed and active
+// Check if database version should be defined and it isn't - This would be a plugin/add-on setup issue
+if (is_file(GLM_MEMBERS_SAMPLE_PLUGIN_PATH.'/setup/databaseScripts/dbVersions.php') && !defined('GLM_MEMBERS_SAMPLE_PLUGIN_DB_VERSION')) {
+ die('You have database scripts but have not defined a current database version at the top of index.php for this plugin/add-on!');
+}
+
+// Check for main plugin and that it's active
function glmMembersSamplePluginRequired() {
echo '
<div class="error">
</div>
';
}
-
-/*
- * Check installation, activation, and version of main Member DB plugin
- */
-include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$plugin_name = 'glm-member-db/glm-member-db.php';
$is_active = is_plugin_active($plugin_name);
-
-// If it's not active, then warn user and deactivate this add-on plugin
if ($is_active != '1') {
add_action( 'admin_notices', 'glmMembersSamplePluginRequired' );
deactivate_plugins('/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'.php');
}
-// Function to generate message regarding main GLM Member DB plugin version is not receint enought to run this add-on
+// Check for Minimum DB version for main Member DB
function glmMembersPluginSampleMinVerRequired() {
echo '
<div class="error">
</div>
';
}
-
-/*
- * Check for Minimum DB version for main Member DB
- */
$glmMembersDatabasePluginVersion = get_option('glmMembersDatabasePluginVersion');
if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_SAMPLE_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION) < 0) {
define('GLM_MEMBERS_SAMPLE_MIN_VERSION_NOTE', "Members DB: $glmMembersDatabasePluginVersion, Sample Requires: ".GLM_MEMBERS_SAMPLE_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION);
* 'GLM Sample', // Menu Title
* 'glm-members-members', // Capability
* 'glm-members-admin-menu-glm-sample', // Menu Slug
- * function() {$this->controller('sample');}, // Called function
+ * function() {$this->controller('sample');}, // Called function - typically controller() with the menu name
* false, // Icon URL
* '92' // Menu Position
* );
+++ /dev/null
--- Gaslight Media Members Database - Sample
--- File Created: 12/02/15 15:27:15
--- Database Version: 0.0.1
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most receint database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
-
--- **********************************************************************
--- NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED
---
--- Please change all references to sample, Sample, or SAMPLE to a name
--- appropriate for your new Add-On.
---
--- Tables and queries in this file are sample only.
---
--- Remove this message before using this file in production!
--- **********************************************************************/
-
-
--- Sample Management Settings
-CREATE TABLE {prefix}management (
- id INT NOT NULL AUTO_INCREMENT,
- canonical_sample_page TINYTEXT NULL, -- Canonical page slug for detail
- PRIMARY KEY (id)
-);
-
-----
-
--- Set default sample management entry
-INSERT INTO {prefix}management
- ( id, canonical_sample_page )
- VALUES
- ( 1, 'sample data' )
-;
-
+++ /dev/null
-<?php
-/**
- * Gaslight Media Members Database
- * GLM Members Sample DB Versions
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @release dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
- * @link http://dev.gaslightmedia.com/
- */
-
-
-/**********************************************************************
- * NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED
- *
- * Please change all references to sample, Sample, or SAMPLE to a name
- * appropriate for your new Add-On.
- *
- * This file lists all versions of the database tables for this add-on.
- * The last entry in the array below should be for the most recent
- * version and should match the "create_database_V..." file in this
- * directory.
- *
- * NOTE: When first creating a new add-on with database tables, there
- * should only be one line in the array below and there should be no
- * "update_database..." files in this directory.
- *
- * Remove this message before using this file in production!
- **********************************************************************/
-
-
-$glmMembersSampleDbVersions = array(
- '0.0.1' => array('version' => '0.0.1', 'tables' => 2),
- '0.0.2' => array('version' => '0.0.2', 'tables' => 3)
-);
-
+++ /dev/null
-<?php
-/*
- * Gaslight Media Members Database - Sample Add-On
- *
- * Database Update Script for version 0.0.2
- */
-
-/**********************************************************************
- * NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED
- *
- * Please change all references to sample, Sample, or SAMPLE to a name
- * appropriate for your new Add-On.
- *
- * This is a sample database update process. There should be an SQL
- * script for each update in this directory. This php file is optionsl
- * and can be used to perform more complex data updates.
- *
- * If this file exists, it is called after the matching SQL script has
- * been run.
- *
- * ******** THE CODE BELOW IS STICTLY A SAMPLE ********
- *
- * Remove this message before using this file in production!
- **********************************************************************/
-
-/*
- * Update sample records to build sample_slug field data from title
- */
-
-// Get all sample records
-$sampleRecords = $this->wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'samples;', ARRAY_A);
-
-// If there's any sample records
-if ($sampleRecords && count($sampleRecords) > 0) {
-
- // For each sample record
- foreach ($sampleRecords as $p) {
-
- // Create a slug from the title
- $slug = sanitize_title($p['title']).'-'.$p['id'];
-
- // Store this value back into the record
- $this->wpdb->update(
- GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'samples',
- array(
- 'sample_slug' => $slug
- ),
- array( 'id' => $p['id'] ),
- array( '%s' ),
- array( '%d')
- );
- }
-
-}
+++ /dev/null
--- Gaslight Media Members Database
--- File Created: 12/09/14 15:27:15
--- Database Version: 0.0.2
--- Database Update From Previous Version Script
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashses
-
--- Package Management Settings
-CREATE TABLE {prefix}management (
- id INT NOT NULL AUTO_INCREMENT,
- canonical_package_page TINYTEXT NULL, -- Canonical page slug for package detail
- PRIMARY KEY (id)
-);
-
-----
-
--- Set default package management entry
-INSERT INTO {prefix}management
- ( id, canonical_package_page )
- VALUES
- ( 1, 'package-detail' )
-;
-
-----
-
-ALTER TABLE {prefix}packages ADD COLUMN package_slug TINYTEXT;
-
-
-
--- /dev/null
+-- Gaslight Media Members Database - Sample
+-- File Created: 12/02/15 15:27:15
+-- Database Version: 0.0.1
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most receint database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+-- **********************************************************************
+-- NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED
+--
+-- Please change all references to sample, Sample, or SAMPLE to a name
+-- appropriate for your new Add-On.
+--
+-- Tables and queries in this file are sample only.
+--
+-- Remove this message before using this file in production!
+-- **********************************************************************/
+
+
+-- Sample Table
+CREATE TABLE {prefix}sometablename (
+ id INT NOT NULL AUTO_INCREMENT,
+ somefield TINYTEXT NULL,
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Sample default entry in table
+INSERT INTO {prefix}sometablename
+ ( id, somefield )
+ VALUES
+ ( 1, 'sample data' )
+;
+
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Sample DB Versions
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+
+/**********************************************************************
+ * NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED
+ *
+ * Please change all references to sample, Sample, or SAMPLE to a name
+ * appropriate for your new Add-On.
+ *
+ * This file lists all versions of the database tables for this add-on.
+ * The last entry in the array below should be for the most recent
+ * version and should match the "create_database_V..." file in this
+ * directory.
+ *
+ * NOTE: When first creating a new add-on with database tables, there
+ * should only be one line in the array below and there should be no
+ * "update_database..." files in this directory.
+ *
+ * Remove this message before using this file in production!
+ **********************************************************************/
+
+
+$glmMembersSampleDbVersions = array(
+ '0.0.1' => array('version' => '0.0.1', 'tables' => 1),
+ '0.0.2' => array('version' => '0.0.2', 'tables' => 2)
+);
+
--- /dev/null
+DATABASE EXAMPLE FILES
+----------------------
+
+*** THESE ARE EXAMPLES ONLY ***
+
+The files in this directory are examples only. Do not use any of these as they are!
+
+The example here is of a set of one table for the add-on that is initially created
+by the create_database_V0.0.1.sql script. That file creates one table and inserts
+one entry into that table.
+
+In this example, the database is later updated by two files. Either of these may
+be included separately if only a PHP file is needed to update the database, or
+just an SQL script. Sometimes both are needed.
+
+There is also an entry in the dbVersions.php file that describes the update.
+
+Note that the number of tables needs to be set to the updated number for each update.
+
+Also note taht the SQL update scripts are run before the PHP update scripts.
+
--- /dev/null
+<?php
+/*
+ * Gaslight Media Members Database - Sample Add-On
+ *
+ * Database Update Script for version 0.0.2
+ */
+
+/**********************************************************************
+ * NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED
+ *
+ * Please change all references to sample, Sample, or SAMPLE to a name
+ * appropriate for your new Add-On.
+ *
+ * This is a sample database update process. There should be an SQL
+ * script for each update in this directory. This php file is optionsl
+ * and can be used to perform more complex data updates.
+ *
+ * If this file exists, it is called after the matching SQL script has
+ * been run.
+ *
+ * ******** THE CODE BELOW IS STICTLY A SAMPLE ********
+ *
+ * Remove this message before using this file in production!
+ **********************************************************************/
+
+/*
+ * Update sample records to take data from one field, change it, then store it in the new field
+ */
+
+// Get all records from the sometablename table.
+$sampleRecords = $this->wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'sometablename;', ARRAY_A);
+
+// If there's any records
+if ($sampleRecords && count($sampleRecords) > 0) {
+
+ // For each record
+ foreach ($sampleRecords as $p) {
+
+ // Create a slug from the somefield field
+ $newData = sanitize_title($p['somefield']).'-'.$p['id'];
+
+ // Store this value back into the record in the new yetanotherfield field
+ $this->wpdb->update(
+ GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'sometablename',
+ array(
+ 'yetanotherfield' => $slug
+ ),
+ array( 'id' => $p['id'] ),
+ array( '%s' ),
+ array( '%d')
+ );
+ }
+
+}
--- /dev/null
+-- Gaslight Media Members Database
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.2
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashses
+
+-- A sample database update script
+CREATE TABLE {prefix}anothertablename (
+ id INT NOT NULL AUTO_INCREMENT,
+ anotherfield TINYTEXT NULL,
+ PRIMARY KEY (id)
+);
+
+----
+
+ALTER TABLE {prefix}sometablename ADD COLUMN yetanotherfield TINYTEXT;
+
+
+
This directory contains database creation and update scripts for this add-on.
-This directly is optional. If there are no data tables added by this add-on,
-this directory should be omitted.
+The files in this directory are checked by the checkDatabase() function in the
+main plugin classes/glmPluginSupport.php file.
+
+This directory is optional. If there are no data tables that need to be created
+for this add-on, there should be no files in this directory. The directory may
+also be deleted.
+
+See the "examples" directory for a sample of what can go in this directory.