PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.14
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Modules / Acl / RoleManager.php

RoleManager.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.14, at app/Modules/Acl/RoleManager.php

115 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Acl;
4
5 class RoleManager
6 {
7 public function getRoles()
8 {
9 if (!current_user_can('manage_options')) {
10 wp_send_json_success(array(
11 'capability' => array(),
12 'roles' => array()
13 ), 200);
14 }
15
16 $roles = \get_editable_roles();
17 $formatted = array();
18 foreach ($roles as $key => $role) {
19 if ($key == 'administrator') {
20 continue;
21 }
22 if ($key != 'subscriber') {
23 $formatted[] = array(
24 'name' => $role['name'],
25 'key' => $key
26 );
27 }
28 }
29
30 $capability = get_option('_fluentform_form_permission');
31
32 if (is_string($capability)) {
33 $capability = [];
34 }
35
36 wp_send_json_success(array(
37 'capability' => $capability,
38 'roles' => $formatted
39 ), 200);
40 }
41
42 public function setRoles()
43 {
44 if (current_user_can('manage_options')) {
45 $capability = isset($_REQUEST['capability']) ? wp_unslash($_REQUEST['capability']) : [];
46
47 foreach ($capability as $item) {
48 if (strtolower($item) == 'subscriber') {
49 wp_send_json_error(array(
50 'message' => __('Sorry, you can not give access to the Subscriber role.', 'fluentform')
51 ), 423);
52 }
53 }
54
55 update_option('_fluentform_form_permission', $capability, 'no');
56 wp_send_json_success(array(
57 'message' => __('Successfully saved the role(s).', 'fluentform')
58 ), 200);
59 } else {
60 wp_send_json_error(array(
61 'message' => __('Sorry, You can not update permissions. Only administrators can update permissions', 'fluentform')
62 ), 423);
63 }
64 }
65
66 public function verifyPermissionSet()
67 {
68 $availablePermissions = Acl::getPermissionSet();
69 $currentCapability = $this->currentUserFormFormCapability();
70 if (!$currentCapability) {
71 return;
72 }
73
74 // Give permission to internal issues
75 foreach ($availablePermissions as $permission) {
76 add_filter('fluentform_verify_user_permission_'.$permission, function ($allowed) {
77 return true;
78 });
79 }
80
81 // Give permission to menu items
82 add_filter('fluentform_dashboard_capability', function ($capability) use ($currentCapability) {
83 return $currentCapability;
84 });
85
86 add_filter('fluentform_settings_capability', function ($capability) use ($currentCapability) {
87 return $currentCapability;
88 });
89 }
90
91 public function currentUserFormFormCapability()
92 {
93 if (current_user_can('manage_options')) {
94 return 'manage_options';
95 }
96 if (!is_user_logged_in()) {
97 return false;
98 }
99
100 $capabilities = get_option('_fluentform_form_permission');
101 if (is_string($capabilities)) {
102 $capabilities = (array) $capabilities;
103 }
104 if (!$capabilities) {
105 return;
106 }
107 foreach ($capabilities as $capability) {
108 if (current_user_can($capability)) {
109 return $capability;
110 }
111 }
112 return false;
113 }
114 }
115