PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.21
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.21
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 / Acl.php

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

119 lines 3.5 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 Acl
6 {
7 public static function getPermissionSet()
8 {
9 return apply_filters('fluentform_permission_set', [
10 'fluentform_full_access',
11 'fluentform_settings_manager',
12 'fluentform_dashboard_access',
13 'fluentform_forms_manager',
14 'fluentform_entries_viewer'
15 ]);
16 }
17
18 /**
19 * Fluentform access controll permissions assignment.
20 */
21 public static function setPermissions()
22 {
23 // Fire an event letting others know that fluentform
24 // is going to assign permission set to a role.
25 do_action('before_fluentform_permission_set_assignment');
26
27 // The permissions that fluentform supports altogether.
28 $permissions = self::getPermissionSet();
29
30 // The role that fluentform will use
31 // to attach the permission set.
32 $role = get_role('administrator');
33
34 // Looping through permission set to add to the role.
35 foreach ($permissions as $permission) {
36 $role->add_cap($permission);
37 }
38
39 // Fire an event letting others know that fluentform is
40 // done with the permission assignment to the role.
41 do_action('after_fluentform_permission_set_assignment');
42 }
43
44 /**
45 * Verify if current user has a fluentform permission.
46 *
47 * @param $permission
48 * @param null $formId
49 * @param string $message
50 * @param bool $json
51 *
52 * @throws \Exception
53 */
54 public static function verify(
55 $permission,
56 $formId = null,
57 $message = 'You do not have permission to perform this action.',
58 $json = true
59 )
60 {
61 $allowed = self::hasPermission($permission, $formId);
62 if (!$allowed) {
63 if ($json) {
64 wp_send_json_error([
65 'message' => $message
66 ], 422);
67 } else {
68 throw new \Exception($message);
69 }
70 }
71 }
72
73 public static function hasPermission($permission, $formId = false)
74 {
75 if (current_user_can('fluentform_full_access')) {
76 return true;
77 }
78
79 $allowed = current_user_can('fluentform_full_access');
80 if ($allowed) {
81 return true;
82 }
83
84 if (is_array($permission)) {
85 foreach ($permission as $eachPermission) {
86 $allowed = current_user_can($eachPermission);
87 if ($allowed) {
88 return apply_filters('fluentform_verify_user_permission_' . $eachPermission, $allowed, $formId);
89 } else {
90 $isHookAllowed = apply_filters('fluentform_permission_callback', false, $eachPermission, $formId);
91 if ($isHookAllowed) {
92 return true;
93 }
94 }
95 }
96 return false;
97 }
98
99 $allowed = current_user_can($permission);
100 $allowed = apply_filters('fluentform_verify_user_permission_' . $permission, $allowed, $formId);
101
102 if ($allowed) {
103 return true;
104 }
105
106 return apply_filters('fluentform_permission_callback', false, $permission, $formId);
107 }
108
109 public static function hasAnyFormPermission($form_id = false)
110 {
111 $allPermissions = self::getPermissionSet();
112 foreach ($allPermissions as $permission) {
113 if (self::hasPermission($permission, $form_id)) {
114 return true;
115 }
116 }
117 return false;
118 }
119 }