PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / InstallActions / ActivationCapabilitiesHook.php

ActivationCapabilitiesHook.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Services/InstallActions/ActivationCapabilitiesHook.php

48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 */
6
7 namespace IvyForms\Services\InstallActions;
8
9 use IvyForms\Services\Permissions\IvyFormsAccess;
10 use IvyForms\Services\Permissions\PermissionCatalog;
11
12 /**
13 * Registers IvyForms-prefixed capabilities on the Administrator role.
14 */
15 class ActivationCapabilitiesHook
16 {
17 /**
18 * Idempotent: safe to call on every activation and new subsite.
19 */
20 public static function ensureAdministratorCaps(): void
21 {
22 $role = get_role('administrator');
23 if ($role === null) {
24 return;
25 }
26
27 foreach (PermissionCatalog::keys() as $key) {
28 $role->add_cap(PermissionCatalog::wpCapability($key));
29 }
30
31 $role->add_cap(IvyFormsAccess::CAP_MANAGE_ALL);
32 $role->add_cap(IvyFormsAccess::CAP_ACCESS_PLUGIN);
33 }
34
35 /**
36 * Backfill caps for sites upgraded without re-running the activation hook.
37 */
38 public static function ensureAdministratorCapsIfMissing(): void
39 {
40 $role = get_role('administrator');
41 if ($role === null || $role->has_cap(IvyFormsAccess::CAP_MANAGE_ALL)) {
42 return;
43 }
44
45 self::ensureAdministratorCaps();
46 }
47 }
48