PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
6.2.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 All 196 releases
fluentform / app / Services / Roles / RolesService.php

RolesService.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Services/Roles/RolesService.php

81 lines 2.2 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\Services\Roles;
4
5 use FluentForm\Framework\Support\Arr;
6
7 class RolesService
8 {
9 public function getRoles($attributes = [])
10 {
11 if (!current_user_can('manage_options')) {
12 return ([
13 'capability' => [],
14 'roles' => [],
15 ]);
16 }
17
18 $formatted = $this->getFormattedRoles();
19
20 $capability = get_option('_fluentform_form_permission');
21
22 if (is_string($capability)) {
23 $capability = [];
24 }
25
26 return ([
27 'capability' => $capability,
28 'roles' => $formatted,
29 ]);
30 }
31
32 public function setCapability($attributes = [])
33 {
34 if (current_user_can('manage_options')) {
35 $capability = wp_unslash(Arr::get($attributes, 'capability', []));
36
37 foreach ($capability as $item) {
38 if ('subscriber' == strtolower($item)) {
39 return ([
40 'message' => __('Sorry, you can not give access to the Subscriber role.', 'fluentform'),
41 ]);
42 }
43 }
44
45 update_option('_fluentform_form_permission', $capability, 'no');
46
47 return ([
48 'message' => __('Successfully saved the role(s).', 'fluentform'),
49 ]);
50 } else {
51 return ([
52 'message' => __('Sorry, You can not update permissions. Only administrators can update permissions',
53 'fluentform')
54 ]);
55 }
56 }
57
58 private function getFormattedRoles()
59 {
60 if (!function_exists('get_editable_roles')) {
61 require_once ABSPATH . 'wp-admin/includes/user.php';
62 }
63
64 $formatted = [];
65 $roles = \get_editable_roles();
66
67 foreach ($roles as $key => $role) {
68 if ('administrator' == $key) {
69 continue;
70 }
71 if ('subscriber' != $key) {
72 $formatted[] = [
73 'name' => $role['name'],
74 'key' => $key,
75 ];
76 }
77 }
78 return $formatted;
79 }
80 }
81