PluginProbe ʕ •ᴥ•ʔ
Page Builder by SiteOrigin / 2.34.3
Page Builder by SiteOrigin v2.34.3
2.34.3 2.34.2 2.29.5 2.29.6 2.29.7 2.29.8 2.29.9 2.3 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.31.4 2.31.5 2.31.6 2.31.7 2.31.8 2.32.0 2.32.1 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.34.0 2.34.1 2.4 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 2.4.22 2.4.23 2.4.24 2.4.25 2.4.3 2.4.4 2.4.5 2.4.6 2.4.8 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0 2.8.1 2.8.2 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 trunk 2.10.0 2.10.1 2.10.10 2.10.11 2.10.12 2.10.13 2.10.14 2.10.15 2.10.16 2.10.17 2.10.2 2.10.3 2.10.4 2.10.5 2.10.6 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.12.0 2.12.1 2.12.2 2.12.3 2.12.4 2.12.5 2.12.6 2.13.0 2.13.1 2.13.2 2.14.0 2.14.1 2.14.2 2.14.3 2.15.0 2.15.1 2.15.2 2.15.3 2.16.0 2.16.1 2.16.10 2.16.11 2.16.12 2.16.13 2.16.14 2.16.15 2.16.16 2.16.17 2.16.18 2.16.19 2.16.2 2.16.3 2.16.4 2.16.5 2.16.6 2.16.7 2.16.8 2.16.9 2.17.0 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.19.0 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.21.1 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.26.1 2.26.2 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.10 2.29.11 2.29.12 2.29.13 2.29.14 2.29.15 2.29.16 2.29.17 2.29.18 2.29.19 2.29.2 2.29.20 2.29.21 2.29.22 2.29.3 2.29.4
siteorigin-panels / inc / settings.php
siteorigin-panels / inc Last commit date
data 3 years ago installer 3 months ago widgets 3 months ago admin-dashboard.php 2 years ago admin-layouts.php 10 months ago admin-widget-dialog.php 1 year ago admin-widgets-bundle.php 11 months ago admin.php 1 month ago compatibility.php 1 month ago css-builder.php 3 years ago functions.php 3 years ago home.php 3 years ago live-editor.php 2 years ago post-content-filters.php 2 years ago renderer-legacy.php 3 months ago renderer.php 1 month ago revisions.php 3 years ago settings.php 3 months ago sidebars-emulator.php 2 years ago styles-admin.php 11 months ago styles.php 11 months ago widget-shortcode.php 2 years ago
settings.php
803 lines
1 <?php
2
3 /**
4 * Class to handle Page Builder settings.
5 *
6 * Class SiteOrigin_Panels_Settings
7 */
8 class SiteOrigin_Panels_Settings {
9 private $settings;
10 private $fields;
11 private $settings_saved;
12
13 public function __construct() {
14 $this->settings = array();
15 $this->fields = array();
16 $this->settings_saved = false;
17
18 // Admin actions
19 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
20 add_action( 'admin_menu', array( $this, 'add_settings_page' ) );
21 add_action( 'after_setup_theme', array( $this, 'clear_cache' ), 100 );
22
23 // Default filters for fields and defaults
24 add_filter( 'siteorigin_panels_settings_defaults', array( $this, 'settings_defaults' ) );
25 add_filter( 'siteorigin_panels_default_add_widget_class', array( $this, 'add_widget_class' ) );
26 add_filter( 'siteorigin_panels_settings_fields', array( $this, 'settings_fields' ) );
27 }
28
29 /**
30 * @return SiteOrigin_Panels_Settings
31 */
32 public static function single() {
33 static $single;
34
35 return empty( $single ) ? $single = new self() : $single;
36 }
37
38 public function clear_cache() {
39 $this->settings = array();
40 }
41
42 /**
43 * Get a settings value.
44 *
45 * @param string $key
46 *
47 * @return array|bool|mixed|void|null
48 */
49 public function get( $key = '' ) {
50 if ( empty( $this->settings ) ) {
51 // Get the settings, attempt to fetch new settings first.
52 $current_settings = get_option( 'siteorigin_panels_settings', false );
53
54 if ( $current_settings === false ) {
55 // We can't find the settings, so try access old settings.
56 $current_settings = get_option( 'siteorigin_panels_display', array() );
57 $post_types = get_option( 'siteorigin_panels_post_types' );
58
59 if ( ! empty( $post_types ) ) {
60 $current_settings['post-types'] = $post_types;
61 }
62
63 // Store the old settings in the new field.
64 update_option( 'siteorigin_panels_settings', $current_settings );
65 }
66
67 // Get the settings provided by the theme.
68 $theme_settings = get_theme_support( 'siteorigin-panels' );
69
70 if ( ! empty( $theme_settings ) ) {
71 $theme_settings = $theme_settings[0];
72 } else {
73 $theme_settings = array();
74 }
75
76 $this->settings = wp_parse_args( $theme_settings, apply_filters( 'siteorigin_panels_settings_defaults', array() ) );
77 $this->settings = wp_parse_args( $current_settings, $this->settings );
78
79 // Filter these settings
80 $this->settings = apply_filters( 'siteorigin_panels_settings', $this->settings );
81 }
82
83 if ( ! empty( $key ) ) {
84 return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : null;
85 }
86
87 return $this->settings;
88 }
89
90 /**
91 * Set a settings value
92 */
93 public function set( $key, $value ) {
94 $current_settings = get_option( 'siteorigin_panels_settings', array() );
95 $current_settings[ $key ] = $value;
96 update_option( 'siteorigin_panels_settings', $current_settings );
97 }
98
99 /**
100 * Add default settings for the Page Builder settings.
101 *
102 * @return mixed
103 */
104 public function settings_defaults( $defaults ) {
105 $defaults['home-page'] = false;
106 $defaults['home-page-default'] = false;
107 $defaults['home-template'] = 'home-panels.php';
108 $defaults['affiliate-id'] = apply_filters( 'siteorigin_panels_affiliate_id', false );
109 $defaults['display-teaser'] = true;
110 $defaults['display-learn'] = true;
111 $defaults['load-on-attach'] = false;
112 $defaults['use-classic'] = true;
113
114 /**
115 * Certain settings have different defaults depending on if this is a new
116 * install, or not.
117 *
118 * This is done here rather than using `siteorigin_panels_version_changed` as
119 * that hook is triggered after the settings are loaded.
120 */
121 $so_settings = get_option( 'siteorigin_panels_settings' );
122
123 if ( empty( $so_settings ) ) {
124 // New install.
125 $parallax_type = 'modern';
126 $live_editor_close_after = true;
127 $mobile_cell_margin = 30;
128 } else {
129 $live_editor_close_after = false;
130 // Parallax Type.
131 if ( isset( $so_settings['parallax-type'] ) ) {
132 // If parallax-type already exists, use the existing value to prevent a potential override.
133 $parallax_type = $so_settings['parallax-type'];
134 } elseif ( isset( $so_settings['parallax-delay'] ) ) {
135 // User is upgrading.
136 $parallax_type = 'legacy';
137 } else {
138 // If all else fails, fallback to modern.
139 $parallax_type = 'modern';
140 }
141 $mobile_cell_margin = isset( $so_settings['margin-bottom'] ) ? $so_settings['margin-bottom'] : 30;
142 }
143
144 // General fields.
145 $defaults['post-types'] = array( 'page', 'post' );
146 $defaults['live-editor-quick-link'] = true;
147 $defaults['live-editor-quick-link-close-after'] = $live_editor_close_after;
148 $defaults['admin-post-state'] = true;
149 $defaults['admin-widget-count'] = false;
150 $defaults['parallax-type'] = $parallax_type;
151 $defaults['parallax-mobile'] = false;
152 $defaults['parallax-motion'] = ''; // legacy parallax
153 $defaults['parallax-delay'] = 0.4;
154 $defaults['parallax-scale'] = 1.2;
155 $defaults['sidebars-emulator'] = true;
156 $defaults['layout-block-default-mode'] = 'preview';
157 $defaults['layout-block-quick-add'] = true;
158
159 // Widgets fields.
160 $defaults['title-html'] = '<h3 class="widget-title">{{title}}</h3>';
161 $defaults['add-widget-class'] = apply_filters( 'siteorigin_panels_default_add_widget_class', true );
162 $defaults['bundled-widgets'] = get_option( 'siteorigin_panels_is_using_bundled', false );
163 $defaults['recommended-widgets'] = true;
164 $defaults['instant-open-widgets'] = true;
165
166 // Layout fields.
167 $defaults['responsive'] = true;
168 $defaults['tablet-layout'] = false;
169 $defaults['legacy-layout'] = 'auto';
170 $defaults['tablet-width'] = 1024;
171 $defaults['mobile-width'] = 780;
172 $defaults['margin-bottom'] = 30;
173 $defaults['row-mobile-margin-bottom'] = '';
174 $defaults['mobile-cell-margin'] = $mobile_cell_margin;
175 $defaults['widget-mobile-margin-bottom'] = '';
176 $defaults['margin-bottom-last-row'] = false;
177 $defaults['display-empty-rows-with-background'] = false;
178 $defaults['margin-sides'] = 30;
179 $defaults['full-width-container'] = 'body';
180 $defaults['output-css-header'] = 'auto';
181 $defaults['inline-styles'] = false;
182
183 // Content fields.
184 $defaults['copy-content'] = true;
185 $defaults['copy-styles'] = false;
186
187 return $defaults;
188 }
189
190 /**
191 * Set the option on whether to add widget classes for known themes.
192 *
193 * @return bool
194 */
195 public function add_widget_class( $add_class ) {
196 switch ( get_option( 'stylesheet' ) ) {
197 case 'twentysixteen':
198 $add_class = false;
199 break;
200 }
201
202 return $add_class;
203 }
204
205 /**
206 * Enqueue admin scripts
207 */
208 public function admin_scripts( $prefix ) {
209 if ( $prefix != 'settings_page_siteorigin_panels' ) {
210 return;
211 }
212 wp_enqueue_style(
213 'siteorigin-panels-settings',
214 esc_url( siteorigin_panels_url( 'settings/admin-settings.css' ) ),
215 array(),
216 SITEORIGIN_PANELS_VERSION
217 );
218 wp_enqueue_script(
219 'siteorigin-panels-settings',
220 esc_url( siteorigin_panels_url( 'settings/admin-settings' . SITEORIGIN_PANELS_JS_SUFFIX . '.js' ) ),
221 array( 'fitvids' ),
222 SITEORIGIN_PANELS_VERSION
223 );
224 }
225
226 /**
227 * Add the Page Builder settings page
228 */
229 public function add_settings_page() {
230 $page = add_options_page(
231 esc_html__( 'SiteOrigin Page Builder', 'siteorigin-panels' ),
232 esc_html__( 'Page Builder', 'siteorigin-panels' ),
233 'manage_options',
234 'siteorigin_panels',
235 array(
236 $this,
237 'display_settings_page',
238 )
239 );
240 add_action( 'load-' . $page, array( $this, 'add_help_tab' ) );
241 add_action( 'load-' . $page, array( $this, 'save_settings' ) );
242 }
243
244 /**
245 * Display the Page Builder settings page.
246 */
247 public function display_settings_page() {
248 $settings_fields = $this->fields = apply_filters( 'siteorigin_panels_settings_fields', array() );
249 include plugin_dir_path( __FILE__ ) . '../settings/tpl/settings.php';
250 }
251
252 /**
253 * Add a settings help tab.
254 */
255 public function add_help_tab() {
256 $screen = get_current_screen();
257 ob_start();
258 include plugin_dir_path( __FILE__ ) . '../settings/tpl/help.php';
259 $content = ob_get_clean();
260
261 $screen->add_help_tab( array(
262 'id' => 'panels-help-tab',
263 'title' => esc_html__( 'Page Builder Settings', 'siteorigin-panels' ),
264 'content' => $content,
265 ) );
266 }
267
268 /**
269 * Add the default Page Builder settings.
270 *
271 * @return mixed
272 */
273 public function settings_fields( $fields ) {
274 // General settings.
275
276 $fields['general'] = array(
277 'title' => __( 'General', 'siteorigin-panels' ),
278 'fields' => array(),
279 );
280
281 $fields['general']['fields']['post-types'] = array(
282 'type' => 'select_multi',
283 'label' => __( 'Post Types', 'siteorigin-panels' ),
284 'options' => $this->get_post_types(),
285 'description' => __( 'The post types on which to use Page Builder.', 'siteorigin-panels' ),
286 );
287
288 $fields['general']['fields']['use-classic'] = array(
289 'type' => 'checkbox',
290 'label' => __( 'Use Classic Editor for New Posts', 'siteorigin-panels' ),
291 'description' => __( 'New posts of the above Post Types will be created using the Classic Editor.', 'siteorigin-panels' ),
292 );
293
294 $fields['general']['fields']['live-editor-quick-link'] = array(
295 'type' => 'checkbox',
296 'label' => __( 'Live Editor Toolbar Link', 'siteorigin-panels' ),
297 'description' => __( 'Display a Live Editor link in the toolbar when viewing site.', 'siteorigin-panels' ),
298 );
299 $fields['general']['fields']['live-editor-quick-link-close-after'] = array(
300 'type' => 'checkbox',
301 'label' => __( 'Live Editor Toolbar Link: Close After Editing', 'siteorigin-panels' ),
302 'description' => __( 'When accessing the Live Editor via the toolbar link, return to the site after saving.', 'siteorigin-panels' ),
303 );
304
305 $fields['general']['fields']['admin-post-state'] = array(
306 'type' => 'checkbox',
307 'label' => __( 'Display Post State', 'siteorigin-panels' ),
308 'description' => sprintf(
309 __( 'Display a %sSiteOrigin Page Builder%s post state in the admin lists of posts/pages to indicate Page Builder is active.', 'siteorigin-panels' ),
310 '<strong>',
311 '</strong>'
312 ),
313 );
314
315 $fields['general']['fields']['admin-widget-count'] = array(
316 'type' => 'checkbox',
317 'label' => __( 'Display Widget Count', 'siteorigin-panels' ),
318 'description' => __( "Display a widget count in the admin lists of posts/pages where you're using Page Builder.", 'siteorigin-panels' ),
319 );
320
321 $fields['general']['fields']['parallax-type'] = array(
322 'type' => 'select',
323 'label' => __( 'Parallax Type', 'siteorigin-panels' ),
324 'options' => array(
325 'modern' => __( 'Modern', 'siteorigin-panels' ),
326 'legacy' => __( 'Legacy', 'siteorigin-panels' ),
327 ),
328 'description' => __( 'Modern is recommended as it can use smaller images and offers better performance.', 'siteorigin-panels' ),
329 );
330
331 $fields['general']['fields']['parallax-mobile'] = array(
332 'type' => 'checkbox',
333 'label' => __( 'Disable Parallax On Mobile', 'siteorigin-panels' ),
334 'description' => __( 'Disable row/widget background parallax when the browser is smaller than the mobile width.', 'siteorigin-panels' ),
335 );
336
337 // Legacy Parallax.
338 $fields['general']['fields']['parallax-motion'] = array(
339 'type' => 'float',
340 'label' => __( 'Limit Parallax Motion', 'siteorigin-panels' ),
341 'description' => __( 'How many pixels of scrolling results in a single pixel of parallax motion. 0 means automatic. Lower values give a more noticeable effect.', 'siteorigin-panels' ),
342 );
343
344 // Modern Parallax.
345 $fields['general']['fields']['parallax-delay'] = array(
346 'type' => 'float',
347 'label' => __( 'Parallax Delay', 'siteorigin-panels' ),
348 'description' => __( 'The delay before the parallax effect finishes after the user stops scrolling.', 'siteorigin-panels' ),
349 );
350
351 $fields['general']['fields']['parallax-scale'] = array(
352 'type' => 'float',
353 'label' => __( 'Parallax Scale', 'siteorigin-panels' ),
354 'description' => __( 'How much the image is scaled. The higher the scale is set, the more visible the parallax effect will be. Increasing the scale will result in a loss of image quality.', 'siteorigin-panels' ),
355 );
356
357 $fields['general']['fields']['sidebars-emulator'] = array(
358 'type' => 'checkbox',
359 'label' => __( 'Sidebars Emulator', 'siteorigin-panels' ),
360 'description' => __( 'Page Builder will create an emulated sidebar, that contains all widgets in the page.', 'siteorigin-panels' ),
361 );
362
363 $fields['general']['fields']['display-teaser'] = array(
364 'type' => 'checkbox',
365 'label' => __( 'Upgrade Teaser', 'siteorigin-panels' ),
366 'description' => sprintf(
367 __( 'Display the %sSiteOrigin Premium%s upgrade teaser in the Page Builder toolbar.', 'siteorigin-panels' ),
368 '<a href="https://siteorigin.com/downloads/premium/" target="_blank" rel="noopener noreferrer">',
369 '</a>'
370 ),
371 );
372
373 $fields['general']['fields']['load-on-attach'] = array(
374 'type' => 'checkbox',
375 'label' => __( 'Default to Page Builder Interface', 'siteorigin-panels' ),
376 'description' => sprintf(
377 __( 'New Classic Editor posts/pages that you create will start with the Page Builder loaded. The %s"Use Classic Editor for New Posts"%s setting must be enabled.', 'siteorigin-panels' ),
378 '<strong>',
379 '</strong>'
380 ),
381 );
382
383 $fields['general']['fields']['layout-block-default-mode'] = array(
384 'label' => __( 'Layout Block Default Mode', 'siteorigin-panels' ),
385 'type' => 'select',
386 'options' => array(
387 'edit' => __( 'Edit', 'siteorigin-panels' ),
388 'preview' => __( 'Preview', 'siteorigin-panels' ),
389 ),
390 'description' => __( 'Whether to display SiteOrigin Layout Blocks in edit mode or preview mode in the Block Editor.', 'siteorigin-panels' ),
391 );
392
393 $fields['general']['fields']['layout-block-quick-add'] = array(
394 'type' => 'checkbox',
395 'label' => __( 'Block Editor Layout Block Quick Add Button', 'siteorigin-panels' ),
396 'description' => __( 'Display the Add SiteOrigin Layout Block quick add button in the Block Editor.', 'siteorigin-panels' ),
397 );
398
399 $fields['general']['fields']['installer'] = array(
400 'type' => 'checkbox',
401 'label' => __( 'Installer', 'siteorigin-panels' ),
402 'description' => __( 'Display the SiteOrigin Installer admin menu item.', 'siteorigin-panels' ),
403 );
404
405 // Widgets settings.
406
407 $fields['widgets'] = array(
408 'title' => __( 'Widgets', 'siteorigin-panels' ),
409 'fields' => array(),
410 );
411
412 $fields['widgets']['fields']['title-html'] = array(
413 'type' => 'html',
414 'label' => __( 'Widget Title HTML', 'siteorigin-panels' ),
415 'description' => __( 'The HTML used for widget titles. {{title}} is replaced with the widget title.', 'siteorigin-panels' ),
416 );
417
418 $fields['widgets']['fields']['add-widget-class'] = array(
419 'type' => 'checkbox',
420 'label' => __( 'Add Widget Class', 'siteorigin-panels' ),
421 'description' => __( 'Add the widget class to Page Builder widgets. Disable if theme widget styles are negatively impacting widgets in Page Builder.', 'siteorigin-panels' ),
422 );
423
424 $fields['widgets']['fields']['bundled-widgets'] = array(
425 'type' => 'checkbox',
426 'label' => __( 'Legacy Bundled Widgets', 'siteorigin-panels' ),
427 'description' => __( 'Load legacy widgets from Page Builder 1.', 'siteorigin-panels' ),
428 );
429
430 $fields['widgets']['fields']['recommended-widgets'] = array(
431 'type' => 'checkbox',
432 'label' => __( 'Recommended Widgets', 'siteorigin-panels' ),
433 'description' => __( 'Display recommend widgets in the Page Builder Add Widget dialog.', 'siteorigin-panels' ),
434 );
435
436 $fields['widgets']['fields']['instant-open-widgets'] = array(
437 'type' => 'checkbox',
438 'label' => __( 'Instant Open Widgets', 'siteorigin-panels' ),
439 'description' => __( 'Open a widget form as soon as it\'s added to a page.', 'siteorigin-panels' ),
440 );
441
442 // Layout settings.
443
444 $fields['layout'] = array(
445 'title' => __( 'Layout', 'siteorigin-panels' ),
446 'fields' => array(),
447 );
448
449 $fields['layout']['fields']['responsive'] = array(
450 'type' => 'checkbox',
451 'label' => __( 'Responsive Layout', 'siteorigin-panels' ),
452 'description' => __( 'Collapse widgets, rows, and columns on mobile devices.', 'siteorigin-panels' ),
453 );
454
455 $fields['layout']['fields']['tablet-layout'] = array(
456 'type' => 'checkbox',
457 'label' => __( 'Use Tablet Layout', 'siteorigin-panels' ),
458 'description' => __( 'Collapses columns differently on tablet devices.', 'siteorigin-panels' ),
459 );
460
461 $fields['layout']['fields']['legacy-layout'] = array(
462 'type' => 'select',
463 'options' => array(
464 'auto' => __( 'Detect older browsers', 'siteorigin-panels' ),
465 'never' => __( 'Never', 'siteorigin-panels' ),
466 'always' => __( 'Always', 'siteorigin-panels' ),
467 ),
468 'label' => __( 'Use Legacy Layout Engine', 'siteorigin-panels' ),
469 'description' => __( 'For compatibility, the Legacy Layout Engine switches from Flexbox to float when older browsers are detected.', 'siteorigin-panels' ),
470 );
471
472 $fields['layout']['fields']['tablet-width'] = array(
473 'type' => 'number',
474 'unit' => 'px',
475 'label' => __( 'Tablet Width', 'siteorigin-panels' ),
476 'description' => __( 'Device width, in pixels, to collapse into a tablet view.', 'siteorigin-panels' ),
477 );
478
479 $fields['layout']['fields']['mobile-width'] = array(
480 'type' => 'number',
481 'unit' => 'px',
482 'label' => __( 'Mobile Width', 'siteorigin-panels' ),
483 'description' => __( 'Device width, in pixels, to collapse into a mobile view.', 'siteorigin-panels' ),
484 );
485
486 $fields['layout']['fields']['margin-bottom'] = array(
487 'type' => 'number',
488 'unit' => 'px',
489 'label' => __( 'Row/Widget Bottom Margin', 'siteorigin-panels' ),
490 'description' => __( 'Default margin below rows and widgets.', 'siteorigin-panels' ),
491 );
492
493 $fields['layout']['fields']['row-mobile-margin-bottom'] = array(
494 'type' => 'number',
495 'unit' => 'px',
496 'label' => __( 'Mobile Row Bottom Margin', 'siteorigin-panels' ),
497 'description' => __( 'The default margin below rows on mobile.', 'siteorigin-panels' ),
498 );
499
500 $fields['layout']['fields']['margin-bottom-last-row'] = array(
501 'type' => 'checkbox',
502 'label' => __( 'Last Row With Margin', 'siteorigin-panels' ),
503 'description' => __( 'Allow margin below the last row.', 'siteorigin-panels' ),
504 );
505
506 $fields['layout']['fields']['display-empty-rows-with-background'] = array(
507 'type' => 'checkbox',
508 'label' => __( 'Display Empty Columns With Background', 'siteorigin-panels' ),
509 'description' => __( 'Display empty columns when a column background color or image is set.', 'siteorigin-panels' ),
510 );
511
512 $fields['layout']['fields']['mobile-cell-margin'] = array(
513 'type' => 'number',
514 'unit' => 'px',
515 'label' => __( 'Mobile Column Bottom Margin', 'siteorigin-panels' ),
516 'description' => __( 'The default vertical space between columns in a collapsed mobile row.', 'siteorigin-panels' ),
517 );
518
519 $fields['layout']['fields']['widget-mobile-margin-bottom'] = array(
520 'type' => 'number',
521 'unit' => 'px',
522 'label' => __( 'Mobile Widget Bottom Margin', 'siteorigin-panels' ),
523 'description' => __( 'The default widget bottom margin on mobile.', 'siteorigin-panels' ),
524 );
525
526 $fields['layout']['fields']['margin-sides'] = array(
527 'type' => 'number',
528 'unit' => 'px',
529 'label' => __( 'Row Gutter', 'siteorigin-panels' ),
530 'description' => __( 'Default spacing between columns in each row.', 'siteorigin-panels' ),
531 'keywords' => 'margin',
532 );
533
534 $fields['layout']['fields']['full-width-container'] = array(
535 'type' => 'text',
536 'label' => __( 'Full Width Container', 'siteorigin-panels' ),
537 'description' => __( 'The container used for the full width layout.', 'siteorigin-panels' ),
538 'keywords' => 'full width, container, stretch',
539 );
540
541 $fields['layout']['fields']['output-css-header'] = array(
542 'type' => 'select',
543 'options' => array(
544 'auto' => __( 'Automatic', 'siteorigin-panels' ),
545 'header' => __( 'Header', 'siteorigin-panels' ),
546 'footer' => __( 'Footer', 'siteorigin-panels' ),
547 ),
548 'label' => __( 'Page Builder Layout CSS Output Location', 'siteorigin-panels' ),
549 );
550
551 $fields['layout']['fields']['inline-styles'] = array(
552 'type' => 'checkbox',
553 'label' => __( 'Inline Styles', 'siteorigin-panels' ),
554 'description' => __( 'Output margin, border, and padding styles inline to reduce potential Cumulative Layout Shift.', 'siteorigin-panels' ),
555 );
556
557 // Content settings.
558
559 $fields['content'] = array(
560 'title' => __( 'Content', 'siteorigin-panels' ),
561 'fields' => array(),
562 );
563
564 $fields['content']['fields']['copy-content'] = array(
565 'type' => 'checkbox',
566 'label' => __( 'Copy Content', 'siteorigin-panels' ),
567 'description' => __( 'Copy content from Page Builder to post content.', 'siteorigin-panels' ),
568 );
569
570 $fields['content']['fields']['copy-styles'] = array(
571 'type' => 'checkbox',
572 'label' => __( 'Copy Styles', 'siteorigin-panels' ),
573 'description' => __( 'Include styles into your Post Content. This keeps page layouts, even when Page Builder is deactivated.', 'siteorigin-panels' ),
574 );
575
576 return $fields;
577 }
578
579 /**
580 * Display a settings field.
581 */
582 public function display_field( $field_id, $field ) {
583 $value = $field_id != 'installer' ? siteorigin_panels_setting( $field_id ) : (bool) get_option( 'siteorigin_installer', true );
584
585 $field_name = 'panels_setting[' . $field_id . ']';
586
587 switch ( $field['type'] ) {
588 case 'text':
589 case 'float':
590 ?><input name="<?php echo esc_attr( $field_name ); ?>"
591 class="panels-setting-<?php echo esc_attr( $field['type'] ); ?>" type="text"
592 value="<?php echo esc_attr( $value ); ?>" /> <?php
593 break;
594
595 case 'password':
596 ?><input name="<?php echo esc_attr( $field_name ); ?>"
597 class="panels-setting-<?php echo esc_attr( $field['type'] ); ?>" type="password"
598 value="<?php echo esc_attr( $value ); ?>" /> <?php
599 break;
600
601 case 'number':
602 ?>
603 <input name="<?php echo esc_attr( $field_name ); ?>" type="number"
604 class="panels-setting-<?php echo esc_attr( $field['type'] ); ?>"
605 value="<?php echo esc_attr( $value ); ?>"/>
606 <?php
607 if ( ! empty( $field['unit'] ) ) {
608 echo esc_html( $field['unit'] );
609 }
610 break;
611
612 case 'html':
613 ?><textarea name="<?php echo esc_attr( $field_name ); ?>"
614 class="panels-setting-<?php echo esc_attr( $field['type'] ); ?> widefat"
615 rows="<?php echo ! empty( $field['rows'] ) ? (int) $field['rows'] : 2; ?>"><?php echo esc_textarea( $value ); ?></textarea> <?php
616 break;
617
618 case 'checkbox':
619 ?>
620 <label class="widefat">
621 <input name="<?php echo esc_attr( $field_name ); ?>"
622 type="checkbox" <?php checked( ! empty( $value ) ); ?> />
623 <?php echo esc_html( ! empty( $field['checkbox_text'] ) ? $field['checkbox_text'] : __( 'Enabled', 'siteorigin-panels' ) ); ?>
624 </label>
625 <?php
626 break;
627
628 case 'select':
629 ?>
630 <select name="<?php echo esc_attr( $field_name ); ?>">
631 <?php foreach ( $field['options'] as $option_id => $option ) { ?>
632 <option
633 value="<?php echo esc_attr( $option_id ); ?>" <?php selected( $option_id, $value ); ?>>
634 <?php echo esc_html( $option ); ?>
635 </option>
636 <?php } ?>
637 </select>
638 <?php
639 break;
640
641 case 'select_multi':
642 foreach ( $field['options'] as $option_id => $option ) {
643 ?>
644 <label class="widefat">
645 <input name="<?php echo esc_attr( $field_name ); ?>[<?php echo esc_attr( $option_id ); ?>]"
646 type="checkbox" <?php checked( in_array( $option_id, $value ) ); ?> />
647 <?php echo esc_html( $option ); ?>
648 </label>
649 <?php
650 }
651
652 break;
653 }
654 }
655
656 /**
657 * Save the Page Builder settings.
658 */
659 public function save_settings() {
660 $screen = get_current_screen();
661
662 if ( $screen->base != 'settings_page_siteorigin_panels' ) {
663 return;
664 }
665
666 if ( ! current_user_can( 'manage_options' ) ) {
667 return;
668 }
669
670 if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'panels-settings' ) ) {
671 return;
672 }
673
674 if ( empty( $_POST['panels_setting'] ) ) {
675 return;
676 }
677
678 $values = array();
679 $post = stripslashes_deep( $_POST['panels_setting'] );
680 $settings_fields = $this->fields = apply_filters( 'siteorigin_panels_settings_fields', array() );
681
682 if ( empty( $settings_fields ) ) {
683 return;
684 }
685
686 foreach ( $settings_fields as $section_id => $section ) {
687 if ( empty( $section['fields'] ) ) {
688 continue;
689 }
690
691 foreach ( $section['fields'] as $field_id => $field ) {
692 // Sanitize the fields
693 switch ( $field['type'] ) {
694 case 'text':
695 $values[ $field_id ] = ! empty( $post[ $field_id ] ) ? sanitize_text_field( $post[ $field_id ] ) : '';
696 break;
697
698 case 'number':
699 if ( $post[ $field_id ] != '' ) {
700 $values[ $field_id ] = ! empty( $post[ $field_id ] ) ? (int) $post[ $field_id ] : 0;
701 } else {
702 $values[ $field_id ] = '';
703 }
704 break;
705
706 case 'float':
707 if ( $post[ $field_id ] != '' ) {
708 $values[ $field_id ] = ! empty( $post[ $field_id ] ) ? (float) $post[ $field_id ] : 0;
709 } else {
710 $values[ $field_id ] = '';
711 }
712 break;
713
714 case 'html':
715 $values[ $field_id ] = ! empty( $post[ $field_id ] ) ? $post[ $field_id ] : '';
716 $values[ $field_id ] = wp_kses_post( $values[ $field_id ] );
717 $values[ $field_id ] = force_balance_tags( $values[ $field_id ] );
718 break;
719
720 case 'checkbox':
721 $values[ $field_id ] = ! empty( $post[ $field_id ] );
722 break;
723
724 case 'select':
725 $values[ $field_id ] = ! empty( $post[ $field_id ] ) ? $post[ $field_id ] : '';
726
727 if ( ! in_array( $values[ $field_id ], array_keys( $field['options'] ) ) ) {
728 unset( $values[ $field_id ] );
729 }
730 break;
731
732 case 'select_multi':
733 $values[ $field_id ] = array();
734 $multi_values = array();
735
736 foreach ( $field['options'] as $option_id => $option ) {
737 $multi_values[ $option_id ] = ! empty( $post[ $field_id ][ $option_id ] );
738 }
739
740 foreach ( $multi_values as $k => $v ) {
741 if ( $v ) {
742 $values[ $field_id ][] = $k;
743 }
744 }
745
746 break;
747 }
748 }
749 }
750
751 // Don't let mobile width go below 320.
752 $values[ 'mobile-width' ] = max( $values[ 'mobile-width' ], 320 );
753
754 if ( isset( $values['installer'] ) ) {
755 update_option( 'siteorigin_installer', (string) rest_sanitize_boolean( $values['installer'] ) );
756 unset( $values['installer'] );
757 }
758
759 // Save the values to the database.
760 update_option( 'siteorigin_panels_settings', $values );
761 do_action( 'siteorigin_panels_save_settings', $values );
762 $this->settings = wp_parse_args( $values, $this->settings );
763 $this->settings_saved = true;
764 }
765
766 /**
767 * Get a post type array.
768 *
769 * @return array
770 */
771 public function get_post_types() {
772 $post_types = get_post_types( array( '_builtin' => false ) );
773
774 $types = array(
775 'page' => 'page',
776 'post' => 'post',
777 );
778
779 // Don't use `array_merge` here as it will break things if a post type has a numeric slug.
780 foreach ( $post_types as $key => $value ) {
781 $types[ $key ] = $value;
782 }
783
784 // These are post types we know we don't want to show Page Builder on.
785 unset( $types['ml-slider'] );
786 unset( $types['shop_coupon'] );
787 unset( $types['shop_order'] );
788
789 foreach ( $types as $type_id => $type ) {
790 $type_object = get_post_type_object( $type_id );
791
792 if ( ! $type_object->show_ui ) {
793 unset( $types[ $type_id ] );
794 continue;
795 }
796
797 $types[ $type_id ] = $type_object->label;
798 }
799
800 return apply_filters( 'siteorigin_panels_settings_enabled_post_types', $types );
801 }
802 }
803