From: Chuck Scott Date: Thu, 13 Oct 2016 20:05:46 +0000 (-0400) Subject: Added a function plugin support to test for existing capabilities and their setting. X-Git-Tag: v2.7.0^2~7 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=13dead44e1d8e290e2cb06e7e97b15a29e1148fd;p=WP-Plugins%2Fglm-member-db.git Added a function plugin support to test for existing capabilities and their setting. --- diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 918e655b..bceff41f 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -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); +}