From: Chuck Scott Date: Sun, 29 Nov 2015 22:29:48 +0000 (-0500) Subject: initial commit X-Git-Tag: v0.0.1~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d53d66db80a1844643135d41a16df0316dcf2088;p=WP-Plugins%2Fglm-member-db-packaging.git initial commit --- d53d66db80a1844643135d41a16df0316dcf2088 diff --git a/activate.php b/activate.php new file mode 100644 index 0000000..ccc381b --- /dev/null +++ b/activate.php @@ -0,0 +1,155 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release activate.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + +/* + * This class performs all necessary additional work when this + * plugin is activated. + * + * Currently the only actions are to add role capability to display and modify + * prototypes. + */ +class glmMembersPackagingPluginActivate +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * Note that the $noDatabaseCheck is used to access the database versions + * without triggering a database check. + * + * Performs all the work for this model + */ + public function __construct ($wpdb, $config) + { + + // Make sure the current user has this capability + if (! current_user_can('activate_plugins')) { + $this->addNotice("Interesting, you don't have permission to activate plugins."); + die(); + } + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Set current plugin version + update_option('glmMembersDatabasePackagingPluginVersion', GLM_MEMBERS_PACKAGING_PLUGIN_VERSION); + + // Set Roles and Capabilities for this plugin + require_once(GLM_MEMBERS_PACKAGING_PLUGIN_SETUP_PATH.'/rolesAndCapabilities.php'); + } + + /* + * Add a capability to all current roles + * + * @param string $capability Name of capability to add + * @param array $default Whether capability should be on by default + * array( + * 'author' => false, + * 'contributor' => false, + * 'editor' => false, + * 'subscriber' => false + * ) + * + * @return void + * @access private + */ + private function addRoleCapability($capability, $default) + { + // Get list of role objects + $roleObjects = $GLOBALS['wp_roles']->role_objects; + + // Get list of roles we can edit + $roles = get_editable_roles(); + + // For each role object + foreach ($roleObjects as $key => $role) { + + // Check if the role exists in list of editable roles and + // the capability does not exist + if (isset($roles[$key]) && ! isset($role->capabilities[$capability])) { + + // Check if a default value has been specified in the $default array + $enabled = false; + if (isset($default[$role->name])) { + + // It has, so use that + $enabled = $default[$role->name]; + + } + + // Add the role + $role->add_cap($capability, $enabled); + + } + } + } + + + /* + * Delete a capability from all current roles + * + * @param string $capability Name of capability to add + * + * @return void + * @access private + */ + private function deleteRoleCapability($capability) + { + // Get list of role objects + $roleObjects = $GLOBALS['wp_roles']->role_objects; + + // Get list of roles we can edit + $roles = get_editable_roles(); + + // For each role object + foreach ($roleObjects as $key => $role) { + + if ( isset($role->capabilities[$capability])) { + $role->remove_cap($capability); + } + + } + + } + + + +} + +?> diff --git a/config/plugin.ini b/config/plugin.ini new file mode 100644 index 0000000..8fdb6a8 --- /dev/null +++ b/config/plugin.ini @@ -0,0 +1,6 @@ +; +; Main Configuration File +; Gaslight Media Members Database Packaging Add-On Plugin +; + +[common] diff --git a/deactivate.php b/deactivate.php new file mode 100644 index 0000000..ad35600 --- /dev/null +++ b/deactivate.php @@ -0,0 +1,63 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + +/* + * This class performs all necessary additional work when this + * plugin is deactivated. + */ +class glmMembersPackagingPluginDeactivate +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * Performs all the work for this model + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Delete our version from WordPress Options + delete_option('glmMembersDatabasePackagingPluginVersion'); + } + +} + +?> \ No newline at end of file diff --git a/defines.php b/defines.php new file mode 100644 index 0000000..312406f --- /dev/null +++ b/defines.php @@ -0,0 +1,61 @@ +prefix.'glm_members_'); + + +// Parameters related to the Main GLM Member DB plugin - Depending on what's going on these may already defined by the main plugin +$pluginsPath = str_replace(GLM_MEMBERS_PACKAGING_PLUGIN_SLUG, '', GLM_MEMBERS_PACKAGING_PLUGIN_PATH); +define('GLM_MEMBERS_PACKAGING_MAIN_PLUGIN_PATH', $pluginsPath.'/glm-member-db'); +define('GLM_MEMBERS_PACKAGING_PLUGIN_LIB_PATH', GLM_MEMBERS_PACKAGING_MAIN_PLUGIN_PATH.'/lib'); +define('GLM_MEMBERS_PACKAGING_PLUGIN_MEDIA_PATH', $WPUploadDir['basedir'].'/'.GLM_MEMBERS_PACKAGING_PLUGIN_SLUG); +define('GLM_MEMBERS_PACKAGING_PLUGIN_IMAGES_PATH', GLM_MEMBERS_PACKAGING_MAIN_PLUGIN_PATH.'/images'); + +?> diff --git a/glm-member-db-packaging.php b/glm-member-db-packaging.php new file mode 100644 index 0000000..4f83c29 --- /dev/null +++ b/glm-member-db-packaging.php @@ -0,0 +1,174 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.0.0 + */ + +/* + * 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. + */ +define('GLM_MEMBERS_PACKAGING_PLUGIN_VERSION', '0.0.0'); + +// This is the minimum version of the GLM Members DB plugin require for this plugin. +define('GLM_MEMBERS_PACKAGING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.43'); + +/* + * 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'); + +/* + * Do some checks to make sure the main GLM Member DB is active and of a recceint enough version + */ + +// Function to generate message regarding main GLM Member DB plugin not installed and active +function glmMembersPackagingPluginRequired() { + echo ' +
+

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

+

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

+
+ '; +} + +/* + * 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', 'glmMembersPackagingPluginRequired' ); + deactivate_plugins('/'.GLM_MEMBERS_PACKAGING_PLUGIN_SLUG.'/'.GLM_MEMBERS_PACKAGING_PLUGIN_SLUG.'.php'); +} + +// Function to generate message regarding main GLM Member DB plugin version is not receint enought to run this add-on +function glmMembersPluginMinVerRequired() { + echo ' +
+

