PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.4
Elementor Website Builder – more than just a page builder v3.7.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / settings / manager.php

manager.php in Elementor Website Builder – more than just a page builder 3.7.4, at core/settings/manager.php

212 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Settings;
3
4 use Elementor\Core\Settings\Base\CSS_Model;
5 use Elementor\Plugin;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Elementor settings manager.
13 *
14 * Elementor settings manager handler class is responsible for registering and
15 * managing Elementor settings managers.
16 *
17 * @since 1.6.0
18 */
19 class Manager {
20
21 /**
22 * Settings managers.
23 *
24 * Holds all the registered settings managers.
25 *
26 * @since 1.6.0
27 * @access private
28 *
29 * @var Base\Manager[]
30 */
31 private static $settings_managers = [];
32
33 /**
34 * Builtin settings managers names.
35 *
36 * Holds the names for builtin Elementor settings managers.
37 *
38 * @since 1.6.0
39 * @access private
40 *
41 * @var array
42 */
43 private static $builtin_settings_managers_names = [ 'page', 'editorPreferences' ];
44
45 /**
46 * Add settings manager.
47 *
48 * Register a single settings manager to the registered settings managers.
49 *
50 * @since 1.6.0
51 * @access public
52 * @static
53 *
54 * @param Base\Manager $manager Settings manager.
55 */
56 public static function add_settings_manager( Base\Manager $manager ) {
57 self::$settings_managers[ $manager->get_name() ] = $manager;
58 }
59
60 /**
61 * Get settings managers.
62 *
63 * Retrieve registered settings manager(s).
64 *
65 * If no parameter passed, it will retrieve all the settings managers. For
66 * any given parameter it will retrieve a single settings manager if one
67 * exist, or `null` otherwise.
68 *
69 * @since 1.6.0
70 * @access public
71 * @static
72 *
73 * @param string $manager_name Optional. Settings manager name. Default is
74 * null.
75 *
76 * @return Base\Manager|Base\Manager[] Single settings manager, if it exists,
77 * null if it doesn't exists, or the all
78 * the settings managers if no parameter
79 * defined.
80 */
81 public static function get_settings_managers( $manager_name = null ) {
82 if ( $manager_name ) {
83 // Backwards compatibility for `general` manager, since 3.0.0.
84 // Register the class only if needed.
85 if ( 'general' === $manager_name ) {
86 // TODO: _deprecated_argument( $manager_name, '3.0.0', 'Plugin::$instance->kits_manager->get_active_kit_for_frontend();' );
87 $manager_class = self::get_manager_class( $manager_name );
88
89 self::add_settings_manager( new $manager_class() );
90 }
91
92 if ( isset( self::$settings_managers[ $manager_name ] ) ) {
93 return self::$settings_managers[ $manager_name ];
94 }
95
96 return null;
97 }
98
99 return self::$settings_managers;
100 }
101
102 /**
103 * Register default settings managers.
104 *
105 * Register builtin Elementor settings managers.
106 *
107 * @since 1.6.0
108 * @access private
109 * @static
110 */
111 private static function register_default_settings_managers() {
112 foreach ( self::$builtin_settings_managers_names as $manager_name ) {
113 $manager_class = self::get_manager_class( $manager_name );
114
115 self::add_settings_manager( new $manager_class() );
116 }
117 }
118
119 /**
120 * Get class path for default settings managers.
121 *
122 * @param $manager_name
123 *
124 * @return string
125 * @since 3.0.0
126 * @access private
127 * @static
128 */
129
130 private static function get_manager_class( $manager_name ) {
131 return __NAMESPACE__ . '\\' . ucfirst( $manager_name ) . '\Manager';
132 }
133
134 /**
135 * Get settings managers config.
136 *
137 * Retrieve the settings managers configuration.
138 *
139 * @since 1.6.0
140 * @access public
141 * @static
142 *
143 * @return array The settings managers configuration.
144 */
145 public static function get_settings_managers_config() {
146 $config = [];
147
148 $user_can = Plugin::instance()->role_manager->user_can( 'design' );
149
150 foreach ( self::$settings_managers as $name => $manager ) {
151 $settings_model = $manager->get_model_for_config();
152 $tabs = $settings_model->get_tabs_controls();
153
154 if ( ! $user_can ) {
155 unset( $tabs['style'] );
156 }
157
158 $config[ $name ] = [
159 'name' => $manager->get_name(),
160 'panelPage' => $settings_model->get_panel_page_settings(),
161 'controls' => $settings_model->get_controls(),
162 'tabs' => $tabs,
163 'settings' => $settings_model->get_settings(),
164 ];
165
166 if ( $settings_model instanceof CSS_Model ) {
167 $config[ $name ]['cssWrapperSelector'] = $settings_model->get_css_wrapper_selector();
168 }
169 }
170
171 return $config;
172 }
173
174 /**
175 * Get settings frontend config.
176 *
177 * Retrieve the settings managers frontend configuration.
178 *
179 * @since 1.6.0
180 * @access public
181 * @static
182 *
183 * @return array The settings managers frontend configuration.
184 */
185 public static function get_settings_frontend_config() {
186 $config = [];
187
188 foreach ( self::$settings_managers as $name => $manager ) {
189 $settings_model = $manager->get_model_for_config();
190
191 if ( $settings_model ) {
192 $config[ $name ] = $settings_model->get_frontend_settings();
193 }
194 }
195
196 return $config;
197 }
198
199 /**
200 * Run settings managers.
201 *
202 * Register builtin Elementor settings managers.
203 *
204 * @since 1.6.0
205 * @access public
206 * @static
207 */
208 public static function run() {
209 self::register_default_settings_managers();
210 }
211 }
212