+++ /dev/null
-<?php
-/**
- * Plugin Name: GLM Members Database Contacts
- * Plugin URI: http://www.gaslightmedia.com/
- * Description: Gaslight Media Members Database.
- * Version: 1.0.7
- * Author: Chuck Scott
- * Author URI: http://www.gaslightmedia.com/
- * License: GPL2
- */
-
-/**
- * Gaslight Media Members Database Contacts
- * Index
- *
- * PHP version 5.5
- *
- * @category glmWordPressPluginChild
- * @package glmMembersDatabaseContacts
- * @author Chuck Scott <cscott@gaslightmedia.com>
- * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.0.4
- */
-
-/*
- * 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_CONTACTS_PLUGIN_VERSION', '1.0.7');
-define('GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.44');
-define('REQUIRED_GLM_MEMBERS_PLUGIN_MIN_DB_VERSION', '1.0.41');
-
-/*
- * 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 glmMembersPluginRequired() {
- echo '
- <div class="error">
- <p>The '.GLM_MEMBERS_CONTACTS_PLUGIN_NAME.' add-on requires the base GLM Member DB plugin to be installed and active!</p>
- <p>The '.GLM_MEMBERS_CONTACTS_PLUGIN_NAME.' plugin has been de-activated.</p>
- </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', 'glmMembersPluginRequired' );
- deactivate_plugins('/'.GLM_MEMBERS_CONTACTS_PLUGIN_SLUG.'/'.GLM_MEMBERS_CONTACTS_PLUGIN_SLUG.'.php');
-}
-
-// Function to generate message regarding main GLM Member DB plugin version is not receint enought to run this add-on
-function glmMembersContactsMembersMinVerRequired() {
- $curVer = get_option('glmMembersDatabasePluginVersion');
- echo '
- <div class="error">
- <p>The '.GLM_MEMBERS_CONTACTS_PLUGIN_NAME.' requires that the main GLM Member DB plugin version be no older than '
- .GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION.' but the current verssion is '.$curVer.'!</p>
- <p>The '.GLM_MEMBERS_CONTACTS_PLUGIN_NAME.' plugin has been de-activated.</p>
- </div>
- ';
-}
-
-/*
- * Check for Minimum DB version for main Member DB
- */
-$glmMembersDatabasePluginVersion = get_option('glmMembersDatabasePluginVersion');
-if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION) < 0) {
- add_action( 'admin_notices', 'glmMembersContactsMembersMinVerRequired');
- deactivate_plugins('/'.GLM_MEMBERS_CONTACTS_PLUGIN_SLUG.'/'.GLM_MEMBERS_CONTACTS_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_CONTACTS_PLUGIN_SETUP_PATH.'/validActions.php');
-// require_once(GLM_MEMBERS_CONTACTS_PLUGIN_DB_SCRIPTS.'/dbVersions.php');
-function glmMembersRegisterContacts($addOns) {
-
- // Add this add-on to the add-ons array
- $addOns[GLM_MEMBERS_CONTACTS_PLUGIN_SLUG] = array(
- 'dir' => GLM_MEMBERS_CONTACTS_PLUGIN_PATH,
- 'name' => GLM_MEMBERS_CONTACTS_PLUGIN_NAME,
- 'short_name' => GLM_MEMBERS_CONTACTS_PLUGIN_SHORT_NAME,
- 'slug' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
- 'actions' => $GLOBALS['glmMembersContactsAddOnValidActions'],
- 'database' => false
- );
-
- // Return the array with our data added
- return $addOns;
-}
-add_filter('glm-member-db-register-addon','glmMembersRegisterContacts', 10, 1);
-
- /*
- *
- * Activate and Deactivate hooks
- *
- */
-
- // Activate
- function glmMembersContactsPluginActivate ()
- {
- global $wpdb, $config;
- require_once (GLM_MEMBERS_CONTACTS_PLUGIN_PATH . '/activate.php');
- new glmMembersContactsPluginActivate($wpdb, $config);
- }
- register_activation_hook(__FILE__, 'glmMembersContactsPluginActivate');
-
- // Deactivate
- function glmMembersContactsPluginDeactivate ()
- {
- global $wpdb, $config;
- require_once (GLM_MEMBERS_CONTACTS_PLUGIN_PATH . '/deactivate.php');
- $x = new glmMembersContactsPluginDeactivate($wpdb, $config);
- return false;
- }
- register_deactivation_hook(__FILE__, 'glmMembersContactsPluginDeactivate');
-
-/*
- * Hooks for testing capabilities provided by this add-on
- */
-require_once(GLM_MEMBERS_CONTACTS_PLUGIN_SETUP_PATH.'/permissions.php');
-
-/*
- * Login Checks and Messages
- */
-
-$wpUserID = get_current_user_id();
-
-// Message to display on Login page after a forced logout detection
-function glmMembersContactsNoLoginMessage( $message ) {
- $message .= "
- <div style=\"border-left:4px solid #dd3d36;background:#fff;box-shadow:0 1px 1px 0 rgba(0,0,0,.1);padding-left: .5em;\">
- <p><b>NOTE:</b> You are trying to log into a contact account that is for informational purposes only
- or has been temporarily dissabled.</p>
- <p>You are not permitted to log in with that contact account at this time.</p>
- </div>
- ";
- return $message;
-}
-
-// If login is from user who was logged out due to restriction or being flagged inactive - Display login message
-if (isset($_COOKIE['glmMembersForcedLogout'])) {
- add_filter('login_message', 'glmMembersContactsNoLoginMessage');
- setcookie ("glmMembersForcedLogout", "", time() - 3600);
-}
-
-if ($wpUserID) {
-
- // Check if user's only role is as a restricted contact
- $userRoles = get_userdata($wpUserID)->roles;
- if (in_array('glm_members_restricted_contact', $userRoles) && count($userRoles) == 1) {
- setcookie ("glmMembersForcedLogout", "Forced Logout", time() + 3600, '/');
- wp_logout();
- }
-
- // Check for a contact user that's inactive and send them back to login also
- $contactUser = get_user_meta($wpUserID, 'glmMembersContactID', true);
- $contactActive = get_user_meta($wpUserID, 'glmMembersContactActive', true);
- if ($contactUser && !$contactActive) {
- setcookie ("glmMembersForcedLogout", "Forced Logout", time() + 3600, '/');
- wp_logout();
- }
-
-}
-
-/*
- * Add filter to redirect user to a particular destination on
- * login based on their roles.
- */
-
-function my_login_redirect( $redirect_to, $request, $user ) {
-
- global $user;
-
- // Do we have a logged in user
- if ( isset( $user->roles ) && is_array( $user->roles ) ) {
-
- // If this is a non-contact user or one with a pre-existing non-contact login
- foreach ($user->roles as $r) {
- if (substr($r,0,12) != 'glm_members_') {
- // Go to normal destination for this user
- return $redirect_to;
- }
- }
-
- // If we get here, this is a pure contact user, start them at their profile
-
- return '/wp-admin/admin.php?page=glm-members-admin-menu-member';
-
- }
-
- // No logged in user - So why is the "login_redirect" filter triggered anyway?
- return $redirect_to;
-
-}
-add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
-
-
-?>
\ No newline at end of file