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

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