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

473 lines 15.2 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\Files\Fonts\Google_Font;
5 use Elementor\Modules\Promotions\Module as Promotions_Module;
6 use Elementor\TemplateLibrary\Source_Local;
7 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
8 use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Home_Menu;
9 use Elementor\Includes\Settings\AdminMenuItems\Editor_One_Settings_Menu;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Elementor "Settings" page in WordPress Dashboard.
17 *
18 * Elementor settings page handler class responsible for creating and displaying
19 * Elementor "Settings" page in WordPress dashboard.
20 *
21 * @since 1.0.0
22 */
23 class Settings extends Settings_Page {
24
25 /**
26 * Settings page ID for Elementor settings.
27 */
28 const PAGE_ID = 'elementor';
29
30 /**
31 * Upgrade menu priority.
32 */
33 const MENU_PRIORITY_GO_PRO = 502;
34
35 /**
36 * Settings page field for update time.
37 */
38 const UPDATE_TIME_FIELD = '_elementor_settings_update_time';
39
40 /**
41 * Settings page general tab slug.
42 */
43 const TAB_GENERAL = 'general';
44
45 /**
46 * Settings page integrations tab slug.
47 */
48 const TAB_INTEGRATIONS = 'integrations';
49
50 /**
51 * Settings page advanced tab slug.
52 */
53 const TAB_ADVANCED = 'advanced';
54
55 /**
56 * Settings page performance tab slug.
57 */
58 const TAB_PERFORMANCE = 'performance';
59
60 const ADMIN_MENU_PRIORITY = 10;
61
62 const MENU_CAPABILITY_EDIT_POSTS = 'edit_posts';
63
64 /**
65 * Register admin menu.
66 *
67 * Add new Elementor Settings admin menu.
68 *
69 * Fired by `admin_menu` action.
70 *
71 * @since 1.0.0
72 * @access public
73 */
74 public function register_admin_menu() {
75 if ( ! current_user_can( self::MENU_CAPABILITY_EDIT_POSTS ) ) {
76 return;
77 }
78
79 add_menu_page(
80 esc_html__( 'Elementor', 'elementor' ),
81 esc_html__( 'Elementor', 'elementor' ),
82 self::MENU_CAPABILITY_EDIT_POSTS,
83 self::PAGE_ID,
84 [ $this, 'display_home_screen' ],
85 '',
86 '58.5'
87 );
88 }
89
90 public function display_home_screen() {
91 echo '<div id="e-home-screen"></div>';
92 }
93
94 private function register_editor_one_settings_menu( Menu_Data_Provider $menu_data_provider ) {
95 $menu_data_provider->register_menu( new Editor_One_Settings_Menu() );
96 }
97
98 private function register_editor_one_home_menu( Menu_Data_Provider $menu_data_provider ) {
99 $menu_data_provider->register_menu( new Editor_One_Home_Menu() );
100 }
101
102 /**
103 * On admin init.
104 *
105 * Preform actions on WordPress admin initialization.
106 *
107 * Fired by `admin_init` action.
108 *
109 * @since 2.0.0
110 * @access public
111 */
112 public function on_admin_init() {
113 $this->maybe_remove_all_admin_notices();
114 }
115
116 /**
117 * Update CSS print method.
118 *
119 * Clear post CSS cache.
120 *
121 * Fired by `add_option_elementor_css_print_method` and
122 * `update_option_elementor_css_print_method` actions.
123 *
124 * @since 1.7.5
125 * @access public
126 * @deprecated 3.0.0 Use `Plugin::$instance->files_manager->clear_cache()` method instead.
127 */
128 public function update_css_print_method() {
129 Plugin::$instance->files_manager->clear_cache();
130 }
131
132 /**
133 * Create tabs.
134 *
135 * Return the settings page tabs, sections and fields.
136 *
137 * @since 1.5.0
138 * @access protected
139 *
140 * @return array An array with the settings page tabs, sections and fields.
141 */
142 protected function create_tabs() {
143 $validations_class_name = __NAMESPACE__ . '\Settings_Validations';
144
145 return [
146 self::TAB_GENERAL => [
147 'label' => esc_html__( 'General', 'elementor' ),
148 'sections' => [
149 'general' => [
150 'label' => esc_html__( 'General', 'elementor' ),
151 'callback' => function() {
152 printf(
153 '<p>%s</p><br><hr><br>',
154 esc_html__( 'Tailor how Elementor enhances your site, from post types to other functions.', 'elementor' )
155 );
156 },
157 'fields' => [
158 self::UPDATE_TIME_FIELD => [
159 'full_field_id' => self::UPDATE_TIME_FIELD,
160 'field_args' => [
161 'type' => 'hidden',
162 ],
163 'setting_args' => [ $validations_class_name, 'current_time' ],
164 ],
165 'cpt_support' => [
166 'label' => esc_html__( 'Post Types', 'elementor' ),
167 'field_args' => [
168 'type' => 'checkbox_list_cpt',
169 'std' => [ 'page', 'post' ],
170 'exclude' => [ 'attachment', 'elementor_library' ],
171 ],
172 'setting_args' => [ $validations_class_name, 'checkbox_list' ],
173 ],
174 'disable_color_schemes' => [
175 'label' => esc_html__( 'Disable Default Colors', 'elementor' ),
176 'field_args' => [
177 'type' => 'checkbox',
178 'value' => 'yes',
179 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Colors, and make Elementor inherit the colors from your theme.', 'elementor' ),
180 ],
181 ],
182 'disable_typography_schemes' => [
183 'label' => esc_html__( 'Disable Default Fonts', 'elementor' ),
184 'field_args' => [
185 'type' => 'checkbox',
186 'value' => 'yes',
187 'sub_desc' => esc_html__( 'Checking this box will disable Elementor\'s Default Fonts, and make Elementor inherit the fonts from your theme.', 'elementor' ),
188 ],
189 ],
190 ],
191 ],
192 'usage' => [
193 'label' => esc_html__( 'Improve Elementor', 'elementor' ),
194 'fields' => $this->get_usage_fields(),
195 ],
196 ],
197 ],
198 self::TAB_INTEGRATIONS => [
199 'label' => esc_html__( 'Integrations', 'elementor' ),
200 'sections' => [
201 'google_maps' => [
202 'label' => esc_html__( 'Google Maps Embed API', 'elementor' ),
203 'callback' => function() {
204 printf(
205 /* translators: 1: Link open tag, 2: Link close tag */
206 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' ),
207 '<a target="_blank" href="https://developers.google.com/maps/documentation/embed/get-api-key">',
208 '</a>'
209 );
210 },
211 'fields' => [
212 'google_maps_api_key' => [
213 'label' => esc_html__( 'API Key', 'elementor' ),
214 'field_args' => [
215 'class' => 'elementor_google_maps_api_key',
216 'type' => 'text',
217 ],
218 ],
219 ],
220 ],
221 ],
222 ],
223 self::TAB_ADVANCED => [
224 'label' => esc_html__( 'Advanced', 'elementor' ),
225 'sections' => [
226 'advanced' => [
227 'label' => esc_html__( 'Advanced', 'elementor' ),
228 'callback' => function() {
229 printf(
230 '<p>%s</p><br><hr><br>',
231 esc_html__( 'Personalize the way Elementor works on your website by choosing the advanced features and how they operate.', 'elementor' )
232 );
233 },
234 'fields' => [
235 'editor_break_lines' => [
236 'label' => esc_html__( 'Switch Editor Loader Method', 'elementor' ),
237 'field_args' => [
238 'type' => 'select',
239 'std' => '',
240 'options' => [
241 '' => esc_html__( 'Disable', 'elementor' ),
242 '1' => esc_html__( 'Enable', 'elementor' ),
243 ],
244 'desc' => esc_html__( 'For troubleshooting server configuration conflicts.', 'elementor' ),
245 ],
246 ],
247 'unfiltered_files_upload' => [
248 'label' => esc_html__( 'Enable Unfiltered File Uploads', 'elementor' ),
249 'field_args' => [
250 'type' => 'select',
251 'std' => '',
252 'options' => [
253 '' => esc_html__( 'Disable', 'elementor' ),
254 '1' => esc_html__( 'Enable', 'elementor' ),
255 ],
256 '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' ),
257 ],
258 ],
259 'google_font' => [
260 'label' => esc_html__( 'Google Fonts', 'elementor' ),
261 'field_args' => [
262 'type' => 'select',
263 'std' => '1',
264 'options' => [
265 '1' => esc_html__( 'Enable', 'elementor' ),
266 '0' => esc_html__( 'Disable', 'elementor' ),
267 ],
268 'desc' => sprintf(
269 /* translators: 1: Link opening tag, 2: Link closing tag */
270 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' ),
271 '<a href="' . admin_url( 'admin.php?page=elementor_custom_fonts' ) . '">',
272 '</a>'
273 ),
274 ],
275 ],
276 'font_display' => [
277 'label' => esc_html__( 'Google Fonts Load', 'elementor' ),
278 'field_args' => [
279 'type' => 'select',
280 'std' => 'auto',
281 'options' => [
282 'auto' => esc_html__( 'Default', 'elementor' ),
283 'block' => esc_html__( 'Blocking', 'elementor' ),
284 'swap' => esc_html__( 'Swap', 'elementor' ),
285 'fallback' => esc_html__( 'Fallback', 'elementor' ),
286 'optional' => esc_html__( 'Optional', 'elementor' ),
287 ],
288 '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' ),
289 ],
290 ],
291 ],
292 ],
293 ],
294 ],
295 self::TAB_PERFORMANCE => [
296 'label' => esc_html__( 'Performance', 'elementor' ),
297 'sections' => [
298 'performance' => [
299 'label' => esc_html__( 'Performance', 'elementor' ),
300 'callback' => function() {
301 printf(
302 '<p>%s</p><br><hr><br>',
303 esc_html__( 'Improve loading times on your site by selecting the optimization tools that best fit your requirements.', 'elementor' )
304 );
305 },
306 'fields' => [
307 'css_print_method' => [
308 'label' => esc_html__( 'CSS Print Method', 'elementor' ),
309 'field_args' => [
310 'class' => 'elementor_css_print_method',
311 'type' => 'select',
312 'std' => 'external',
313 'options' => [
314 'external' => esc_html__( 'External File', 'elementor' ),
315 'internal' => esc_html__( 'Internal Embedding', 'elementor' ),
316 ],
317 'desc' => sprintf(
318 /* translators: %s: <head> tag. */
319 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' ),
320 '<code>&lt;head&gt;</code>',
321 ),
322 ],
323 ],
324 'optimized_image_loading' => [
325 'label' => esc_html__( 'Optimized Image Loading', 'elementor' ),
326 'field_args' => [
327 'type' => 'select',
328 'std' => '1',
329 'options' => [
330 '1' => esc_html__( 'Enable', 'elementor' ),
331 '0' => esc_html__( 'Disable', 'elementor' ),
332 ],
333 'desc' => sprintf(
334 /* translators: 1: fetchpriority attribute, 2: lazy loading attribute. */
335 esc_html__( 'Improve performance by applying %1$s on LCP image and %2$s on images below the fold.', 'elementor' ),
336 '<code>fetchpriority="high"</code>',
337 '<code>loading="lazy"</code>'
338 ),
339 ],
340 ],
341 'optimized_gutenberg_loading' => [
342 'label' => esc_html__( 'Optimized Gutenberg Loading', 'elementor' ),
343 'field_args' => [
344 'type' => 'select',
345 'std' => '1',
346 'options' => [
347 '1' => esc_html__( 'Enable', 'elementor' ),
348 '0' => esc_html__( 'Disable', 'elementor' ),
349 ],
350 'desc' => esc_html__( 'Reduce unnecessary render-blocking loads by dequeuing unused Gutenberg block editor scripts and styles.', 'elementor' ),
351 ],
352 ],
353 'lazy_load_background_images' => [
354 'label' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
355 'field_args' => [
356 'type' => 'select',
357 'std' => '1',
358 'options' => [
359 '1' => esc_html__( 'Enable', 'elementor' ),
360 '0' => esc_html__( 'Disable', 'elementor' ),
361 ],
362 'desc' => esc_html__( 'Improve initial page load performance by lazy loading all background images except the first one.', 'elementor' ),
363 ],
364 ],
365 'local_google_fonts' => [
366 'label' => esc_html__( 'Load Google Fonts Locally', 'elementor' ),
367 'field_args' => [
368 'type' => 'select',
369 'std' => '0',
370 'options' => [
371 '1' => esc_html__( 'Enable', 'elementor' ),
372 '0' => esc_html__( 'Disable', 'elementor' ),
373 ],
374 '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' ),
375 ],
376 ],
377 ],
378 ],
379 ],
380 ],
381 ];
382 }
383
384 /**
385 * Get settings page title.
386 *
387 * Retrieve the title for the settings page.
388 *
389 * @since 1.5.0
390 * @access protected
391 *
392 * @return string Settings page title.
393 */
394 protected function get_page_title() {
395 return esc_html__( 'Elementor', 'elementor' );
396 }
397
398 /**
399 * @since 2.2.0
400 * @access private
401 */
402 private function maybe_remove_all_admin_notices() {
403 $elementor_pages = [
404 'elementor-system-info',
405 'e-form-submissions',
406 'elementor_custom_fonts',
407 'elementor_custom_icons',
408 'elementor-license',
409 'elementor_custom_code',
410 'popup_templates',
411 'elementor-apps',
412 ];
413
414 if ( empty( $_GET['page'] ) || ! in_array( $_GET['page'], $elementor_pages, true ) ) {
415 return;
416 }
417
418 remove_all_actions( 'admin_notices' );
419 }
420
421 public function add_generator_tag_settings( $settings ) {
422 $css_print_method = get_option( 'elementor_css_print_method', 'external' );
423 $settings[] = 'css_print_method-' . $css_print_method;
424
425 $google_font = Fonts::is_google_fonts_enabled() ? 'enabled' : 'disabled';
426 $settings[] = 'google_font-' . $google_font;
427
428 $font_display = Fonts::get_font_display_setting();
429 $settings[] = 'font_display-' . $font_display;
430
431 return $settings;
432 }
433
434 /**
435 * Settings page constructor.
436 *
437 * Initializing Elementor "Settings" page.
438 *
439 * @since 1.0.0
440 * @access public
441 */
442 public function __construct() {
443 parent::__construct();
444
445 add_action( 'admin_init', [ $this, 'on_admin_init' ] );
446 add_filter( 'elementor/generator_tag/settings', [ $this, 'add_generator_tag_settings' ] );
447
448 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 20 );
449
450 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
451 $this->register_editor_one_settings_menu( $menu_data_provider );
452 $this->register_editor_one_home_menu( $menu_data_provider );
453 } );
454
455 $clear_cache_callback = [ Plugin::$instance->files_manager, 'clear_cache' ];
456
457 // Clear CSS Meta after change css related methods.
458 $css_settings = [
459 'elementor_disable_color_schemes',
460 'elementor_disable_typography_schemes',
461 'elementor_css_print_method',
462 'elementor_local_google_fonts',
463 ];
464
465 foreach ( $css_settings as $option_name ) {
466 add_action( "add_option_{$option_name}", $clear_cache_callback );
467 add_action( "update_option_{$option_name}", $clear_cache_callback );
468 }
469
470 add_action( 'update_option_elementor_font_display', [ Google_Font::class, 'clear_cache' ] );
471 }
472 }
473