PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / includes / admin / tabs-handlers / tab-handler-manager.php

tab-handler-manager.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at includes/admin/tabs-handlers/tab-handler-manager.php

138 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin\Tabs_Handlers;
5
6 use Jet_Form_Builder\Classes\Instance_Trait;
7 use JFB_Components\Repository\Repository_Pattern_Trait;
8 use Jet_Form_Builder\Exceptions\Repository_Exception;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 /**
16 * @method static Tab_Handler_Manager instance()
17 *
18 * Class Tab_Handler_Manager
19 * @package Jet_Form_Builder\Admin\Tabs_Handlers
20 */
21 final class Tab_Handler_Manager {
22
23 use Instance_Trait;
24 use Repository_Pattern_Trait;
25
26 // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
27 private $_tabs_options = array();
28
29 /**
30 * @param string $slug
31 * @param array $if_empty
32 *
33 * @return array|false|void
34 */
35 public static function get_options( string $slug, array $if_empty = array() ) {
36 $tab = self::instance()->tab( $slug );
37
38 return $tab->get_options( $if_empty );
39 }
40
41 public function __construct() {
42 $this->rep_install();
43
44 add_filter(
45 'jet-form-builder/page-config/jfb-settings',
46 array( $this, 'modify_page_config' )
47 );
48 }
49
50 public function rep_instances(): array {
51 return apply_filters(
52 'jet-form-builder/register-tabs-handlers',
53 array(
54 new Options_Handler(),
55 )
56 );
57 }
58
59 /**
60 * @param $item
61 *
62 * @throws Repository_Exception
63 */
64 public function rep_before_install_item( $item ) {
65 if ( ! ( $item instanceof Base_Handler ) ) {
66 $this->_rep_abort_this();
67 }
68 }
69
70 /**
71 * @param Base_Handler $item
72 */
73 public function rep_after_install_item( $item ) {
74 $item->after_install();
75 }
76
77 public function modify_page_config( array $page_config ): array {
78 /** @var Base_Handler $item */
79 foreach ( $this->rep_get_items() as $item ) {
80 $page_config[ $item->slug() ] = apply_filters(
81 "jet-form-builder/tab-config/{$item->slug()}",
82 $item->on_load()
83 );
84 }
85
86 return $page_config;
87 }
88
89 /**
90 * @param $slug
91 *
92 * @return Base_Handler
93 */
94 public function tab( $slug ): Base_Handler {
95 return $this->rep_get_item_or_die( $slug );
96 }
97
98 public function options( $slug, $is_empty = array() ) {
99 return $this->tab( $slug )->get_options( $is_empty );
100 }
101
102 /**
103 * @since 3.1.0 Remove $default_tabs argument
104 *
105 * @return array
106 */
107 public function all(): array {
108 $response = array();
109
110 /** @var Base_Handler[] $tabs */
111 $tabs = $this->rep_get_items();
112
113 foreach ( $tabs as $slug => $tab ) {
114 $response[ $slug ] = $tab->on_editor_load();
115 }
116
117 return $response;
118 }
119
120 public function install( Base_Handler $item ): bool {
121 return $this->rep_install_item_soft( $item );
122 }
123
124 /**
125 * @param Base_Handler|string $item
126 */
127 public function uninstall( $item ) {
128 $this->rep_remove( $item );
129 }
130
131 public static function get_form_records_access_capability() {
132 $capability = self::get_options( 'options-tab' )['form_records_access_capability'] ?? '';
133 return ! empty( $capability ) ? $capability : 'manage_options';
134 }
135
136
137 }
138