The '.GLM_MEMBERS_PACKAGING_PLUGIN_NAME.' requires that the main GLM Member DB plugin version be no older than ' + .GLM_MEMBERS_PACKAGING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.'!

+

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

+
+ '; +} + +/* + * Check for Minimum DB version for main Member DB + */ +$glmMembersDatabasePluginVersion = get_option('glmMembersDatabasePluginVersion'); +if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_PACKAGING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION) < 0) { + add_action( 'admin_notices', 'glmMembersPluginMinVerRequired'); + deactivate_plugins('/'.GLM_MEMBERS_PACKAGING_PLUGIN_SLUG.'/'.GLM_MEMBERS_PACKAGING_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_PACKAGING_PLUGIN_SETUP_PATH.'/validActions.php'); +function glmMembersRegisterPackaging($addOns) { + + // Add this add-on to the add-ons array + $addOns[GLM_MEMBERS_PACKAGING_PLUGIN_SLUG] = array( + 'dir' => GLM_MEMBERS_PACKAGING_PLUGIN_PATH, + 'name' => GLM_MEMBERS_PACKAGING_PLUGIN_NAME, + 'short_name' => GLM_MEMBERS_PACKAGING_PLUGIN_SHORT_NAME, + 'slug' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG, + 'actions' => $GLOBALS['glmMembersAddOnValidActions'] + ); + + // Return the array with our data added + return $addOns; +} +add_filter('glm-member-db-register-addon','glmMembersRegisterPackaging', 10, 1); + + /* + * + * Activate and Deactivate hooks + * + */ + + // Activate + function glmMembersPackagingPluginActivate () + { + global $wpdb, $config; + require_once (GLM_MEMBERS_PACKAGING_PLUGIN_PATH . '/activate.php'); + new glmMembersPackagingPluginActivate($wpdb, $config); + } + register_activation_hook(__FILE__, 'glmMembersPackagingPluginActivate'); + + // Deactivate + function glmMembersPackagingPluginDeactivate () + { + global $wpdb, $config; + require_once (GLM_MEMBERS_PACKAGING_PLUGIN_PATH . '/deactivate.php'); + $x = new glmMembersPackagingPluginDeactivate($wpdb, $config); + return false; + } + register_deactivation_hook(__FILE__, 'glmMembersPackagingPluginDeactivate'); + +/* + * Hooks for testing capabilities provided by this add-on + */ +require_once(GLM_MEMBERS_PACKAGING_PLUGIN_SETUP_PATH.'/permissions.php'); + + +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..4e6c07c --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/misc/documentation/CreateNewAddOn.txt b/misc/documentation/CreateNewAddOn.txt new file mode 100644 index 0000000..98089a9 --- /dev/null +++ b/misc/documentation/CreateNewAddOn.txt @@ -0,0 +1,22 @@ +Proceedure to create a new GLM Members add-on plugin +---------------------------------------------------- + +* Checkout glm-member-db-blank and rename directory to glm-member-db-{addon name} + +* Rename glm-member-db-blank.php to glm-member-db-{addon name}.php + +* Search for an update any "GLM_MEMBERS_BLANK_" defines and references + +* Update defines.php and replace references to "blank" + +* deactivate.php - update "delete_option" at the bottom to reflect correct name + +* Change references to "glmMembersBlankPluginMinVerRequired" + +* Update all remaining references to the "blank" add-on name + +* Reset version number to 0.0.0 + +* Create new repository named WP-Plugins/glm-member-db-{name of add-on}.git + + \ No newline at end of file diff --git a/models/admin/sample/index.php b/models/admin/sample/index.php new file mode 100644 index 0000000..4a64cd6 --- /dev/null +++ b/models/admin/sample/index.php @@ -0,0 +1,81 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * This model is called when the "Shortcodes" menu is selected + * + */ +class GlmMembersAdmin_sample_index +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + + /* + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + public function modelAction($actionData = false) { + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/sample/index.html', + 'data' => false + ); + + } +} + +?> \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..b541db5 --- /dev/null +++ b/readme.txt @@ -0,0 +1,27 @@ +=== Gaslight Media Member Database Packaging Child Plugin === +Contributors: cscott@gaslightmedia.com +Donate link: http://www.gaslightmedia.com +Tags: Gaslight Media,Plugin,Members Packaging +Requires at least: 3.0.1 +Tested up to: 3.4 +Stable tag: 4.3 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +This is the Gaslight Media Members Database Packaging Child Plugin. + +== Description == + +The Gaslight Media Members Database Packaging Child Plugin is an add-on to the Gaslight Media Members Database, +which is required to install and run this plugin + +== Installation == + +This section describes how to install the plugin and get it working. + +e.g. + +1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory +1. Activate the plugin through the 'Plugins' menu in WordPress + + diff --git a/setup/adminMenus.php b/setup/adminMenus.php new file mode 100644 index 0000000..d23d5c2 --- /dev/null +++ b/setup/adminMenus.php @@ -0,0 +1,34 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * Added menus or sub-menus examples + * + * add_submenu_page( + * 'glm-members-admin-menu-members', // Parent slug + * 'Sample', // Page title + * 'Sample', // Menu Title + * 'glm_members_edit', // Capability required + * 'glm-members-admin-menu-sample', // Menu slug + * function() {$this->controller('sample');} + * ); + * + * If creating a main menu item with add_menu_page(), please document + * that structure here. + * + */ + + +?> diff --git a/setup/adminTabs.php b/setup/adminTabs.php new file mode 100644 index 0000000..a420b34 --- /dev/null +++ b/setup/adminTabs.php @@ -0,0 +1,36 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * To add a new tab to an existing Member DB page use a blick + * like this and replace the {} parameters. + * + * add_filter('glm-member-db-add-tab-for-{menu name}', + * function($addOnTabs) { + * $newTabs = array( + * array( + * 'text' => '{text for display on tab}', + * 'menu' => '{menu name}', + * 'action' => '{action to perform}' + * ) + * ); + * $addOnTabs = array_merge($addOnTabs, $newTabs); + * return $addOnTabs; + * } + * ); + * + */ + +?> \ No newline at end of file diff --git a/setup/permissions.php b/setup/permissions.php new file mode 100644 index 0000000..048444d --- /dev/null +++ b/setup/permissions.php @@ -0,0 +1,44 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release permissions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * Below are permission checks for various specific things in this add-on and + * elsewhere in the Member DB main plugin and add-ons. + * + * Each location where a permission might be required has an apply_filters() + * hook with a tag name that includes the plugin or add-on name, the menu, + * the action, and a name for the specific thing that needs permissions. + * + * This can be included in code or in a Smarty template used in these plugins. + * For example, to check permissions for the main Members menu and it's "index" + * action to see if a member search is permitted, the template includes the + * following code... + * + * {if $membersList && apply_filters('glm_members_permit_admin_members_index_member_search', true)} + * --- some template output --- + * {/if} + * + * In the case above, it's also checking to see if the members list even exists + * before checking the permissions. The default value of "true" in the hook ensures + * that the permission is granted if nothing has linked into the hook to say otherwise. + * + * Note that each add_filter() below first checks if the permission has already + * been retracted by prior hook. This requires all that are attached to the hook + * to permit the action. + * + * Of course any of these may test more than one capability if that's desired. + */ + +?> \ No newline at end of file diff --git a/setup/rolesAndCapabilities.php b/setup/rolesAndCapabilities.php new file mode 100644 index 0000000..9c3dc82 --- /dev/null +++ b/setup/rolesAndCapabilities.php @@ -0,0 +1,21 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release rolesAndPermissions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/** + * NOTE: This file is only included in the activate.php process. + * It is not regularly used during operation. + */ + +?> \ No newline at end of file diff --git a/setup/validActions.php b/setup/validActions.php new file mode 100644 index 0000000..a766289 --- /dev/null +++ b/setup/validActions.php @@ -0,0 +1,44 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * Array of valid menu items and actions. + * + * The higher level elements are valid menu items. These correlate to + * actual menu or sub menu items that are hooks back to this controller + * class. + * + * The lower level items below each menu item are actions that may be specified + * by a "glmMembersAction" form field. + * + * The string after the action is the slug of the plugin where the model/view + * is to perform that action. + * + * This array is integrated into the valid actions array in the main GLM Member + * DB plugin when this plugin registers itself. + */ + +$glmMembersAddOnValidActions = array( + 'adminActions' => array( + 'sample' => array( + 'index' => GLM_MEMBERS_PACKAGING_PLUGIN_SLUG + ) + ), + 'frontActions' => array( + ) +); + + +?> \ No newline at end of file diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 0000000..b6f8124 --- /dev/null +++ b/uninstall.php @@ -0,0 +1,28 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Check that we're being called by WordPress. +if (!defined('ABSPATH')) { + die("Please do not call this code directly!"); +} + +//if uninstall not called from WordPress exit +if (!defined('WP_UNINSTALL_PLUGIN')) { + die("Sorry, uninstall must be called by WordPress!"); +} + + +?> diff --git a/views/admin/sample/header.html b/views/admin/sample/header.html new file mode 100644 index 0000000..f9fdb91 --- /dev/null +++ b/views/admin/sample/header.html @@ -0,0 +1,5 @@ +
+ +

{$glmPluginName}

+ + \ No newline at end of file diff --git a/views/admin/sample/index.html b/views/admin/sample/index.html new file mode 100644 index 0000000..6159f5d --- /dev/null +++ b/views/admin/sample/index.html @@ -0,0 +1,7 @@ +{include file='admin/sample/header.html'} + +

A Sample Add-On Menu

+ + This is a test + +{include file='admin/footer.html'}