PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.6
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.6, at app/Modules/Acl/RoleManager.php

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