Repository navigation
Expand file tree
/
Copy pathpanels-lite.php
More file actions
610 lines (502 loc) · 22.4 KB
/
Copy pathpanels-lite.php
File metadata and controls
610 lines (502 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<?php
define('SITEORIGIN_PANELS_LITE_VERSION', '1.0');
include get_template_directory() . '/inc/panels-lite/inc/css.php';
include get_template_directory() . '/inc/panels-lite/inc/default-styles.php';
include get_template_directory() . '/inc/panels-lite/inc/widgets.php';
/**
* Get a localization string
*
* @param bool|false $key
*
* @return mixed|void
*/
function siteorigin_panels_lite_localization( $key = false ){
static $loc = false;
if( empty($loc) ) {
$loc = apply_filters( 'siteorigin_panels_lite_localization', array(
'page_builder' => __( 'Page Builder', 'siteorigin' ),
'home_page_title' => __( 'Custom Home Page Builder', 'siteorigin' ),
'home_page_menu' => __( 'Home Page', 'siteorigin' ),
'install_plugin' => __( 'Install Page Builder Plugin', 'siteorigin' ),
'on_text' => __( 'On', 'siteorigin' ),
'off_text' => __( 'Off', 'siteorigin' ),
// Longer message to display to a user about installing the plugin
'home_install_message' => __( 'This theme supports Page Builder to create beautifully proportioned column based content.', 'siteorigin' ),
'home_disable_message' => '', // Message about disabling the custom home page if the user doesn't want to use it
) );
}
if( empty($key) ) return $loc;
else {
return $loc[$key];
}
return $loc;
}
/**
* Add the admin menu entries
*/
function siteorigin_panels_lite_admin_menu(){
add_theme_page(
siteorigin_panels_lite_localization( 'home_page_title' ),
siteorigin_panels_lite_localization( 'home_page_menu' ),
'edit_theme_options',
'so_panels_home_page',
'siteorigin_panels_lite_render_admin_home_page'
);
}
add_action('admin_menu', 'siteorigin_panels_lite_admin_menu');
/**
* Render the page used to build the custom home page.
*/
function siteorigin_panels_lite_render_admin_home_page(){
add_meta_box( 'so-panels-panels', siteorigin_panels_lite_localization( 'page_builder' ), 'siteorigin_panels_metabox_render', 'appearance_page_so_panels_home_page', 'advanced', 'high' );
if(isset($_GET['_wpnonce']) && isset($_GET['toggle']) && wp_verify_nonce($_GET['_wpnonce'], 'toggle_panels_home')){
// Update home page enabled setting
set_theme_mod('siteorigin_panels_home_page_enabled', (bool) $_GET['panels_new']);
}
get_template_part('inc/panels-lite/tpl/admin', 'home-page');
}
/**
* Handle the action for toggling the value of the home page theme mod
*/
function siteorigin_panels_lite_handle_toggle(){
if( !current_user_can('edit_theme_options') ) exit();
if( empty($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'toggle_panels_home') ) exit();
set_theme_mod('siteorigin_panels_home_page_enabled', (bool) $_GET['panels_new']);
if( !empty($_GET['redirect']) ) {
wp_redirect( $_GET['redirect'] );
}
else {
wp_redirect( admin_url('themes.php?page=so_panels_home_page') );
}
exit();
}
add_action('wp_ajax_panels_lite_toggle', 'siteorigin_panels_lite_handle_toggle');
/**
* Enqueue any required admin scripts.
*
* @param $prefix
*/
function siteorigin_panels_lite_enqueue_admin($prefix){
if($prefix == 'appearance_page_so_panels_home_page'){
add_thickbox();
wp_enqueue_script('plugin-install');
wp_enqueue_style('siteorigin-panels-lite-teaser', get_template_directory_uri().'/inc/panels-lite/css/panels-admin.css');
}
if( ( $prefix == 'post.php' || $prefix == 'post-new.php' ) ) {
if( current_user_can( 'install_plugins' ) ) {
add_thickbox();
wp_enqueue_script('plugin-install');
wp_enqueue_script( 'siteorigin-panels-lite-teaser', get_template_directory_uri() . '/inc/panels-lite/js/tab' . SITEORIGIN_THEME_JS_PREFIX . '.js', array( 'jquery' ), SITEORIGIN_PANELS_LITE_VERSION );
wp_localize_script( 'siteorigin-panels-lite-teaser', 'panelsLiteTeaser', array(
'tab' => siteorigin_panels_lite_localization( 'page_builder' ),
'installUrl' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=siteorigin-panels&width=600&height=550' ),
) );
wp_enqueue_style( 'siteorigin-panels-lite-teaser', get_template_directory_uri() . '/inc/panels-lite/css/post-teaser.css', array(), SITEORIGIN_PANELS_LITE_VERSION );
}
}
}
add_action('admin_enqueue_scripts', 'siteorigin_panels_lite_enqueue_admin');
/**
* The admin action for displaying content
*/
function siteorigin_panels_lite_install_content(){
if( !current_user_can( 'install_plugins' ) ) exit();
get_template_part('inc/panels-lite/tpl/install');
exit();
}
add_action('wp_ajax_panels_lite_install_content', 'siteorigin_panels_lite_install_content');
/**
* Get a setting value
*
* @param bool $key
* @return mixed|null|void
*/
function siteorigin_panels_lite_setting($key = false){
$settings = get_theme_support('siteorigin-panels');
if(!empty($settings)) $settings = $settings[0];
else $settings = array();
$settings = wp_parse_args( $settings, array(
'home-page' => false, // Is Appearance > Home Page supported?
'home-page-default' => false, // A string containg the name of the exported layout to be used.
'home-template' => 'home-panels.php', // The page template used for the home page.
'home-demo-template' => false, // A string containg the name of the file to be used.
'post-types' => get_option('siteorigin_panels_post_types', array('page', 'post') ), // Post types that can be edited.
'bundled-widgets' => !isset( $display_settings['bundled-widgets'] ) ? true : $display_settings['bundled-widgets'], // Include bundled widgets.
'responsive' => !isset( $display_settings['responsive'] ) ? true : $display_settings['responsive'], // Should we use a responsive layout?
'mobile-width' => !isset( $display_settings['mobile-width'] ) ? 780 : $display_settings['mobile-width'], // What is considered a mobile width?
'margin-bottom' => !isset( $display_settings['margin-bottom'] ) ? 30 : $display_settings['margin-bottom'], // Row bottom margin.
'margin-sides' => !isset( $display_settings['margin-sides'] ) ? 30 : $display_settings['margin-sides'], // Row gutter, the amount of space between cells.
'affiliate-id' => false, // SiteOrigin affiliate ID.
'copy-content' => !isset( $display_settings['copy-content'] ) ? true : $display_settings['copy-content'], // Should we copy across content?
'animations' => !isset( $display_settings['animations'] ) ? true : $display_settings['animations'], // Do we need animations?
'inline-css' => !isset( $display_settings['inline-css'] ) ? true : $display_settings['inline-css'], // How to display CSS?
) );
// Filter these settings
$settings = apply_filters('siteorigin_panels_settings', $settings);
if( empty( $settings['post-types'] ) ) $settings['post-types'] = array();
if( !empty( $key ) ) return isset( $settings[$key] ) ? $settings[$key] : null;
return $settings;
}
/**
* Modify the front page template
*
* @param $template
* @return string
*/
function siteorigin_panels_lite_filter_home_template($template){
// The user has already selected their own page as the home template
if ( get_option( 'show_on_front' ) !== 'posts' ) return $template;
if ( defined( 'PANELS_LITE_NO_DEFAULT_HOME' ) ) return $template;
// Do we even support the home template
if ( !get_theme_mod('siteorigin_panels_home_page_enabled', siteorigin_panels_lite_setting('home-page-default') ) ) return $template;
if ( !siteorigin_panels_lite_setting('home-page-default') || !siteorigin_panels_lite_setting('home-demo-template') ) return $template;
return locate_template( array(
siteorigin_panels_lite_setting( 'home-demo-template' ),
$template
) );
}
add_filter('home_template', 'siteorigin_panels_lite_filter_home_template');
/**
* @return mixed|void Are we currently viewing the home page
*/
function siteorigin_panels_lite_is_home(){
$home = ( is_home() && is_front_page() && get_theme_mod('siteorigin_panels_home_page_enabled', siteorigin_panels_lite_setting('home-page-default') ) && !is_page() && siteorigin_panels_lite_setting( 'home-page-default' ) );
return apply_filters('siteorigin_panels_is_home', $home);
}
/**
* Enqueue the required styles
*/
function siteorigin_panels_lite_enqueue_styles(){
if( siteorigin_panels_lite_is_home() ){
wp_enqueue_style( 'siteorigin-panels-lite-front', get_template_directory_uri() . '/inc/panels-lite/css/front.css', array(), SITEORIGIN_PANELS_LITE_VERSION );
// Render this here so we can enqueue all the scripts we need early.
global $siteorigin_panels_cache;
if( empty($siteorigin_panels_cache[ get_the_ID() ] ) ) {
$siteorigin_panels_cache[ 'home' ] = siteorigin_panels_lite_home_render( );
}
}
}
add_action('wp_enqueue_scripts', 'siteorigin_panels_lite_enqueue_styles');
/**
* Set the home body class when we're displaying a panels page.
*
* @param $classes
* @return array
*/
function siteorigin_panels_lite_body_class($classes){
if( siteorigin_panels_lite_is_home() ) {
$classes[] = 'siteorigin-panels';
$classes[] = 'siteorigin-panels-home';
$classes[] = 'siteorigin-panels-lite-home';
}
return $classes;
}
add_filter('body_class', 'siteorigin_panels_lite_body_class');
/**
* Render the widget.
*
* @param string $widget The widget class name.
* @param array $instance The widget instance
* @param $grid
* @param $cell
* @param $panel
* @param $is_first
* @param $is_last
*/
function siteorigin_panels_lite_the_widget( $widget, $instance, $grid, $cell, $panel, $is_first, $is_last ) {
global $wp_widget_factory;
// Load the widget from the widget factory and give themes and plugins a chance to provide their own
$the_widget = !empty($wp_widget_factory->widgets[$widget]) ? $wp_widget_factory->widgets[$widget] : false;
$the_widget = apply_filters( 'siteorigin_panels_widget_object', $the_widget, $widget, $instance );
if( empty($post_id) ) $post_id = get_the_ID();
$classes = apply_filters( 'siteorigin_panels_widget_classes', array( 'panel', 'widget' ), $widget, $instance);
if ( !empty( $the_widget ) && !empty( $the_widget->id_base ) ) $classes[] = 'widget_' . $the_widget->id_base;
if ( $is_first ) $classes[] = 'panel-first-child';
if ( $is_last ) $classes[] = 'panel-last-child';
$id = 'panel-' . $post_id . '-' . $grid . '-' . $cell . '-' . $panel;
// Filter and sanitize the classes
$classes = apply_filters('siteorigin_panels_widget_classes', $classes, $widget, $instance);
$classes = array_map('sanitize_html_class', $classes);
$args = array(
'before_widget' => '<div class="' . esc_attr( implode( ' ', $classes ) ) . '" id="' . $id . '">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
'widget_id' => 'widget-' . $grid . '-' . $cell . '-' . $panel
);
// If there is a style wrapper, add it.
if( !empty($style_wrapper) ) {
$args['before_widget'] = $args['before_widget'] . $style_wrapper;
$args['after_widget'] = '</div>' . $args['after_widget'];
}
$widget_code = '';
if ( !empty($the_widget) && is_a($the_widget, 'WP_Widget') ) {
ob_start();
$the_widget->widget($args , $instance );
$widget_code = ob_get_clean();
}
else {
// This gives themes a chance to display some sort of placeholder for missing widgets
$widget_code = apply_filters('siteorigin_panels_missing_widget', $args['before_widget'] . $args['after_widget'], $widget, $args , $instance);
}
// This is a special filter to create demo content
echo apply_filters('siteorigin_panels_lite_widget', $widget_code, $widget, $args , $instance);
}
/**
* Echo the CSS for the current panel
*
* @param array $panels_data
*/
function siteorigin_panels_lite_generate_css($post_id, $panels_data) {
// Exit if we don't have panels data
if ( empty( $panels_data ) || empty( $panels_data['grids'] ) ) return;
// Get some of the default settings
$settings = siteorigin_panels_lite_setting();
$panels_mobile_width = $settings['mobile-width'];
$panels_margin_bottom = $settings['margin-bottom'];
$css = new SiteOrigin_Panels_Lite_Css_Builder();
$ci = 0;
foreach ( $panels_data['grids'] as $gi => $grid ) {
$cell_count = intval( $grid['cells'] );
// Add the cell sizing
for ( $i = 0; $i < $cell_count; $i++ ) {
$cell = $panels_data['grid_cells'][$ci++];
if ( $cell_count > 1 ) {
$width = round( $cell['weight'] * 100, 3 ) . '%';
$width = apply_filters('siteorigin_panels_css_cell_width', $width, $grid, $gi, $cell, $ci - 1, $panels_data, $post_id);
// Add the width and ensure we have correct formatting for CSS.
$css->add_cell_css($post_id, $gi, $i, '', array(
'width' => str_replace(',', '.', $width)
));
}
}
// Add the bottom margin to any grids that aren't the last
if($gi != count($panels_data['grids'])-1){
// Filter the bottom margin for this row with the arguments
$css->add_row_css($post_id, $gi, '', array(
'margin-bottom' => apply_filters('siteorigin_panels_css_row_margin_bottom', $panels_margin_bottom.'px', $grid, $gi, $panels_data, $post_id)
));
}
if ( $cell_count > 1 ) {
$css->add_cell_css($post_id, $gi, false, '', array(
// Float right for RTL
'float' => !is_rtl() ? 'left' : 'right'
));
}
if ( $settings['responsive'] ) {
// Mobile Responsive
$css->add_cell_css($post_id, $gi, false, '', array(
'float' => 'none',
'width' => 'auto'
), $panels_mobile_width);
for ( $i = 0; $i < $cell_count; $i++ ) {
if ( $i != $cell_count - 1 ) {
$css->add_cell_css($post_id, $gi, $i, '', array(
'margin-bottom' => $panels_margin_bottom . 'px',
), $panels_mobile_width);
}
}
}
}
if( $settings['responsive'] ) {
// Add CSS to prevent overflow on mobile resolution.
$css->add_row_css($post_id, false, '', array(
'margin-left' => 0,
'margin-right' => 0,
), $panels_mobile_width);
$css->add_cell_css($post_id, false, false, '', array(
'padding' => 0,
), $panels_mobile_width);
}
// Add the bottom margins
$css->add_cell_css($post_id, false, false, '.panel', array(
'margin-bottom' => $panels_margin_bottom.'px'
));
$css->add_cell_css($post_id, false, false, '.panel:last-child', array(
'margin-bottom' => 0
));
// Let other plugins customize various aspects of the rows (grids)
foreach ( $panels_data['grids'] as $gi => $grid ) {
// Rows with only one cell don't need gutters
if($grid['cells'] <= 1) continue;
// Let other themes and plugins change the gutter.
$gutter = apply_filters('siteorigin_panels_css_row_gutter', $settings['margin-sides'].'px', $grid, $gi, $panels_data);
if( !empty($gutter) ) {
// We actually need to find half the gutter.
preg_match('/([0-9\.,]+)(.*)/', $gutter, $match);
if( !empty( $match[1] ) ) {
$margin_half = (floatval($match[1])/2) . $match[2];
$css->add_row_css($post_id, $gi, '', array(
'margin-left' => '-' . $margin_half,
'margin-right' => '-' . $margin_half,
) );
$css->add_cell_css($post_id, $gi, false, '', array(
'padding-left' => $margin_half,
'padding-right' => $margin_half,
) );
}
}
}
// Let other plugins and components filter the CSS object.
$css = apply_filters( 'siteorigin_panels_css_object', $css, $panels_data, $post_id, array() );
return $css->get_css();
}
/**
*
*/
function siteorigin_panels_lite_css(){
if( !siteorigin_panels_lite_is_home() ) return;
$layouts = apply_filters( 'siteorigin_panels_prebuilt_layouts', array() );
if(empty($layouts[ siteorigin_panels_lite_setting('home-page-default') ])) return;
$panels_data = $layouts[siteorigin_panels_lite_setting('home-page-default')];
$panels_data = apply_filters( 'siteorigin_panels_data', $panels_data, 'home' );
?><style type="text/css"><?php echo siteorigin_panels_lite_generate_css('home', $panels_data) ?></style><?php
}
add_action( 'wp_head', 'siteorigin_panels_lite_css', 15 );
/**
* @param string $post_id
*
* @return mixed|void
*/
function siteorigin_panels_lite_home_render( $post_id = 'home' ){
if( empty($post_id) ) $post_id = get_the_ID();
global $siteorigin_panels_current_post;
$old_current_post = $siteorigin_panels_current_post;
$siteorigin_panels_current_post = $post_id;
// Try get the cached panel from in memory cache.
global $siteorigin_panels_cache;
if(!empty($siteorigin_panels_cache) && !empty($siteorigin_panels_cache[$post_id]))
return $siteorigin_panels_cache[$post_id];
// Load the default layout
$layouts = apply_filters('siteorigin_panels_prebuilt_layouts', array());
$prebuilt_id = siteorigin_panels_lite_setting('home-page-default') ? siteorigin_panels_lite_setting('home-page-default') : 'home';
$panels_data = !empty($layouts[$prebuilt_id]) ? $layouts[$prebuilt_id] : current($layouts);
$panels_data = apply_filters( 'siteorigin_panels_data', $panels_data, $post_id );
if( empty( $panels_data ) || empty( $panels_data['grids'] ) ) return '';
// Create the skeleton of the grids
$grids = array();
if( !empty( $panels_data['grids'] ) && !empty( $panels_data['grids'] ) ) {
foreach ( $panels_data['grids'] as $gi => $grid ) {
$gi = intval( $gi );
$grids[$gi] = array();
for ( $i = 0; $i < $grid['cells']; $i++ ) {
$grids[$gi][$i] = array();
}
}
}
// We need this to migrate from the old $panels_data that put widget meta into the "info" key instead of "panels_info"
if( !empty( $panels_data['widgets'] ) && is_array($panels_data['widgets']) ) {
foreach ( $panels_data['widgets'] as $i => $widget ) {
if( empty( $panels_data['widgets'][$i]['panels_info'] ) ) {
$panels_data['widgets'][$i]['panels_info'] = $panels_data['widgets'][$i]['info'];
unset($panels_data['widgets'][$i]['info']);
}
}
}
if( !empty( $panels_data['widgets'] ) && is_array($panels_data['widgets']) ){
foreach ( $panels_data['widgets'] as $widget ) {
// Put the widgets in the grids
$grids[ intval( $widget['panels_info']['grid']) ][ intval( $widget['panels_info']['cell'] ) ][] = $widget;
}
}
ob_start();
// Add the panel layout wrapper
echo '<div id="pl-' . $post_id . '">';
global $siteorigin_panels_inline_css;
if( empty($siteorigin_panels_inline_css) ) $siteorigin_panels_inline_css = '';
echo apply_filters( 'siteorigin_panels_before_content', '', $panels_data, $post_id );
foreach ( $grids as $gi => $cells ) {
$grid_classes = apply_filters( 'siteorigin_panels_row_classes', array('panel-grid'), $panels_data['grids'][$gi] );
$grid_attributes = apply_filters( 'siteorigin_panels_row_attributes', array(
'class' => implode( ' ', $grid_classes ),
'id' => 'pg-' . $post_id . '-' . $gi
), $panels_data['grids'][$gi] );
// This allows other themes and plugins to add html before the row
echo apply_filters( 'siteorigin_panels_before_row', '', $panels_data['grids'][$gi], $grid_attributes );
echo '<div ';
foreach ( $grid_attributes as $name => $value ) {
echo $name.'="'.esc_attr($value).'" ';
}
echo '>';
$style_attributes = array();
if( !empty( $panels_data['grids'][$gi]['style']['class'] ) ) {
$style_attributes['class'] = array('panel-row-style-'.$panels_data['grids'][$gi]['style']['class']);
}
// Themes can add their own attributes to the style wrapper
$row_style_wrapper = siteorigin_panels_lite_start_style_wrapper( 'row', $style_attributes, !empty($panels_data['grids'][$gi]['style']) ? $panels_data['grids'][$gi]['style'] : array() );
if( !empty($row_style_wrapper) ) echo $row_style_wrapper;
foreach ( $cells as $ci => $widgets ) {
// Themes can add their own styles to cells
$cell_classes = apply_filters( 'siteorigin_panels_row_cell_classes', array('panel-grid-cell'), $panels_data );
$cell_attributes = apply_filters( 'siteorigin_panels_row_cell_attributes', array(
'class' => implode( ' ', $cell_classes ),
'id' => 'pgc-' . $post_id . '-' . $gi . '-' . $ci
), $panels_data );
echo '<div ';
foreach ( $cell_attributes as $name => $value ) {
echo $name.'="'.esc_attr($value).'" ';
}
echo '>';
$cell_style_wrapper = siteorigin_panels_lite_start_style_wrapper( 'cell', array(), !empty($panels_data['grids'][$gi]['style']) ? $panels_data['grids'][$gi]['style'] : array() );
if( !empty($cell_style_wrapper) ) echo $cell_style_wrapper;
foreach ( $widgets as $pi => $widget_info ) {
$instance = $widget_info;
unset( $instance['panels_info'] );
// TODO this wrapper should go in the before/after widget arguments
$widget_style_wrapper = siteorigin_panels_lite_start_style_wrapper( 'widget', array(), !empty( $widget_info['panels_info']['style'] ) ? $widget_info['panels_info']['style'] : array() );
siteorigin_panels_lite_the_widget( $widget_info['panels_info']['class'], $instance, $gi, $ci, $pi, $pi == 0, $pi == count( $widgets ) - 1, $post_id, $widget_style_wrapper );
}
if ( empty( $widgets ) ) echo ' ';
if( !empty($cell_style_wrapper) ) echo '</div>';
echo '</div>';
}
echo '</div>';
// Close the
if( !empty($row_style_wrapper) ) echo '</div>';
// This allows other themes and plugins to add html after the row
echo apply_filters( 'siteorigin_panels_after_row', '', $panels_data['grids'][$gi], $grid_attributes );
}
echo apply_filters( 'siteorigin_panels_after_content', '', $panels_data, $post_id );
echo '</div>';
$html = ob_get_clean();
// Reset the current post
$siteorigin_panels_current_post = $old_current_post;
return apply_filters( 'siteorigin_panels_render', $html, $post_id, !empty($post) ? $post : null );
}
/**
* Echo the style wrapper and return if there was a wrapper
*
* @param $name
* @param $style_attributes
* @param array $style_args
*
* @return bool Is there a style wrapper
*/
function siteorigin_panels_lite_start_style_wrapper($name, $style_attributes, $style_args = array()){
$style_wrapper = '';
if( empty($style_attributes['class']) ) $style_attributes['class'] = array();
if( empty($style_attributes['style']) ) $style_attributes['style'] = '';
$style_attributes = apply_filters('siteorigin_panels_' . $name . '_style_attributes', $style_attributes, $style_args );
if( empty($style_attributes['class']) ) unset($style_attributes['class']);
if( empty($style_attributes['style']) ) unset($style_attributes['style']);
if( !empty($style_attributes) ) {
if(empty($style_attributes['class'])) $style_attributes['class'] = array();
$style_attributes['class'][] = 'panel-' . $name . '-style';
$style_attributes['class'] = array_unique( $style_attributes['class'] );
// Filter and sanitize the classes
$style_attributes['class'] = apply_filters('siteorigin_panels_' . $name . '_style_classes', $style_attributes['class'], $style_attributes, $style_args);
$style_attributes['class'] = array_map('sanitize_html_class', $style_attributes['class']);
$style_wrapper = '<div ';
foreach ( $style_attributes as $name => $value ) {
if( is_array($value) ) {
$style_wrapper .= $name.'="'.esc_attr( implode( " ", array_unique( $value ) ) ).'" ';
}
else {
$style_wrapper .= $name.'="'.esc_attr($value).'" ';
}
}
$style_wrapper .= '>';
return $style_wrapper;
}
return $style_wrapper;
}