Skip to content

Commit

Permalink
Merge branch 'release/2.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Misplon committed May 3, 2021
2 parents cbb2f27 + 789a390 commit d45adf6
Show file tree
Hide file tree
Showing 48 changed files with 1,566 additions and 347 deletions.
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+12 −12 package-lock.json
2 changes: 0 additions & 2 deletions build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ module.exports = {
'widgets/**/styles/*.less', // All the widgets' runtime .less files
'!widgets/**/styles/*.css', // Don't copy any .css files compiled from runtime .less files
'!{node_modules,node_modules/**}', // Ignore node_modules/ and contents
'!{tests,tests/**}', // Ignore tests/ and contents
'!{tmp,tmp/**}', // Ignore dist/ and contents
'!phpunit.xml', // Not the unit tests configuration file.
'!siteorigin-panels.php', // Not the base plugin file. It is copied by the 'version' task.
'!package.json', // Ignore the package.json file..
'!readme.txt', // Not the readme.txt file. It is copied by the 'version' task.
Expand Down
98 changes: 98 additions & 0 deletions compat/acf-widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
class SiteOrigin_Panels_Compat_ACF_Widgets {
public function __construct() {
add_action( 'admin_print_scripts-post-new.php', array( $this, 'enqueue_assets' ), 100 );
add_action( 'admin_print_scripts-post.php', array( $this, 'enqueue_assets' ), 100 );

// Widget Form Rendering.
add_action( 'siteorigin_panels_before_widget_form', array( $this, 'store_acf_widget_fields_instance' ), 10, 3 );
add_filter( 'acf/pre_load_value', array( $this, 'load_panels_widget_field_data' ), 10, 3 );

// Widget Saving inside of Page Builder.
add_filter( 'widget_update_callback', array( $this, 'acf_override_instance' ), 10, 4 );
}

public static function single() {
static $single;

return empty( $single ) ? $single = new self() : $single;
}

public function enqueue_assets() {
if ( SiteOrigin_Panels_Admin::is_admin() ) {
wp_enqueue_script(
'so-panels-acf-widgets-compat',
siteorigin_panels_url( 'compat/js/acf-widgets' . SITEORIGIN_PANELS_JS_SUFFIX . '.js' ),
array(
'jquery',
'so-panels-admin',
),
SITEORIGIN_PANELS_VERSION,
true
);
}
}

/**
* Extracts the widgets ACF fields, and ACF stores them and the instance.
*
* @param $the_widget The WP Widget Object.
* @param $instance The Panels widget instance.
*/
public function store_acf_widget_fields_instance( $the_widget, $instance ) {
$field_groups = acf_get_field_groups( array(
'widget' => $the_widget->id_base,
) );

if ( ! empty( $field_groups ) ) {
// Get all fields, and merge them into a single array.
foreach( $field_groups as $field_group ) {
$fields[] = acf_get_fields( $field_group );
}
$fields = call_user_func_array('array_merge', $fields );

acf_register_store( 'so_fields', $fields );
acf_register_store( 'so_widget_instance', $instance['acf'] );
}
}

/**
* Sets the ACF Widget Field values based on instance data.
*
* @param $value
* @param $post_id
* @param $widget_field The ACF object for the field being processed.
*
* @return string if set, the user defined field value.
*/
public function load_panels_widget_field_data( $value, $post_id, $widget_field ) {
$fields = acf_get_store( 'so_fields' );
$instance = acf_get_store( 'so_widget_instance' );

if ( ! empty( $fields ) ) {
foreach ( $fields->data as $field ) {
if ( $field['key'] == $widget_field['key'] && ! empty( $instance->data[ $field['key'] ] ) ) {
return $instance->data[ $field['key'] ];
}
}
}
}

/**
* Restores initial ACF form data to prevent saving issue in non SOWB widgets.
*
* @param $instance The updated widget settings.
* @param $new_instance An array of new settings.
* @param $old_instance An array of old settings.
* @param $this The current widget instance.
*
*/
public function acf_override_instance( $instance, $widget, $old_widget, $the_widget ) {
// Ensure widget update is from Page Builder and there's ACF data present.
if ( ! empty( $widget['panels_info'] ) && ! empty( $instance['acf'] ) ) {
$instance['acf'] = $widget['acf'];
}

return $instance;
}
}
7 changes: 7 additions & 0 deletions compat/js/acf-widgets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
( function( $ ) {
$( document ).on( 'open_dialog', function( e, view ) {
setTimeout( function() {
acf.doAction( 'append', $( '.so-content' ) );
}, 1250 )
} );
} )( jQuery );
20 changes: 17 additions & 3 deletions compat/js/siteorigin-panels-layout-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ function (_wp$element$Component) {
};

if (this.state.editing) {
return React.createElement(wp.element.Fragment, null, React.createElement(wp.blockEditor.BlockControls, null, React.createElement(wp.components.Toolbar, {
return React.createElement(wp.element.Fragment, null, panelsData ? React.createElement(wp.blockEditor.BlockControls, null, React.createElement(wp.components.Toolbar, {
label: wp.i18n.__('Page Builder Mode.', 'siteorigin-panels')
}, React.createElement(wp.components.ToolbarButton, {
icon: "visibility",
className: "components-icon-button components-toolbar__control",
label: wp.i18n.__('Preview layout.', 'siteorigin-panels'),
onClick: switchToPreview
}))), React.createElement("div", {
}))) : null, React.createElement("div", {
key: "layout-block",
className: "siteorigin-panels-layout-block-container",
ref: this.panelsContainer
Expand Down Expand Up @@ -332,6 +332,11 @@ wp.blocks.registerBlockType('siteorigin-panels/layout-block', {
setAttributes(panelsAttributes);
wp.data.dispatch('core/editor').unlockPostSaving();
});
} else {
setAttributes({
panelsData: null,
contentPreview: null
});
}
};

Expand Down Expand Up @@ -363,7 +368,16 @@ wp.blocks.registerBlockType('siteorigin-panels/layout-block', {
var editorDispatch = wp.data.dispatch('core/editor');
var editorSelect = wp.data.select('core/editor');
var tmpl = jQuery('#siteorigin-panels-add-layout-block-button').html();
var $addButton = jQuery(tmpl).insertAfter('.editor-writing-flow > div:first, .block-editor-writing-flow > div:not([tabindex])');

if (jQuery('.block-editor-writing-flow > .block-editor-block-list__layout').length) {
// > WP 5.7
var buttonSelector = '.block-editor-writing-flow > .block-editor-block-list__layout';
} else {
// < WP 5.7
var buttonSelector = '.editor-writing-flow > div:first, .block-editor-writing-flow > div:not([tabindex])';
}

var $addButton = jQuery(tmpl).appendTo(buttonSelector);
$addButton.on('click', function () {
var layoutBlock = wp.blocks.createBlock('siteorigin-panels/layout-block', {});
var isEmpty = editorSelect.isEditedPostEmpty();
Expand Down
38 changes: 27 additions & 11 deletions compat/js/siteorigin-panels-layout-block.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,20 @@ class SiteOriginPanelsLayoutBlock extends wp.element.Component {
if ( this.state.editing ) {
return (
<wp.element.Fragment>
<wp.blockEditor.BlockControls>
<wp.components.Toolbar label={ wp.i18n.__( 'Page Builder Mode.', 'siteorigin-panels' ) }>
<wp.components.ToolbarButton
icon="visibility"
className="components-icon-button components-toolbar__control"
label={ wp.i18n.__( 'Preview layout.', 'siteorigin-panels' ) }
onClick={ switchToPreview }
/>
</wp.components.Toolbar>
</wp.blockEditor.BlockControls>
{ panelsData ? (
<wp.blockEditor.BlockControls>
<wp.components.Toolbar label={ wp.i18n.__( 'Page Builder Mode.', 'siteorigin-panels' ) }>
<wp.components.ToolbarButton
icon="visibility"
className="components-icon-button components-toolbar__control"
label={ wp.i18n.__( 'Preview layout.', 'siteorigin-panels' ) }
onClick={ switchToPreview }
/>
</wp.components.Toolbar>
</wp.blockEditor.BlockControls>
) : (
null
) }
<div
key="layout-block"
className="siteorigin-panels-layout-block-container"
Expand Down Expand Up @@ -275,6 +279,11 @@ wp.blocks.registerBlockType( 'siteorigin-panels/layout-block', {
wp.data.dispatch( 'core/editor' ).unlockPostSaving();
}
);
} else {
setAttributes( {
panelsData: null,
contentPreview: null,
} );
}
};

Expand Down Expand Up @@ -310,7 +319,14 @@ wp.blocks.registerBlockType( 'siteorigin-panels/layout-block', {
const editorDispatch = wp.data.dispatch( 'core/editor' );
const editorSelect = wp.data.select( 'core/editor' );
var tmpl = jQuery( '#siteorigin-panels-add-layout-block-button' ).html();
var $addButton = jQuery(tmpl).insertAfter( '.editor-writing-flow > div:first, .block-editor-writing-flow > div:not([tabindex])' );
if ( jQuery( '.block-editor-writing-flow > .block-editor-block-list__layout' ).length ) {
// > WP 5.7
var buttonSelector = '.block-editor-writing-flow > .block-editor-block-list__layout';
} else {
// < WP 5.7
var buttonSelector = '.editor-writing-flow > div:first, .block-editor-writing-flow > div:not([tabindex])';
}
var $addButton = jQuery( tmpl ).appendTo( buttonSelector );
$addButton.on( 'click', () => {
var layoutBlock = wp.blocks.createBlock( 'siteorigin-panels/layout-block', {} );
const isEmpty = editorSelect.isEditedPostEmpty();
Expand Down
63 changes: 63 additions & 0 deletions compat/lazy-load-backgrounds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Apply background and Lazy Load attributes/classes to rows, cells and widgets.
*
* @param $attributes
* @param $style
*
* @return array $attributes
*/

function siteorigin_apply_lazy_load_attributes( $attributes, $style ) {
if (
! empty( $style['background_display'] ) &&
! empty( $style['background_image_attachment'] ) &&
$style['background_display'] != 'parallax' &&
$style['background_display'] != 'parallax-original'
) {
$url = SiteOrigin_Panels_Styles::get_attachment_image_src( $style['background_image_attachment'], 'full' );

if ( ! empty( $url ) ) {
$attributes['class'][] = 'lazy';
$attributes['data-bg'] = $url[0];

// WP Rocket uses a different lazy load class.
if ( defined( 'ROCKET_LL_VERSION' ) ) {
$attributes['class'][] = 'rocket-lazyload';
}

// Other lazy loads can sometimes use an inline background image.
if ( apply_filters( 'siteorigin_lazy_load_inline_background', false ) ) {
$attributes['style'] = 'background-image: url(' . $url[0] . ')';
}
}
}

return $attributes;
}
add_filter( 'siteorigin_panels_row_style_attributes', 'siteorigin_apply_lazy_load_attributes', 10, 2 );
add_filter( 'siteorigin_panels_cell_style_attributes', 'siteorigin_apply_lazy_load_attributes', 10, 2 );
add_filter( 'siteorigin_panels_widget_style_attributes', 'siteorigin_apply_lazy_load_attributes', 10, 2 );

/**
* Prevent background image from being added using CSS.
*
* @param $css
* @param $style
*
* @return mixed
*/
function siteorigin_prevent_background_css( $css, $style ) {
if (
! empty( $css['background-image'] ) &&
$style['background_display'] != 'parallax' &&
$style['background_display'] != 'parallax-original'
) {
unset( $css['background-image'] );
}

return $css;
}
add_filter( 'siteorigin_panels_row_style_css', 'siteorigin_prevent_background_css', 10, 2 );
add_filter( 'siteorigin_panels_cell_style_css', 'siteorigin_prevent_background_css', 10, 2 );
add_filter( 'siteorigin_panels_widget_style_css', 'siteorigin_prevent_background_css', 10, 2 );
Loading

0 comments on commit d45adf6

Please sign in to comment.