PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / FeatureFlags / OptionBasedFormEditor / Settings / AbstractOptionBasedFormEditorSettings.php
AbstractOptionBasedFormEditorSettings.php
101 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\FeatureFlags\OptionBasedFormEditor\Settings;
4
5 use Give\FeatureFlags\OptionBasedFormEditor\OptionBasedFormEditor;
6
7 /**
8 * @since 3.18.0
9 */
10 abstract class AbstractOptionBasedFormEditorSettings
11 {
12 /**
13 * @since 3.18.0
14 */
15 abstract public function getDisabledOptionIds(): array;
16
17 /**
18 * @since 3.18.0
19 */
20 public function getDisabledSectionIds(): array
21 {
22 return [];
23 }
24
25 /**
26 * @since 3.18.0
27 */
28 public function getNewDefaultSection(): string
29 {
30 return '';
31 }
32
33 /**
34 * @since 3.18.0
35 */
36 final public function maybeDisableSections(array $sections): array
37 {
38 if (OptionBasedFormEditor::isEnabled()) {
39 return $sections;
40 }
41
42 foreach ($sections as $key => $value) {
43 if (in_array($key, $this->getDisabledSectionIds())) {
44 unset($sections[$key]);
45 }
46 }
47
48 return $sections;
49 }
50
51 /**
52 * @since 3.18.0
53 */
54 final public function maybeDisableOptions(array $options): array
55 {
56 foreach ($options as $key => $value) {
57 if ( ! $this->isOptionDisabled($value['id']) && ! $this->isCurrentSectionDisabled()) {
58 continue;
59 }
60
61 if (OptionBasedFormEditor::isEnabled()) {
62 $options[$key]['name'] .= isset($value['name']) ? OptionBasedFormEditor::helperText() : '';
63 } else {
64 unset($options[$key]);
65 }
66 }
67
68 return $options;
69 }
70
71 /**
72 * @since 3.18.0
73 */
74 final public function maybeSetNewDefaultSection($currentSection)
75 {
76 if (OptionBasedFormEditor::isEnabled()) {
77 return $currentSection;
78 }
79
80 $newDefaultSection = $this->getNewDefaultSection();
81
82 return ! empty($newDefaultSection) && $newDefaultSection != $currentSection ? $newDefaultSection : $currentSection;
83 }
84
85 /**
86 * @since 3.18.0
87 */
88 private function isOptionDisabled($option): bool
89 {
90 return $option && in_array($option, $this->getDisabledOptionIds());
91 }
92
93 /**
94 * @since 3.18.0
95 */
96 private function isCurrentSectionDisabled(): bool
97 {
98 return in_array(give_get_current_setting_section(), $this->getDisabledSectionIds());
99 }
100 }
101