3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC https://civicrm.org/licensing
39 class CRM_Core_Permission_WordPress
extends CRM_Core_Permission_Base
{
42 * Given a permission string, check for access requirements
45 * The permission to check.
49 * true if yes, else false
51 public function check($str, $userId = NULL) {
52 // Generic cms 'administer users' role tranlates to users with the 'edit_users' capability' in WordPress
53 $str = $this->translatePermission($str, 'WordPress', [
54 'administer users' => 'edit_users',
56 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
59 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
64 // During some extern/* calls we don't bootstrap CMS hence
65 // below constants are not set. In such cases, we don't need to
66 // check permission, hence directly return TRUE
67 if (!defined('ABSPATH') ||
!defined('WPINC')) {
68 require_once 'CRM/Utils/System.php';
69 CRM_Utils_System
::loadBootStrap();
72 require_once ABSPATH
. WPINC
. '/pluggable.php';
74 // for administrators give them all permissions
75 if (!function_exists('current_user_can')) {
79 $user = $userId ?
get_userdata($userId) : wp_get_current_user();
81 if ($user->has_cap('super admin') ||
$user->has_cap('administrator')) {
85 // Make string lowercase and convert spaces into underscore
86 $str = CRM_Utils_String
::munge(strtolower($str));
88 if ($user->exists()) {
89 // Check whether the logged in user has the capabilitity
90 if ($user->has_cap($str)) {
95 //check the capabilities of Anonymous user)
96 $roleObj = new WP_Roles();
98 $roleObj->get_role('anonymous_user') != NULL &&
99 array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities
)
110 public function isModulePermissionSupported() {
117 public function upgradePermissions($permissions) {