PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 1.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v1.2.4
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 1.2.4, at app/Modules/Acl/Acl.php

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