PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
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 / Permissions / AccessRulesCapabilityBootstrap.php

AccessRulesCapabilityBootstrap.php in The Innovative Form Builder – IvyForms 1.5.1, at backend/src/Services/Permissions/AccessRulesCapabilityBootstrap.php

56 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 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 */
6
7 namespace IvyForms\Services\Permissions;
8
9 // phpcs:disable PSR1.Files.SideEffects
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 use IvyForms\Plugin\Plugin;
15 use IvyForms\Repository\Permissions\AccessRulesRepository;
16 use IvyForms\Vendor\DI\DependencyException;
17 use IvyForms\Vendor\DI\NotFoundException;
18
19 /**
20 * One-time sync of stored access rules to WP role/user capabilities (backfill after upgrades).
21 */
22 final class AccessRulesCapabilityBootstrap
23 {
24 private const OPTION_FLAG = 'ivyforms_access_rules_caps_synced_v2';
25
26 public static function maybeRunOnce(): void
27 {
28 if (!is_admin() || get_option(self::OPTION_FLAG, false)) {
29 return;
30 }
31
32 $plugin = Plugin::getInstance();
33 if (!$plugin instanceof Plugin || $plugin->container === null) {
34 return;
35 }
36
37 try {
38 /** @var AccessRulesRepository $repo */
39 $repo = $plugin->container->get(AccessRulesRepository::class);
40 $rules = $repo->getPayload()['rules'];
41 AccessRulesRoleCapabilitySynchronizer::syncFromRules(
42 $rules,
43 AccessRulesRoleCapabilitySynchronizer::extractUserIdsFromUserRules($rules)
44 );
45 } catch (DependencyException |NotFoundException $e) {
46 if (defined('WP_DEBUG') && WP_DEBUG) {
47 error_log('IvyForms access rules capability sync: ' . $e->getMessage());
48 }
49
50 return;
51 }
52
53 update_option(self::OPTION_FLAG, 1, false);
54 }
55 }
56