PluginProbe
Elementor Website Builder – more than just a page builder / 3.16.0-dev1
Elementor Website Builder – more than just a page builder v3.16.0-dev1
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.16.0-dev1, at core/settings/manager.php

211 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 private static function get_manager_class( $manager_name ) {
130 return __NAMESPACE__ . '\\' . ucfirst( $manager_name ) . '\Manager';
131 }
132
133 /**
134 * Get settings managers config.
135 *
136 * Retrieve the settings managers configuration.
137 *
138 * @since 1.6.0
139 * @access public
140 * @static
141 *
142 * @return array The settings managers configuration.
143 */
144 public static function get_settings_managers_config() {
145 $config = [];
146
147 $user_can = Plugin::instance()->role_manager->user_can( 'design' );
148
149 foreach ( self::$settings_managers as $name => $manager ) {
150 $settings_model = $manager->get_model_for_config();
151 $tabs = $settings_model->get_tabs_controls();
152
153 if ( ! $user_can ) {
154 unset( $tabs['style'] );
155 }
156
157 $config[ $name ] = [
158 'name' => $manager->get_name(),
159 'panelPage' => $settings_model->get_panel_page_settings(),
160 'controls' => $settings_model->get_controls(),
161 'tabs' => $tabs,
162 'settings' => $settings_model->get_settings(),
163 ];
164
165 if ( $settings_model instanceof CSS_Model ) {
166 $config[ $name ]['cssWrapperSelector'] = $settings_model->get_css_wrapper_selector();
167 }
168 }
169
170 return $config;
171 }
172
173 /**
174 * Get settings frontend config.
175 *
176 * Retrieve the settings managers frontend configuration.
177 *
178 * @since 1.6.0
179 * @access public
180 * @static
181 *
182 * @return array The settings managers frontend configuration.
183 */
184 public static function get_settings_frontend_config() {
185 $config = [];
186
187 foreach ( self::$settings_managers as $name => $manager ) {
188 $settings_model = $manager->get_model_for_config();
189
190 if ( $settings_model ) {
191 $config[ $name ] = $settings_model->get_frontend_settings();
192 }
193 }
194
195 return $config;
196 }
197
198 /**
199 * Run settings managers.
200 *
201 * Register builtin Elementor settings managers.
202 *
203 * @since 1.6.0
204 * @access public
205 * @static
206 */
207 public static function run() {
208 self::register_default_settings_managers();
209 }
210 }
211