Added a function plugin support to test for existing capabilities and their setting.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 13 Oct 2016 20:05:46 +0000 (16:05 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 13 Oct 2016 20:05:46 +0000 (16:05 -0400)
classes/glmPluginSupport.php

index 918e655..bceff41 100644 (file)
@@ -489,4 +489,29 @@ function glmMembersInstallErrorsNotice() {
     delete_option('glmMembersInstallErrors');
 }
 
+/**
+ * Check if a particular capability exists for the current user and if it's checked
+ *
+ * If $permit is already false, we just return that since we can only withdraw permission with these tests, not add it.
+ * @param $cap string Capability to check
+ * @param $permit boolean Used to pass on pre-existing permission value
+ *
+ * @return boolean True if capability exists
+ */
+$glmUser = wp_get_current_user();
+$glmMembersCaps = $glmUser->allcaps;
+function glmMembersUserCan( $cap, $permit )
+{
+    global $glmMembersCaps;
+
+    if (!$permit) {
+        return false;
+    }
+
+    if (!isset($glmMembersCaps[$cap])) {
+        return $permit;
+    }
+trigger_error('TEST',E_USER_NOTICE);
+    return current_user_can($cap);
+}