PluginProbe
Elementor Website Builder – more than just a page builder / 3.21.7
Elementor Website Builder – more than just a page builder v3.21.7
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 / includes / settings / settings.php

settings.php in Elementor Website Builder – more than just a page builder 3.21.7, at includes/settings/settings.php

524 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
5 use Elementor\Core\Settings\Manager as SettingsManager;
6 use Elementor\Includes\Settings\AdminMenuItems\Admin_Menu_Item;
7 use Elementor\Includes\Settings\AdminMenuItems\Get_Help_Menu_Item;
8 use Elementor\Includes\Settings\AdminMenuItems\Getting_Started_Menu_Item;
9 use Elementor\Modules\Promotions\Module as Promotions_Module;
10 use Elementor\TemplateLibrary\Source_Local;
11 use Elementor\Modules\Home\Module as Home_Module;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Elementor "Settings" page in WordPress Dashboard.
19 *
20 * Elementor settings page handler class responsible for creating and displaying
21 * Elementor "Settings" page in WordPress dashboard.
22 *
23 * @since 1.0.0
24 */
25 class Settings extends Settings_Page {
26
27 /**
28 * Settings page ID for Elementor settings.
29 */
30 const PAGE_ID = 'elementor';
31
32 /**
33 * Upgrade menu priority.
34 */
35 const MENU_PRIORITY_GO_PRO = 502;
36
37 /**
38 * Settings page field for update time.
39 */
40 const UPDATE_TIME_FIELD = '_elementor_settings_update_time';
41
42 /**
43 * Settings page general tab slug.
44 */
45 const TAB_GENERAL = 'general';
46
47 /**
48 * Settings page style tab slug.
49 */
50 const TAB_STYLE = 'style';
51
52 /**
53 * Settings page integrations tab slug.
54 */
55 const TAB_INTEGRATIONS = 'integrations';
56
57 /**
58 * Settings page advanced tab slug.
59 */
60 const TAB_ADVANCED = 'advanced';
61
62 const ADMIN_MENU_PRIORITY = 10;
63
64 public Home_Module $home_module;
65
66 /**
67 * Register admin menu.
68 *
69 * Add new Elementor Settings admin menu.
70 *
71 * Fired by `admin_menu` action.
72 *
73 * @since 1.0.0
74 * @access public
75 */
76 public function register_admin_menu() {
77 global $menu;
78
79 $menu[] = [ '', 'read', 'separator-elementor', '', 'wp-menu-separator elementor' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
80
81 if ( ! current_user_can( 'manage_options' ) ) {
82 return;
83 }
84
85 add_menu_page(
86 esc_html__( 'Elementor', 'elementor' ),
87 esc_html__( 'Elementor', 'elementor' ),
88 'manage_options',
89 self::PAGE_ID,
90 [
91 $this,
92 $this->home_module->is_experiment_active() ? 'display_home_screen' : 'display_settings_page',
93 ],
94 '',
95 '58.5'
96 );
97
98 if ( $this->home_module->is_experiment_active() ) {
99 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
100 $admin_menu->register( 'elementor-settings', new Admin_Menu_Item( $this ) );
101 }, 0 );
102 }
103 }
104
105 public function display_home_screen() {
106 echo '<div id="e-home-screen"></div>';
107 }
108
109 /**
110 * Reorder the Elementor menu items in admin.
111 * Based on WC.
112 *
113 * @since 2.4.0
114 *
115 * @param array $menu_order Menu order.
116 * @return array
117 */
118 public function menu_order( $menu_order ) {
119 // Initialize our custom order array.
120 $elementor_menu_order = [];
121
122 // Get the index of our custom separator.
123 $elementor_separator = array_search( 'separator-elementor', $menu_order, true );
124
125 // Get index of library menu.
126 $elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true );
127
128 // Loop through menu order and do some rearranging.
129 foreach ( $menu_order as $index => $item ) {
130 if ( 'elementor' === $item ) {
131 $elementor_menu_order[] = 'separator-elementor';
132 $elementor_menu_order[] = $item;
133 $elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG;
134
135 unset( $menu_order[ $elementor_separator ] );
136 unset( $menu_order[ $elementor_library ] );
137 } elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) {
138 $elementor_menu_order[] = $item;
139 }
140 }
141
142 // Return order.
143 return $elementor_menu_order;
144 }
145
146 /**
147 * Register Elementor knowledge base sub-menu.
148 *
149 * Add new Elementor knowledge base sub-menu under the main Elementor menu.
150 *
151 * Fired by `admin_menu` action.
152 *
153 * @since 2.0.3
154 * @access private
155 */
156 private function register_knowledge_base_menu( Admin_Menu_Manager $admin_menu ) {
157 $admin_menu->register( 'elementor-getting-started', new Getting_Started_Menu_Item() );
158 $admin_menu->register( 'go_knowledge_base_site', new Get_Help_Menu_Item() );
159 }
160
161 /**
162 * Go Elementor Pro.
163 *
164 * Redirect the Elementor Pro page the clicking the Elementor Pro menu link.
165 *
166 * Fired by `admin_init` action.
167 *
168 * @since 2.0.3
169 * @access public
170 */
171 public function handle_external_redirects() {
172 if ( empty( $_GET['page'] ) ) {
173 return;
174 }
175
176 if ( 'go_knowledge_base_site' === $_GET['page'] ) {
177 wp_redirect( Get_Help_Menu_Item::URL );
178 die;
179 }
180 }
181
182 /**
183 * On admin init.
184 *
185 * Preform actions on WordPress admin initialization.
186 *
187 * Fired by `admin_init` action.
188 *
189 * @since 2.0.0
190 * @access public
191 */
192 public function on_admin_init() {
193 $this->handle_external_redirects();
194
195 $this->maybe_remove_all_admin_notices();
196 }
197
198 /**
199 * Change "Settings" menu name.
200 *
201 * Update the name of the Settings admin menu from "Elementor" to "Settings".
202 *
203 * Fired by `admin_menu` action.
204 *
205 * @since 1.0.0
206 * @access public
207 */
208 public function admin_menu_change_name() {
209 $menu_name = $this->home_module->is_experiment_active()
210 ? esc_html__( 'Home', 'elementor' )
211 : esc_html__( 'Settings', 'elementor' );
212
213 Utils::change_submenu_first_item_label( 'elementor', $menu_name );
214 }
215
216 /**
217 * Update CSS print method.
218 *
219 * Clear post CSS cache.
220 *
221 * Fired by `add_option_elementor_css_print_method` and
222 * `update_option_elementor_css_print_method` actions.
223 *
224 * @since 1.7.5
225 * @access public
226 * @deprecated 3.0.0 Use `Plugin::$instance->files_manager->clear_cache()` method instead.
227 */
228 public function update_css_print_method() {
229 Plugin::$instance->files_manager->clear_cache();
230 }
231
232 /**
233 * Create tabs.
234 *
235 * Return the settings page tabs, sections and fields.
236 *
237 * @since 1.5.0
238 * @access protected
239 *
240 * @return array An array with the settings page tabs, sections and fields.
241 */
242 protected function create_tabs() {
243 $validations_class_name = __NAMESPACE__ . '\Settings_Validations';
244
245 return [
246 self::TAB_GENERAL => [
247 'label' => esc_html__( 'General', 'elementor' ),
248 'sections' => [
249 'general' => [
250 'fields' => [
251 self::UPDATE_TIME_FIELD => [
252 'full_field_id' => self::UPDATE_TIME_FIELD,
253 'field_args' => [
254 'type' => 'hidden',
255 ],
256 'setting_args' => [ $validations_class_name, 'current_time' ],
257 ],
258 'cpt_support' => [
259 'label' => esc_html__( 'Post Types', 'elementor' ),
260 'field_args' => [
261 'type' => 'checkbox_list_cpt',
262 'std' => [ 'page', 'post' ],
263 'exclude' => [ 'attachment', 'elementor_library' ],
264 ],
265 'setting_args' => [ $validations_class_name, 'checkbox_list' ],
266 ],
267 'disable_color_schemes' => [
268 'label' => esc_html__( 'Disable Default Colors', 'elementor' ),
269 'field_args' => [
270 'type' => 'checkbox',
271 'value' => 'yes',
272 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Colors, and make Elementor inherit the colors from your theme.', 'elementor' ),
273 ],
274 ],
275 'disable_typography_schemes' => [
276 'label' => esc_html__( 'Disable Default Fonts', 'elementor' ),
277 'field_args' => [
278 'type' => 'checkbox',
279 'value' => 'yes',
280 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Fonts, and make Elementor inherit the fonts from your theme.', 'elementor' ),
281 ],
282 ],
283 ],
284 ],
285 'usage' => [
286 'label' => esc_html__( 'Improve Elementor', 'elementor' ),
287 'fields' => $this->get_usage_fields(),
288 ],
289 ],
290 ],
291 self::TAB_INTEGRATIONS => [
292 'label' => esc_html__( 'Integrations', 'elementor' ),
293 'sections' => [
294 'google_maps' => [
295 'label' => esc_html__( 'Google Maps Embed API', 'elementor' ),
296 'callback' => function() {
297 printf(
298 /* translators: 1: Link open tag, 2: Link close tag */
299 esc_html__( 'Google Maps Embed API is a free service by Google that allows embedding Google Maps in your site. For more details, visit Google Maps\' %1$sUsing API Keys%2$s page.', 'elementor' ),
300 '<a target="_blank" href="https://developers.google.com/maps/documentation/embed/get-api-key">',
301 '</a>'
302 );
303 },
304 'fields' => [
305 'google_maps_api_key' => [
306 'label' => esc_html__( 'API Key', 'elementor' ),
307 'field_args' => [
308 'class' => 'elementor_google_maps_api_key',
309 'type' => 'text',
310 ],
311 ],
312 ],
313 ],
314 ],
315 ],
316 self::TAB_ADVANCED => [
317 'label' => esc_html__( 'Advanced', 'elementor' ),
318 'sections' => [
319 'advanced' => [
320 'fields' => [
321 'css_print_method' => [
322 'label' => esc_html__( 'CSS Print Method', 'elementor' ),
323 'field_args' => [
324 'class' => 'elementor_css_print_method',
325 'type' => 'select',
326 'std' => 'external',
327 'options' => [
328 'external' => esc_html__( 'External File', 'elementor' ),
329 'internal' => esc_html__( 'Internal Embedding', 'elementor' ),
330 ],
331 'desc' => '<div class="elementor-css-print-method-description" data-value="external" style="display: none">' . esc_html__( 'Use external CSS files for all generated stylesheets. Choose this setting for better performance (recommended).', 'elementor' ) . '</div><div class="elementor-css-print-method-description" data-value="internal" style="display: none">' . esc_html__( 'Use internal CSS that is embedded in the head of the page. For troubleshooting server configuration conflicts and managing development environments.', 'elementor' ) . '</div>',
332 ],
333 ],
334 'editor_break_lines' => [
335 'label' => esc_html__( 'Switch Editor Loader Method', 'elementor' ),
336 'field_args' => [
337 'type' => 'select',
338 'std' => '',
339 'options' => [
340 '' => esc_html__( 'Disable', 'elementor' ),
341 '1' => esc_html__( 'Enable', 'elementor' ),
342 ],
343 'desc' => esc_html__( 'For troubleshooting server configuration conflicts.', 'elementor' ),
344 ],
345 ],
346 'unfiltered_files_upload' => [
347 'label' => esc_html__( 'Enable Unfiltered File Uploads', 'elementor' ),
348 'field_args' => [
349 'type' => 'select',
350 'std' => '',
351 'options' => [
352 '' => esc_html__( 'Disable', 'elementor' ),
353 '1' => esc_html__( 'Enable', 'elementor' ),
354 ],
355 'desc' => esc_html__( 'Please note! Allowing uploads of any files (SVG & JSON included) is a potential security risk.', 'elementor' ) . '<br>' . esc_html__( 'Elementor will try to sanitize the unfiltered files, removing potential malicious code and scripts.', 'elementor' ) . '<br>' . esc_html__( 'We recommend you only enable this feature if you understand the security risks involved.', 'elementor' ),
356 ],
357 ],
358 'google_font' => [
359 'label' => esc_html__( 'Google Fonts', 'elementor' ),
360 'field_args' => [
361 'type' => 'select',
362 'std' => '1',
363 'options' => [
364 '1' => esc_html__( 'Enable', 'elementor' ),
365 '0' => esc_html__( 'Disable', 'elementor' ),
366 ],
367 'desc' => sprintf(
368 esc_html__( 'Disable this option if you want to prevent Google Fonts from being loaded. This setting is recommended when loading fonts from a different source (plugin, theme or %1$scustom fonts%2$s).', 'elementor' ),
369 '<a href="' . admin_url( 'admin.php?page=elementor_custom_fonts' ) . '">',
370 '</a>'
371 ),
372 ],
373 ],
374 'font_display' => [
375 'label' => esc_html__( 'Google Fonts Load', 'elementor' ),
376 'field_args' => [
377 'type' => 'select',
378 'std' => 'auto',
379 'options' => [
380 'auto' => esc_html__( 'Default', 'elementor' ),
381 'block' => esc_html__( 'Blocking', 'elementor' ),
382 'swap' => esc_html__( 'Swap', 'elementor' ),
383 'fallback' => esc_html__( 'Fallback', 'elementor' ),
384 'optional' => esc_html__( 'Optional', 'elementor' ),
385 ],
386 'desc' => esc_html__( 'Font-display property defines how font files are loaded and displayed by the browser.', 'elementor' ) . '<br>' . esc_html__( 'Set the way Google Fonts are being loaded by selecting the font-display property (Default: Auto).', 'elementor' ),
387 ],
388 ],
389 'optimized_gutenberg_loading' => [
390 'label' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ),
391 'field_args' => [
392 'type' => 'select',
393 'std' => '1',
394 'options' => [
395 '1' => esc_html__( 'Enable', 'elementor' ),
396 '0' => esc_html__( 'Disable', 'elementor' ),
397 ],
398 'desc' => esc_html__( 'Use this experiment to reduce unnecessary render-blocking loads, enhancing site performance by dequeuing unused Gutenberg block editor files (styles and scripts).', 'elementor' ),
399 ],
400 ],
401 'optimized_image_loading' => [
402 'label' => esc_html__( 'Optimized Image Loading', 'elementor' ),
403 'field_args' => [
404 'type' => 'select',
405 'std' => '1',
406 'options' => [
407 '1' => esc_html__( 'Enable', 'elementor' ),
408 '0' => esc_html__( 'Disable', 'elementor' ),
409 ],
410 'desc' => sprintf(
411 /* translators: 1: fetchpriority attribute, 2: lazy loading attribute. */
412 esc_html__( 'Applying %1$s on LCP image and %2$s on images below the fold to improve performance scores.', 'elementor' ),
413 '<code>fetchpriority="high"</code>',
414 '<code>loading="lazy"</code>'
415 ),
416 ],
417 ],
418 ],
419 ],
420 ],
421 ],
422 ];
423 }
424
425 /**
426 * Get settings page title.
427 *
428 * Retrieve the title for the settings page.
429 *
430 * @since 1.5.0
431 * @access protected
432 *
433 * @return string Settings page title.
434 */
435 protected function get_page_title() {
436 if ( Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
437 return esc_html__( 'Settings', 'elementor' );
438 }
439
440 return esc_html__( 'Elementor', 'elementor' );
441 }
442
443 /**
444 * @since 2.2.0
445 * @access private
446 */
447 private function maybe_remove_all_admin_notices() {
448 $elementor_pages = [
449 'elementor-getting-started',
450 'elementor-system-info',
451 'e-form-submissions',
452 'elementor_custom_fonts',
453 'elementor_custom_icons',
454 'elementor-license',
455 'elementor_custom_code',
456 'popup_templates',
457 'elementor-apps',
458 ];
459
460 if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
461 return;
462 }
463
464 remove_all_actions( 'admin_notices' );
465 }
466
467 public function add_generator_tag_settings( $settings ) {
468 $css_print_method = get_option( 'elementor_css_print_method', 'external' );
469 $settings[] = 'css_print_method-' . $css_print_method;
470
471 $google_font = Fonts::is_google_fonts_enabled() ? 'enabled' : 'disabled';
472 $settings[] = 'google_font-' . $google_font;
473
474 $font_display = Fonts::get_font_display_setting();
475 $settings[] = 'font_display-' . $font_display;
476
477 return $settings;
478 }
479
480 /**
481 * Settings page constructor.
482 *
483 * Initializing Elementor "Settings" page.
484 *
485 * @since 1.0.0
486 * @access public
487 */
488 public function __construct() {
489 parent::__construct();
490
491 $this->home_module = new Home_Module();
492
493 add_action( 'admin_init', [ $this, 'on_admin_init' ] );
494 add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] );
495
496 if ( ! Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
497 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
498
499 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
500 $this->register_knowledge_base_menu( $admin_menu );
501 }, Promotions_Module::ADMIN_MENU_PRIORITY - 1 );
502
503 add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 );
504
505 add_filter( 'custom_menu_order', '__return_true' );
506 add_filter( 'menu_order', [ $this, 'menu_order' ] );
507 }
508
509 $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
510
511 // Clear CSS Meta after change css related methods.
512 $css_settings = [
513 'elementor_disable_color_schemes',
514 'elementor_disable_typography_schemes',
515 'elementor_css_print_method',
516 ];
517
518 foreach ( $css_settings as $option_name ) {
519 add_action( "add_option_{$option_name}", $clear_cache_callback );
520 add_action( "update_option_{$option_name}", $clear_cache_callback );
521 }
522 }
523 }
524