PluginProbe
Visual Composer Website Builder / 45.16.4
Visual Composer Website Builder v45.16.4
45.16.4 45.16.3 45.16.2 45.16.1 45.2-beta.1 45.2-beta.2 45.2.0 45.3-beta.1 45.3.0 45.4-beta.1 45.4.0 45.4.1 45.4.1-beta.2 45.5-beta.1 45.5.0 45.6-beta.1 45.6.0 45.7-beta.1 45.7.0 45.8-beta.1 45.8.0 45.9.0 trunk 45.0 45.0-beta.1 All 42 releases
visualcomposer / visualcomposer / Modules / Migrations / NewDefaultCapabilitiesMigration.php

NewDefaultCapabilitiesMigration.php in Visual Composer Website Builder 45.16.4, at visualcomposer/Modules/Migrations/NewDefaultCapabilitiesMigration.php

54 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace VisualComposer\Modules\Migrations;
4
5 if (!defined('ABSPATH')) {
6 header('Status: 403 Forbidden');
7 header('HTTP/1.1 403 Forbidden');
8 exit;
9 }
10
11 use VisualComposer\Framework\Illuminate\Support\Module;
12
13 class NewDefaultCapabilitiesMigration extends MigrationsController implements Module
14 {
15 protected $migrationId = 'defaultCapabilitiesMigration46';
16
17 protected $migrationPriority = 1;
18
19 protected function run()
20 {
21 // Run migration only if role Manager addon is available and is enabled
22 if (!vcvenv('VCV_ADDON_ROLE_MANAGER_PARTS')) {
23 return false;
24 }
25
26 $roleHelper = vchelper('AccessRole');
27 $userCapabilitiesHelper = vchelper('AccessUserCapabilities');
28 $defaultCapabilities = $userCapabilitiesHelper->getDefaultCapabilities();
29
30 // for a security reason we decided to remove all default caps in some user roles.
31 $roleWithoutDefaultCaps = ['author', 'contributor'];
32
33 foreach ($defaultCapabilities as $roleName => $roleParts) {
34 if (in_array($roleName, $roleWithoutDefaultCaps)) {
35 continue;
36 }
37
38 foreach ($roleParts as $capPart => $capabilities) {
39 foreach ($capabilities as $cap) {
40 if (!is_object($roleHelper->who($roleName)->part($capPart)->getRole())) {
41 continue;
42 }
43
44 if (! $roleHelper->who($roleName)->part($capPart)->issetCapRule($cap)) {
45 $roleHelper->who($roleName)->part($capPart)->setCapRule($cap);
46 }
47 }
48 }
49 }
50
51 return true;
52 }
53 }
54