From 92b43b3aab68b45cdf64622d8bf9db6e8da925c3 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 6 Jun 2016 15:32:27 -0400 Subject: [PATCH 1/1] initial commit --- index.php | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..5990586 --- /dev/null +++ b/index.php @@ -0,0 +1,225 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 1.1.1 + */ + +/* + * Plugin and Database Versions + * + * Note that the database version matches the version of the last + * plugin version where there was a change in the database. + * + * Updates to checkDatabase() in glmPluginSupport.php must be + * made together with the DB_VERSION below. ONLY bump the DB + * version when there's a change in the database!! Use the + * version nunmber of that release for the DB version. + * + * We check the plugin version stored in the WordPress option below + * so that we're sure the other add-ons see an up to date + * version from this plugin. + */ +define('GLM_MEMBERS_SAMPLE_PLUGIN_VERSION', '0.0.7'); +// define('GLM_MEMBERS_SAMPLE_PLUGIN_DB_VERSION', '0.0.1'); + +// This is the minimum version of the GLM Members DB plugin require for this plugin. +define('GLM_MEMBERS_SAMPLE_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.57'); + +// Check if plugin version is not current in WordPress option and if needed updated it +if (GLM_MEMBERS_SAMPLE_PLUGIN_VERSION != get_option('glmMembersDatabaseSamplePluginVersion')) { + update_option('glmMembersDatabaseSamplePluginVersion', GLM_MEMBERS_SAMPLE_PLUGIN_VERSION); +} + +/* + * Copyright 2014 Charles Scott (email : cscott@gaslightmedia.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + +/* +* Some initial setup and tests +*/ + +$startupNotices = ''; + +// Get standard defined parameters +require_once('defines.php'); + +// 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 preliminary sanity checks + */ + +// 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 ' +
+

The '.GLM_MEMBERS_SAMPLE_PLUGIN_NAME.' add-on requires the base GLM Member DB plugin to be installed and active!

+

The '.GLM_MEMBERS_SAMPLE_PLUGIN_NAME.' plugin has been de-activated.

+
+ '; +} +$plugin_name = 'glm-member-db/index.php'; +$is_active = is_plugin_active($plugin_name); +if ($is_active != '1') { + add_action( 'admin_notices', 'glmMembersSamplePluginRequired' ); + deactivate_plugins('/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'/index.php'); +} + +// Check for Minimum DB version for main Member DB +function glmMembersPluginSampleMinVerRequired() { + echo ' +
+

The '.GLM_MEMBERS_SAMPLE_PLUGIN_NAME.' requires that the main GLM Member DB plugin version be no older than ' + .GLM_MEMBERS_SAMPLE_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.'!
+ '.GLM_MEMBERS_SAMPLE_MIN_VERSION_NOTE.'

+

The '.GLM_MEMBERS_SAMPLE_PLUGIN_NAME.' plugin has been de-activated.

+
+ '; +} +$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); + add_action( 'admin_notices', 'glmMembersPluginSampleMinVerRequired'); + deactivate_plugins('/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'.php'); +} + +/* + * Register this add-on with the main GLM Member DB plugin and get information on all add-ons loaded. + */ +require_once(GLM_MEMBERS_SAMPLE_PLUGIN_SETUP_PATH.'/validActions.php'); +require_once(GLM_MEMBERS_SAMPLE_PLUGIN_SETUP_PATH.'/shortcodes.php'); +if (is_file(GLM_MEMBERS_SAMPLE_PLUGIN_DB_SCRIPTS.'/dbVersions.php')) { + require_once(GLM_MEMBERS_SAMPLE_PLUGIN_DB_SCRIPTS.'/dbVersions.php'); +} + +// Load Sample Management Settings data +/* None - Need to figure out a smooth way to do this. +$sampleManagementSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A ); +unset($sampleManagementSettings['id']); +*/ + +function glmMembersRegisterSample($addOns) { + + // Add this add-on to the add-ons array + $addOns[GLM_MEMBERS_SAMPLE_PLUGIN_SLUG] = array( + 'dir' => GLM_MEMBERS_SAMPLE_PLUGIN_PATH, + 'name' => GLM_MEMBERS_SAMPLE_PLUGIN_NAME, + 'short_name' => GLM_MEMBERS_SAMPLE_PLUGIN_SHORT_NAME, + 'slug' => GLM_MEMBERS_SAMPLE_PLUGIN_SLUG, + 'actions' => $GLOBALS['glmMembersSampleAddOnValidActions'], + 'config' => array( + ), + 'shortcodes' => $GLOBALS['glmMembersSampleShortcodes'], + 'shortcodesDescription' => $GLOBALS['glmMembersSampleShortcodesDescription'] + ); + + // If we have database tables for this plugin/addon, provide that data also + if (isset($GLOBALS['glmMembersSampleDbVersions'])) { + $addOns[GLM_MEMBERS_SAMPLE_PLUGIN_SLUG]['database'] = array( + 'dbPrefix' => GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX, + 'dbCurrentVersion' => GLM_MEMBERS_SAMPLE_PLUGIN_DB_VERSION, + 'dbActiveVersionOption' => GLM_MEMBERS_SAMPLE_PLUGIN_ACTIVE_DB_OPTION, + 'dbScriptPath' => GLM_MEMBERS_SAMPLE_PLUGIN_DB_SCRIPTS, + 'dbVersions' => $GLOBALS['glmMembersSampleDbVersions'] + ); + } else { + $addOns[GLM_MEMBERS_SAMPLE_PLUGIN_SLUG]['database'] = false; + } + + // Return the array with our data added + return $addOns; +} +add_filter('glm-member-db-register-addon','glmMembersRegisterSample', 10, 1); + + /* + * + * Activate and Deactivate hooks + * + */ + + // Activate + function glmMembersSamplePluginActivate () + { + global $wpdb, $config; + require_once (GLM_MEMBERS_SAMPLE_PLUGIN_PATH . '/activate.php'); + new glmMembersSamplePluginActivate($wpdb, $config); + } + register_activation_hook(__FILE__, 'glmMembersSamplePluginActivate'); + + // Deactivate + function glmMembersSamplePluginDeactivate () + { + global $wpdb, $config; + require_once (GLM_MEMBERS_SAMPLE_PLUGIN_PATH . '/deactivate.php'); + $x = new glmMembersSamplePluginDeactivate($wpdb, $config); + return false; + } + register_deactivation_hook(__FILE__, 'glmMembersSamplePluginDeactivate'); + +/* + * Hooks for testing capabilities provided by this add-on + */ +require_once(GLM_MEMBERS_SAMPLE_PLUGIN_SETUP_PATH.'/permissions.php'); + -- 2.17.1