Skip to content

Commit

Permalink
Merge branch 'release/2.21.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Misplon committed Apr 22, 2023
2 parents f554a04 + dbd6b94 commit 79da3bb
Show file tree
Hide file tree
Showing 61 changed files with 2,546 additions and 2,306 deletions.
9 changes: 3 additions & 6 deletions compat/acf-widgets.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

class SiteOrigin_Panels_Compat_ACF_Widgets {
public function __construct() {
add_action( 'admin_print_scripts-post-new.php', array( $this, 'enqueue_assets' ), 100 );
Expand All @@ -14,7 +15,7 @@ public function __construct() {

public static function single() {
static $single;

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

Expand Down Expand Up @@ -47,7 +48,7 @@ public function store_acf_widget_fields_instance( $the_widget, $instance ) {

if ( ! empty( $field_groups ) ) {
// Get all fields, and merge them into a single array.
foreach( $field_groups as $field_group ) {
foreach ( $field_groups as $field_group ) {
$fields[] = acf_get_fields( $field_group );
}
$fields = call_user_func_array( 'array_merge', $fields );
Expand All @@ -61,8 +62,6 @@ public function store_acf_widget_fields_instance( $the_widget, $instance ) {
/**
* 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.
Expand Down Expand Up @@ -91,7 +90,6 @@ public function load_panels_widget_field_data( $value, $post_id, $widget_field )
* Generates and filters out invalid fields and indexes from the ACF Widget fields array.
*
* @param $fields A possible array containing fields, or a string containing a field value.
*
*/
private function generate_fields_array( $fields ) {
if ( is_array( $fields ) ) {
Expand All @@ -118,7 +116,6 @@ private function generate_fields_array( $fields ) {
* @param $new_instance An array of new settings.
* @param $old_instance An array of old settings.
* @param $the_widget 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.
Expand Down
4 changes: 0 additions & 4 deletions compat/gravity-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
/**
* Override Gravity Forms "Disable Print Scripts" setting to prevent missing jQuery error.
*
* @param $instance
* @param $the_widget
* @param $widget_class
*
* @return $instance
*/
function siteorigin_gravity_forms_override_disable_print_scripts( $instance, $the_widget, $widget_class ) {
Expand Down
8 changes: 3 additions & 5 deletions compat/jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* Prevent Photon from filtering srcset.
* This is done using a method to prevent conflicting with other usage of this filter.
*
* @param $valid
* @param $url
* @param $parsed_url
*
* @return false
*/
function siteorigin_panels_photon_exclude_parallax_srcset( $valid, $url, $parsed_url ) {
Expand All @@ -26,17 +22,19 @@ function siteorigin_panels_photon_exclude_parallax( $skip, $src, $tag ) {
if ( ! is_array( $tag ) && strpos( $tag, 'data-siteorigin-parallax' ) !== false ) {
$skip = true;
}

return $skip;
}

/**
* When a post is copied using Jetpack, copy Page Builder data.
*
* @param WP_Post $source_post Post object that was copied.
* @param WP_Post $source_post Post object that was copied.
* @param int $target_post_id Target post ID.
*/
function siteorigin_panels_jetpack_copy_post( $source_post, $target_post_id ) {
$panels_data = get_post_meta( $source_post, 'panels_data', true );

if ( ! empty( $panels_data ) ) {
add_post_meta( $target_post_id, 'panels_data', $panels_data );
}
Expand Down
29 changes: 16 additions & 13 deletions compat/layout-block.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

class SiteOrigin_Panels_Compat_Layout_Block {

const BLOCK_NAME = 'siteorigin-panels/layout-block';

/**
* Get the singleton instance
*
* @return SiteOrigin_Panels_Compat_Layout_Block
*/
public static function single() {
static $single;

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

public function __construct() {
add_action( 'init', array( $this, 'register_layout_block' ) );
// This action is slightly later than `enqueue_block_editor_assets`,
Expand All @@ -24,18 +23,19 @@ public function __construct() {
// We need to override the container when using the Block Editor to allow for resizing.
add_filter( 'siteorigin_panels_full_width_container', array( $this, 'override_container' ) );
}

public function register_layout_block() {
register_block_type( self::BLOCK_NAME, array(
'render_callback' => array( $this, 'render_layout_block' ),
) );
}

public function enqueue_layout_block_editor_assets() {
if ( SiteOrigin_Panels_Admin::is_block_editor() || is_customize_preview() ) {
$panels_admin = SiteOrigin_Panels_Admin::single();
$panels_admin->enqueue_admin_scripts();
$panels_admin->enqueue_admin_styles();

if ( ! is_customize_preview() ) {
$panels_admin->js_templates();
}
Expand Down Expand Up @@ -77,22 +77,22 @@ public function enqueue_layout_block_editor_assets() {
}
SiteOrigin_Panels_Styles::register_scripts();
wp_enqueue_script( 'siteorigin-panels-front-styles' );

// Enqueue front end scripts for our widgets bundle.
if ( class_exists( 'SiteOrigin_Widgets_Bundle' ) ) {
$sowb = SiteOrigin_Widgets_Bundle::single();
$sowb->register_general_scripts();

if ( method_exists( $sowb, 'enqueue_registered_widgets_scripts' ) ) {
$sowb->enqueue_registered_widgets_scripts( true, false );
}
}
}
}

public function render_layout_block( $attributes ) {

if ( empty( $attributes['panelsData'] ) ) {
return '<div>'.
return '<div>' .
__( "You need to add a widget, row, or prebuilt layout before you'll see anything here. :)", 'siteorigin-panels' ) .
'</div>';
}
Expand All @@ -101,27 +101,30 @@ public function render_layout_block( $attributes ) {
$builder_id = isset( $attributes['builder_id'] ) ? $attributes['builder_id'] : uniqid( 'gb' . get_the_ID() . '-' );

// Support for custom CSS classes
$add_custom_class_name = function( $class_names ) use ($attributes) {
$add_custom_class_name = function ( $class_names ) use ( $attributes ) {
if ( ! empty( $attributes['className'] ) ) {
$class_names[] = $attributes['className'];
}

return $class_names;
};
add_filter( 'siteorigin_panels_layout_classes', $add_custom_class_name );
$rendered_layout = SiteOrigin_Panels::renderer()->render( $builder_id, true, $panels_data );
remove_filter( 'siteorigin_panels_layout_classes', $add_custom_class_name );

return $rendered_layout;
}

private function sanitize_panels_data( $panels_data ) {
// We force calling widgets' update functions here, but a better solution is to ensure these are called when
// the block is saved, but there is currently no simple method to do so.
$panels_data['widgets'] = SiteOrigin_Panels_Admin::single()->process_raw_widgets( $panels_data['widgets'], false, true );
$panels_data = SiteOrigin_Panels_Styles_Admin::single()->sanitize_all( $panels_data );

return $panels_data;
}

function override_container( $container ) {
public function override_container( $container ) {
return SiteOrigin_Panels_Admin::is_block_editor() ? '.editor-styles-wrapper' : $container;
}
}
7 changes: 0 additions & 7 deletions compat/lazy-load-backgrounds.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
/**
* 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'] ) &&
Expand Down Expand Up @@ -42,9 +38,6 @@ function siteorigin_apply_lazy_load_attributes( $attributes, $style ) {
/**
* Prevent background image from being added using CSS.
*
* @param $css
* @param $style
*
* @return mixed
*/
function siteorigin_prevent_background_css( $css, $style ) {
Expand Down
2 changes: 1 addition & 1 deletion compat/polylang.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* When Polylang duplicates a post, copy over panels_data if it exists.
*
*/
function siteorigin_polylang_include_panels_data( $keys, $sync ) {
if ( ! $sync ) {
$keys[] = 'panels_data';
}

return $keys;
}
add_filter( 'pll_copy_post_metas', 'siteorigin_polylang_include_panels_data', 10, 2 );
12 changes: 12 additions & 0 deletions compat/rank-math.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
function siteorigin_rank_math_sitemap( $content, $post_id ) {
$panels_data = get_post_meta( $post_id, 'panels_data', true );
if ( ! empty( $panels_data ) ) {
$GLOBALS[ 'SITEORIGIN_PANELS_PREVIEW_RENDER' ] = true;
$content = SiteOrigin_Panels::renderer()->render( (int) $post_id, false, $panels_data );
unset( $GLOBALS[ 'SITEORIGIN_PANELS_PREVIEW_RENDER' ] );
}

return $content;
}
add_filter( 'rank_math/sitemap/content_before_parse_html_images', 'siteorigin_rank_math_sitemap', 10, 2 );
37 changes: 16 additions & 21 deletions compat/widget-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,36 @@
/**
* Filter panels_data so it's compatible with Widget Options plugin.
*
* @param $panels_data
*
* @return mixed
*/
function siteorigin_panels_widget_options_compat_panels_data( $panels_data ) {
if( !empty($panels_data['widgets']) && is_array($panels_data['widgets']) ) {
foreach( $panels_data['widgets'] as & $widget ) {
if( !empty($widget['extended_widget_opts']) ) {
$widget['extended_widget_opts'] = siteorigin_panels_widget_options_compat_filter($widget['extended_widget_opts']);
if ( ! empty( $panels_data['widgets'] ) && is_array( $panels_data['widgets'] ) ) {
foreach ( $panels_data['widgets'] as & $widget ) {
if ( ! empty( $widget['extended_widget_opts'] ) ) {
$widget['extended_widget_opts'] = siteorigin_panels_widget_options_compat_filter( $widget['extended_widget_opts'] );
}
}
}

return $panels_data;
}
add_filter('siteorigin_panels_data', 'siteorigin_panels_widget_options_compat_panels_data');
add_filter( 'siteorigin_panels_data', 'siteorigin_panels_widget_options_compat_panels_data' );

/**
* Filter that removes any empty strings so they pass an !isset test.
*
* @param $value
* Filter that removes any empty strings so they pass an ! isset() test.
*
* @return array
*/
function siteorigin_panels_widget_options_compat_filter($value){
if( is_array($value) ) {
foreach($value as $k => & $v) {
if(is_array($v)) {
$v = siteorigin_panels_widget_options_compat_filter($v);
}
else if( is_string($v) && empty($v) ) {
unset($value[$k]);
function siteorigin_panels_widget_options_compat_filter( $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $k => & $v ) {
if ( is_array( $v ) ) {
$v = siteorigin_panels_widget_options_compat_filter( $v );
} elseif ( is_string( $v ) && empty( $v ) ) {
unset( $value[$k] );
}
}
}

return $value;
}
}
12 changes: 7 additions & 5 deletions compat/yoast.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?php

if (
class_exists( 'WPSEO_Options' ) &&
method_exists( 'WPSEO_Options', 'get' ) &&
WPSEO_Options::get( 'opengraph' )
) {
/**
* If Yoast OpenGraph is enabled, we'll need disable PB when it gets the excerpt
* If Yoast OpenGraph is enabled, we'll need disable PB when it gets the excerpt
* to avoid conflicts with other plugins.
*
*/
function siteorigin_yoast_opengraph_panels_disable( $content ) {
global $wp_current_filter;

if ( count( $wp_current_filter ) > 2 && $wp_current_filter[1] == 'wpseo_head' ) {
// Temporarily disable Page Builder for this instance of the_content.
add_filter( 'siteorigin_panels_filter_content_enabled', '__return_false' );
} else {
add_filter( 'siteorigin_panels_filter_content_enabled', '__return_true' );
}

return $content;
}

Expand Down Expand Up @@ -77,11 +79,11 @@ class_exists( 'DOMDocument' )
* @return string
*/
function siteorigin_yoast_video_render_page_builder( $content, $vid, $post ) {
if ( ! empty( $_POST['panels_data'] ) ) {
if ( ! empty( $_POST['panels_data'] ) ) {
$content = SiteOrigin_Panels::renderer()->render( $post->ID );
}
return $content;

return $content;
}
add_filter( 'wpseo_video_index_content', 'siteorigin_yoast_video_render_page_builder', 10, 3 );
}
}
Loading

0 comments on commit 79da3bb

Please sign in to comment.