From aa55daa1e85c7ca48b38008f7a52c52d6fe4f5c7 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 25 Jan 2016 14:33:31 -0500 Subject: [PATCH] Added additional hooks documentation and enhanced hook to get current user info --- glm-member-db-contacts.php | 30 ++---- setup/hooksHelp.html | 202 +++++++++++++++++++++++++++++++++++++ setup/permissions.php | 32 ++++-- 3 files changed, 234 insertions(+), 30 deletions(-) diff --git a/glm-member-db-contacts.php b/glm-member-db-contacts.php index 563bf40..f77857c 100644 --- a/glm-member-db-contacts.php +++ b/glm-member-db-contacts.php @@ -182,49 +182,41 @@ add_filter('glm-member-db-register-addon','glmMembersRegisterContacts', 10, 1); require_once(GLM_MEMBERS_CONTACTS_PLUGIN_SETUP_PATH.'/permissions.php'); /* - * Notification to user if logging in with restricted contact + * Notification to user if logging in with restricted or inactive contact */ -$wpUserID = get_current_user_id(); function glmMembersContactsNoLoginMessage( $message ) { $message .= "
- NOTE: You are trying to log into a contact account that is for informational purposes only - or has been temporarily dissabled. You are not permitted to log in with that contact account at this time. +

NOTE: You are trying to log into a contact account that is for informational purposes only + or has been temporarily dissabled.

+

You are not permitted to log in with that contact account at this time.

"; return $message; } -/* -$restrictedLoginAttempt = get_user_meta($wpUserID, 'glmMembersDatabaseContactRestrictedLogin', false); -if ($restrictedLoginAttempt) { +// 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'); - delete_user_mega($wpUserID, 'glmMembersDatabaseContactRestrictedLogin'); + setcookie ("glmMembersForcedLogout", "", time() - 3600); } +// Check for a restricted contact user and log them out with login message if (current_user_can('glm_members_restricted_contact')) { - update_user_meta($wpUserID, 'glmMembersDatabaseContactRestrictedLogin', true); + setcookie ("glmMembersForcedLogout", "stuff", time() + 3600, '/'); wp_logout(); } -*/ -/* - * Check for a contact user that's inactive and send them back to login also - */ -/* +// Check for a contact user that's inactive and send them back to login also $wpUserID = get_current_user_id(); $contactUser = get_user_meta($wpUserID, 'glmMembersContactID', true); $contactActive = get_user_meta($wpUserID, 'glmMembersContactActive', true); if ($contactUser && !$contactActive) { - update_user_meta($wpUserID, 'glmMembersDatabaseContactRestrictedLogin', true); + setcookie ("glmMembersForcedLogout", "stuff", 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; diff --git a/setup/hooksHelp.html b/setup/hooksHelp.html index ce62e67..6c80f55 100644 --- a/setup/hooksHelp.html +++ b/setup/hooksHelp.html @@ -36,3 +36,205 @@ Hook to test if the logged in user is permitted to edit a contact. + + glm_members_current_logged_in_user + Filter + + + Filter that returns the current WordPress user data along with any + current Member Contact user information. The information returned + is listed below +
Array
+(
+    [wpUser] => Array
+        (
+            [ID]                    (numeric)
+            [user_login]
+            [user_pass]             (encrypted)
+            [user_nicename]
+            [user_email]
+            [user_url]
+            [user_registered]       (date)
+            [user_activation_key]
+            [user_status] => 0
+            [display_name] => George Tootikian
+        )
+    [contactUser] => Array
+        (
+            [ID] =>                 (numeric)
+            [fname]
+            [lname]
+            [email]
+            [ref_type]              (numeric: 10 = Member contact)
+            [ref_type_name]
+            [ref_dest]              (id of reference destination - if type = 10 this is member ID)
+            [ref_dest_name]
+            [role]                  (Wordpress role ID)
+            [role_name]
+            [access]                (see "Member Access Levels" in glm-member-db/config/plugin.ini))
+            [access_name]
+        )
+
+)
+ + + + glm_members_locked_to_member_id + Filter + + + Filter that provides the member ID of any member the current user is locked into. + + + + glm_members_menu_members + Filter + + + Returns boolean answer to "Can current user access any member?" + + + + glm_members_permit_admin_members_index_member_config_warning + Filter + + + Returns boolean answer to "Should we display configuration warnings to current user?" + + + + glm_members_permit_admin_members_index_add_member + Filter + + + Returns boolean answer to "Can current user edit any member?" + + + + glm_members_permit_admin_member_index_add_member_info_version + Filter + + + Returns boolean answer to "Should current user see the member information display and add-new links/buttons?" + + + + glm_members_permit_admin_member_index_edit_member + Filter + + + Returns boolean answer to "Should current user see the member edit page?" (if not, then just show the info) + + + + glm_members_permit_admin_member_index_view_member_info_version + Filter + + + Returns boolean answer to "Should current user see link to view/edit member information?" + + + + glm_members_permit_admin_member_index_clone_activate_info_version + Filter + + + Returns boolean answer to "Should current user see Clone and Activate buttons for member information?" + + + + glm_members_permit_admin_member_contacts_tab + Filter + + + Returns boolean answer to "Should current user see the Contacts tab?" + + + + glm_members_permit_admin_member_contacts_add_contact + Filter + + + Returns boolean answer to "Should current user be able to add contacts?" + + + + glm_members_permit_admin_member_contacts_view_contact + Filter + + + Returns boolean answer to "Should current user be able to view contact data?" + + + + glm_members_permit_admin_member_contacts_edit_contact + Filter + + + Returns boolean answer to "Should current user be able to edit contact data?" + + + + glm_members_permit_admin_widget_members + Filter + + + Returns boolean answer to "Should current user see the member search and member list in dashboard widget?" + + + + glm_members_permit_admin_widget_warnings + Filter + + + Returns boolean answer to "Should current user see warnings in dashboard widget?" + + + + glm_members_permit_admin_widget_pending_info + Filter + + + Returns boolean answer to "Should current user see pending member information list in dashboard widget?" + + + + glm_members_permit_admin_member_index_list_inactive_info + Filter + + + Returns boolean answer to "Should current user see inactive member information records in member info list?" + + + + glm_members_permit_admin_member_info_edit + Filter + + + Returns boolean answer to "Should current user be able to edit member information records?" + + + + glm_members_permit_admin_profile_index_edit_profile + Filter + + + Returns boolean answer to "Should current user be able to edit own contact profile?" + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/setup/permissions.php b/setup/permissions.php index b8ce13a..f597909 100644 --- a/setup/permissions.php +++ b/setup/permissions.php @@ -22,7 +22,8 @@ add_filter('glm_members_current_logged_in_user', function($loggedInUser) { - global $wpdb; + global $wpdb, $config; + // Add default of no current contact user $loggedInUser['contactUser'] = false; @@ -40,24 +41,33 @@ add_filter('glm_members_current_logged_in_user', } // Try to get the matching contact data - $contactInfo = $wpdb->get_row("SELECT * FROM ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts WHERE id = $contactID;"); +// $contactInfo = $wpdb->get_row("SELECT * FROM ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts WHERE id = $contactID;"); + + require_once(GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php'); + $ContactInfo = new GlmDataContacts($wpdb, $config); + $contactInfo = $ContactInfo->getEntry($contactID); // If contact is not active, then return false - should not be logged in - if (!$contactInfo->active) { + if (!$contactInfo['active']['value']) { return false; } // Return array with base data on this contact that might be needed by this add-on $loggedInUser['contactUser'] = array( 'ID' => $contactID, - 'fname' => $contactInfo->fname, - 'lname' => $contactInfo->lname, - 'email' => $contactInfo->email, - 'ref_type' => $contactInfo->ref_type, - 'ref_dest' => $contactInfo->ref_dest, - 'role' => $contactInfo->contact_role, - 'access' => $contactInfo->access + 'fname' => $contactInfo['fname'], + 'lname' => $contactInfo['lname'], + 'email' => $contactInfo['email'], + 'ref_type' => $contactInfo['ref_type']['value'], + 'ref_type_name' => $contactInfo['ref_type']['name'], + 'ref_dest' => $contactInfo['ref_dest'], + 'ref_dest_name' => $contactInfo['ref_dest_name'], + 'role' => $contactInfo['contact_role']['value'], + 'role_name' => $contactInfo['contact_role']['name'], + 'access' => $contactInfo['access']['value'], + 'access_name' => $contactInfo['access']['name'] ); + return $loggedInUser; } ); @@ -181,7 +191,7 @@ add_filter('glm_members_permit_admin_member_contacts_tab', } ); -// glm-member-db, view/member/contacts.html, Display Contacts tab +// glm-member-db, view/member/contacts.html, Add Contacts data add_filter('glm_members_permit_admin_member_contacts_add_contact', function($permit) { if (!$permit) { return false; } -- 2.17.1