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

621 lines 19.5 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\Files\Fonts\Google_Font;
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 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
13 use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Home_Menu;
14 use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Settings_Menu;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Elementor "Settings" page in WordPress Dashboard.
22 *
23 * Elementor settings page handler class responsible for creating and displaying
24 * Elementor "Settings" page in WordPress dashboard.
25 *
26 * @since 1.0.0
27 */
28 class Settings extends Settings_Page {
29
30 /**
31 * Settings page ID for Elementor settings.
32 */
33 const PAGE_ID = 'elementor';
34
35 /**
36 * Upgrade menu priority.
37 */
38 const MENU_PRIORITY_GO_PRO = 502;
39
40 /**
41 * Settings page field for update time.
42 */
43 const UPDATE_TIME_FIELD = '_elementor_settings_update_time';
44
45 /**
46 * Settings page general tab slug.
47 */
48 const TAB_GENERAL = 'general';
49
50 /**
51 * Settings page style tab slug.
52 */
53 const TAB_STYLE = 'style';
54
55 /**
56 * Settings page integrations tab slug.
57 */
58 const TAB_INTEGRATIONS = 'integrations';
59
60 /**
61 * Settings page advanced tab slug.
62 */
63 const TAB_ADVANCED = 'advanced';
64
65 /**
66 * Settings page performance tab slug.
67 */
68 const TAB_PERFORMANCE = 'performance';
69
70 const ADMIN_MENU_PRIORITY = 10;
71
72 const MENU_CAPABILITY_MANAGE_OPTIONS = 'manage_options';
73
74 const MENU_CAPABILITY_EDIT_POSTS = 'edit_posts';
75
76 public Home_Module $home_module;
77
78 /**
79 * Register admin menu.
80 *
81 * Add new Elementor Settings admin menu.
82 *
83 * Fired by `admin_menu` action.
84 *
85 * @since 1.0.0
86 * @access public
87 */
88 public function register_admin_menu() {
89 global $menu;
90
91 $menu[] = [ '', 'read', 'separator-elementor', '', 'wp-menu-separator elementor' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
92
93 $required_capability = $this->get_menu_capability();
94
95 if ( ! current_user_can( $required_capability ) ) {
96 return;
97 }
98
99 add_menu_page(
100 esc_html__( 'Elementor', 'elementor' ),
101 esc_html__( 'Elementor', 'elementor' ),
102 $required_capability,
103 self::PAGE_ID,
104 [
105 $this,
106 $this->home_module->is_experiment_active() ? 'display_home_screen' : 'display_settings_page',
107 ],
108 '',
109 '58.5'
110 );
111
112 if ( $this->home_module->is_experiment_active() ) {
113 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
114 if ( ! $this->is_editor_one_active() ) {
115 $admin_menu->register( 'elementor-settings', new Admin_Menu_Item( $this ) );
116 }
117 }, 0 );
118 }
119 }
120
121 public function display_home_screen() {
122 echo '<div id="e-home-screen"></div>';
123 }
124
125 /**
126 * Reorder the Elementor menu items in admin.
127 * Based on WC.
128 *
129 * @since 2.4.0
130 *
131 * @param array $menu_order Menu order.
132 * @return array
133 */
134 public function menu_order( $menu_order ) {
135 // Initialize our custom order array.
136 $elementor_menu_order = [];
137
138 // Get the index of our custom separator.
139 $elementor_separator = array_search( 'separator-elementor', $menu_order, true );
140
141 // Get index of library menu.
142 $elementor_library = array_search( Source_Local::ADMIN_MENU_SLUG, $menu_order, true );
143
144 // Loop through menu order and do some rearranging.
145 foreach ( $menu_order as $index => $item ) {
146 if ( 'elementor' === $item ) {
147 $elementor_menu_order[] = 'separator-elementor';
148 $elementor_menu_order[] = $item;
149 $elementor_menu_order[] = Source_Local::ADMIN_MENU_SLUG;
150
151 unset( $menu_order[ $elementor_separator ] );
152 unset( $menu_order[ $elementor_library ] );
153 } elseif ( ! in_array( $item, [ 'separator-elementor' ], true ) ) {
154 $elementor_menu_order[] = $item;
155 }
156 }
157
158 // Return order.
159 return $elementor_menu_order;
160 }
161
162 /**
163 * Register Elementor knowledge base sub-menu.
164 *
165 * Add new Elementor knowledge base sub-menu under the main Elementor menu.
166 *
167 * Fired by `admin_menu` action.
168 *
169 * @since 2.0.3
170 * @access private
171 */
172 private function register_knowledge_base_menu( Admin_Menu_Manager $admin_menu ) {
173 if ( ! Plugin::instance()->modules_manager->get_modules( 'editor-one' ) ) {
174 $admin_menu->register( 'elementor-getting-started', new Getting_Started_Menu_Item() );
175 $admin_menu->register( 'go_knowledge_base_site', new Get_Help_Menu_Item() );
176 }
177 }
178
179 private function register_editor_one_settings_menu( Menu_Data_Provider $menu_data_provider ) {
180 $menu_data_provider->register_menu( new Editor_One_Settings_Menu() );
181 }
182
183 private function register_editor_one_home_menu( Menu_Data_Provider $menu_data_provider ) {
184 $menu_data_provider->register_menu( new Editor_One_Home_Menu() );
185 }
186
187 private function is_editor_one_active(): bool {
188 return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
189 }
190
191 private function get_menu_capability(): string {
192 return $this->is_editor_one_active() ? self::MENU_CAPABILITY_EDIT_POSTS : self::MENU_CAPABILITY_MANAGE_OPTIONS;
193 }
194
195 /**
196 * Go Elementor Pro.
197 *
198 * Redirect the Elementor Pro page the clicking the Elementor Pro menu link.
199 *
200 * Fired by `admin_init` action.
201 *
202 * @since 2.0.3
203 * @access public
204 */
205 public function handle_external_redirects() {
206 if ( empty( $_GET['page'] ) ) {
207 return;
208 }
209
210 if ( 'go_knowledge_base_site' === $_GET['page'] ) {
211 wp_redirect( Get_Help_Menu_Item::URL );
212 die;
213 }
214 }
215
216 /**
217 * On admin init.
218 *
219 * Preform actions on WordPress admin initialization.
220 *
221 * Fired by `admin_init` action.
222 *
223 * @since 2.0.0
224 * @access public
225 */
226 public function on_admin_init() {
227 $this->handle_external_redirects();
228
229 $this->maybe_remove_all_admin_notices();
230 }
231
232 /**
233 * Change "Settings" menu name.
234 *
235 * Update the name of the Settings admin menu from "Elementor" to "Settings".
236 *
237 * Fired by `admin_menu` action.
238 *
239 * @since 1.0.0
240 * @access public
241 */
242 public function admin_menu_change_name() {
243 $menu_name = $this->home_module->is_experiment_active()
244 ? esc_html__( 'Home', 'elementor' )
245 : esc_html__( 'Settings', 'elementor' );
246
247 Utils::change_submenu_first_item_label( 'elementor', $menu_name );
248 }
249
250 /**
251 * Update CSS print method.
252 *
253 * Clear post CSS cache.
254 *
255 * Fired by `add_option_elementor_css_print_method` and
256 * `update_option_elementor_css_print_method` actions.
257 *
258 * @since 1.7.5
259 * @access public
260 * @deprecated 3.0.0 Use `Plugin::$instance->files_manager->clear_cache()` method instead.
261 */
262 public function update_css_print_method() {
263 Plugin::$instance->files_manager->clear_cache();
264 }
265
266 /**
267 * Create tabs.
268 *
269 * Return the settings page tabs, sections and fields.
270 *
271 * @since 1.5.0
272 * @access protected
273 *
274 * @return array An array with the settings page tabs, sections and fields.
275 */
276 protected function create_tabs() {
277 $validations_class_name = __NAMESPACE__ . '\Settings_Validations';
278
279 return [
280 self::TAB_GENERAL => [
281 'label' => esc_html__( 'General', 'elementor' ),
282 'sections' => [
283 'general' => [
284 'label' => esc_html__( 'General', 'elementor' ),
285 'callback' => function() {
286 printf(
287 '<p>%s</p><br><hr><br>',
288 esc_html__( 'Tailor how Elementor enhances your site, from post types to other functions.', 'elementor' )
289 );
290 },
291 'fields' => [
292 self::UPDATE_TIME_FIELD => [
293 'full_field_id' => self::UPDATE_TIME_FIELD,
294 'field_args' => [
295 'type' => 'hidden',
296 ],
297 'setting_args' => [ $validations_class_name, 'current_time' ],
298 ],
299 'cpt_support' => [
300 'label' => esc_html__( 'Post Types', 'elementor' ),
301 'field_args' => [
302 'type' => 'checkbox_list_cpt',
303 'std' => [ 'page', 'post' ],
304 'exclude' => [ 'attachment', 'elementor_library' ],
305 ],
306 'setting_args' => [ $validations_class_name, 'checkbox_list' ],
307 ],
308 'disable_color_schemes' => [
309 'label' => esc_html__( 'Disable Default Colors', 'elementor' ),
310 'field_args' => [
311 'type' => 'checkbox',
312 'value' => 'yes',
313 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Colors, and make Elementor inherit the colors from your theme.', 'elementor' ),
314 ],
315 ],
316 'disable_typography_schemes' => [
317 'label' => esc_html__( 'Disable Default Fonts', 'elementor' ),
318 'field_args' => [
319 'type' => 'checkbox',
320 'value' => 'yes',
321 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Fonts, and make Elementor inherit the fonts from your theme.', 'elementor' ),
322 ],
323 ],
324 ],
325 ],
326 'usage' => [
327 'label' => esc_html__( 'Improve Elementor', 'elementor' ),
328 'fields' => $this->get_usage_fields(),
329 ],
330 ],
331 ],
332 self::TAB_INTEGRATIONS => [
333 'label' => esc_html__( 'Integrations', 'elementor' ),
334 'sections' => [
335 'google_maps' => [
336 'label' => esc_html__( 'Google Maps Embed API', 'elementor' ),
337 'callback' => function() {
338 printf(
339 /* translators: 1: Link open tag, 2: Link close tag */
340 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' ),
341 '<a target="_blank" href="https://developers.google.com/maps/documentation/embed/get-api-key">',
342 '</a>'
343 );
344 },
345 'fields' => [
346 'google_maps_api_key' => [
347 'label' => esc_html__( 'API Key', 'elementor' ),
348 'field_args' => [
349 'class' => 'elementor_google_maps_api_key',
350 'type' => 'text',
351 ],
352 ],
353 ],
354 ],
355 ],
356 ],
357 self::TAB_ADVANCED => [
358 'label' => esc_html__( 'Advanced', 'elementor' ),
359 'sections' => [
360 'advanced' => [
361 'label' => esc_html__( 'Advanced', 'elementor' ),
362 'callback' => function() {
363 printf(
364 '<p>%s</p><br><hr><br>',
365 esc_html__( 'Personalize the way Elementor works on your website by choosing the advanced features and how they operate.', 'elementor' )
366 );
367 },
368 'fields' => [
369 'editor_break_lines' => [
370 'label' => esc_html__( 'Switch Editor Loader Method', 'elementor' ),
371 'field_args' => [
372 'type' => 'select',
373 'std' => '',
374 'options' => [
375 '' => esc_html__( 'Disable', 'elementor' ),
376 '1' => esc_html__( 'Enable', 'elementor' ),
377 ],
378 'desc' => esc_html__( 'For troubleshooting server configuration conflicts.', 'elementor' ),
379 ],
380 ],
381 'unfiltered_files_upload' => [
382 'label' => esc_html__( 'Enable Unfiltered File Uploads', 'elementor' ),
383 'field_args' => [
384 'type' => 'select',
385 'std' => '',
386 'options' => [
387 '' => esc_html__( 'Disable', 'elementor' ),
388 '1' => esc_html__( 'Enable', 'elementor' ),
389 ],
390 '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' ),
391 ],
392 ],
393 'google_font' => [
394 'label' => esc_html__( 'Google Fonts', 'elementor' ),
395 'field_args' => [
396 'type' => 'select',
397 'std' => '1',
398 'options' => [
399 '1' => esc_html__( 'Enable', 'elementor' ),
400 '0' => esc_html__( 'Disable', 'elementor' ),
401 ],
402 'desc' => sprintf(
403 /* translators: 1: Link opening tag, 2: Link closing tag */
404 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' ),
405 '<a href="' . admin_url( 'admin.php?page=elementor_custom_fonts' ) . '">',
406 '</a>'
407 ),
408 ],
409 ],
410 'font_display' => [
411 'label' => esc_html__( 'Google Fonts Load', 'elementor' ),
412 'field_args' => [
413 'type' => 'select',
414 'std' => 'auto',
415 'options' => [
416 'auto' => esc_html__( 'Default', 'elementor' ),
417 'block' => esc_html__( 'Blocking', 'elementor' ),
418 'swap' => esc_html__( 'Swap', 'elementor' ),
419 'fallback' => esc_html__( 'Fallback', 'elementor' ),
420 'optional' => esc_html__( 'Optional', 'elementor' ),
421 ],
422 '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 (Recommended: Swap).', 'elementor' ),
423 ],
424 ],
425 ],
426 ],
427 ],
428 ],
429 self::TAB_PERFORMANCE => [
430 'label' => esc_html__( 'Performance', 'elementor' ),
431 'sections' => [
432 'performance' => [
433 'label' => esc_html__( 'Performance', 'elementor' ),
434 'callback' => function() {
435 printf(
436 '<p>%s</p><br><hr><br>',
437 esc_html__( 'Improve loading times on your site by selecting the optimization tools that best fit your requirements.', 'elementor' )
438 );
439 },
440 'fields' => [
441 'css_print_method' => [
442 'label' => esc_html__( 'CSS Print Method', 'elementor' ),
443 'field_args' => [
444 'class' => 'elementor_css_print_method',
445 'type' => 'select',
446 'std' => 'external',
447 'options' => [
448 'external' => esc_html__( 'External File', 'elementor' ),
449 'internal' => esc_html__( 'Internal Embedding', 'elementor' ),
450 ],
451 'desc' => sprintf(
452 /* translators: %s: <head> tag. */
453 esc_html__( 'Internal Embedding places all CSS in the %s which works great for troubleshooting, while External File uses external CSS file for better performance (recommended).', 'elementor' ),
454 '<code>&lt;head&gt;</code>',
455 ),
456 ],
457 ],
458 'optimized_image_loading' => [
459 'label' => esc_html__( 'Optimized Image Loading', 'elementor' ),
460 'field_args' => [
461 'type' => 'select',
462 'std' => '1',
463 'options' => [
464 '1' => esc_html__( 'Enable', 'elementor' ),
465 '0' => esc_html__( 'Disable', 'elementor' ),
466 ],
467 'desc' => sprintf(
468 /* translators: 1: fetchpriority attribute, 2: lazy loading attribute. */
469 esc_html__( 'Improve performance by applying %1$s on LCP image and %2$s on images below the fold.', 'elementor' ),
470 '<code>fetchpriority="high"</code>',
471 '<code>loading="lazy"</code>'
472 ),
473 ],
474 ],
475 'optimized_gutenberg_loading' => [
476 'label' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ),
477 'field_args' => [
478 'type' => 'select',
479 'std' => '1',
480 'options' => [
481 '1' => esc_html__( 'Enable', 'elementor' ),
482 '0' => esc_html__( 'Disable', 'elementor' ),
483 ],
484 'desc' => esc_html__( 'Reduce unnecessary render-blocking loads by dequeuing unused Gutenberg block editor scripts and styles.', 'elementor' ),
485 ],
486 ],
487 'lazy_load_background_images' => [
488 'label' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
489 'field_args' => [
490 'type' => 'select',
491 'std' => '1',
492 'options' => [
493 '1' => esc_html__( 'Enable', 'elementor' ),
494 '0' => esc_html__( 'Disable', 'elementor' ),
495 ],
496 'desc' => esc_html__( 'Improve initial page load performance by lazy loading all background images except the first one.', 'elementor' ),
497 ],
498 ],
499 'local_google_fonts' => [
500 'label' => esc_html__( 'Load Google Fonts Locally', 'elementor' ),
501 'field_args' => [
502 'type' => 'select',
503 'std' => '0',
504 'options' => [
505 '1' => esc_html__( 'Enable', 'elementor' ),
506 '0' => esc_html__( 'Disable', 'elementor' ),
507 ],
508 'desc' => esc_html__( 'Load Google fonts locally to benefit from faster performance and ensure GDPR compliance. Fonts will be served from your own server instead of Google’s. Only the very first load (in the editor and on the front end) may take slightly longer.', 'elementor' ),
509 ],
510 ],
511 ],
512 ],
513 ],
514 ],
515 ];
516 }
517
518 /**
519 * Get settings page title.
520 *
521 * Retrieve the title for the settings page.
522 *
523 * @since 1.5.0
524 * @access protected
525 *
526 * @return string Settings page title.
527 */
528 protected function get_page_title() {
529 return esc_html__( 'Elementor', 'elementor' );
530 }
531
532 /**
533 * @since 2.2.0
534 * @access private
535 */
536 private function maybe_remove_all_admin_notices() {
537 $elementor_pages = [
538 'elementor-getting-started',
539 'elementor-system-info',
540 'e-form-submissions',
541 'elementor_custom_fonts',
542 'elementor_custom_icons',
543 'elementor-license',
544 'elementor_custom_code',
545 'popup_templates',
546 'elementor-apps',
547 ];
548
549 if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
550 return;
551 }
552
553 remove_all_actions( 'admin_notices' );
554 }
555
556 public function add_generator_tag_settings( $settings ) {
557 $css_print_method = get_option( 'elementor_css_print_method', 'external' );
558 $settings[] = 'css_print_method-' . $css_print_method;
559
560 $google_font = Fonts::is_google_fonts_enabled() ? 'enabled' : 'disabled';
561 $settings[] = 'google_font-' . $google_font;
562
563 $font_display = Fonts::get_font_display_setting();
564 $settings[] = 'font_display-' . $font_display;
565
566 return $settings;
567 }
568
569 /**
570 * Settings page constructor.
571 *
572 * Initializing Elementor "Settings" page.
573 *
574 * @since 1.0.0
575 * @access public
576 */
577 public function __construct() {
578 parent::__construct();
579
580 $this->home_module = new Home_Module();
581
582 add_action( 'admin_init', [ $this, 'on_admin_init' ] );
583 add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] );
584
585 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
586
587 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
588 if ( $this->home_module->is_experiment_active() ) {
589 $this->register_editor_one_settings_menu( $menu_data_provider );
590 $this->register_editor_one_home_menu( $menu_data_provider );
591 }
592 } );
593
594 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
595 $this->register_knowledge_base_menu( $admin_menu );
596 }, Promotions_Module::ADMIN_MENU_PRIORITY - 1 );
597
598 add_action( 'admin_menu', [ $this, 'admin_menu_change_name' ], 200 );
599
600 add_filter( 'custom_menu_order', '__return_true' );
601 add_filter( 'menu_order', [ $this, 'menu_order' ] );
602
603 $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
604
605 // Clear CSS Meta after change css related methods.
606 $css_settings = [
607 'elementor_disable_color_schemes',
608 'elementor_disable_typography_schemes',
609 'elementor_css_print_method',
610 'elementor_local_google_fonts',
611 ];
612
613 foreach ( $css_settings as $option_name ) {
614 add_action( "add_option_{$option_name}", $clear_cache_callback );
615 add_action( "update_option_{$option_name}", $clear_cache_callback );
616 }
617
618 add_action( 'update_option_elementor_font_display', [ Google_Font::class, 'clear_cache' ] );
619 }
620 }
621