From 67d36b9ee74354e85b6e0826d675c873292fa200 Mon Sep 17 00:00:00 2001 From: Alex S <17275120+AlexGStapleton@users.noreply.github.com> Date: Tue, 1 Feb 2022 21:13:25 +1000 Subject: [PATCH 1/4] Compat: Add "Yoast SEO: Video Compatibility --- compat/yoast.php | 21 +++++++++++++++++++++ siteorigin-panels.php | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/compat/yoast.php b/compat/yoast.php index cd9bdc574..0119c643b 100644 --- a/compat/yoast.php +++ b/compat/yoast.php @@ -62,3 +62,24 @@ class_exists( 'DOMDocument' ) return $images; } add_filter( 'wpseo_sitemap_urlimages', 'siteorigin_yoast_sitemap_images_compat', 10, 2 ); + + +if ( function_exists( 'yoast_wpseo_video_seo_init' ) ) { + /** + * If the Yoast SEO: Video plugin is trying to index a post, and the post has a page builder layout, render it using Page Builder. + * + * @param $content The content to analyze. + * @param $vid Array with video info, usually empty. + * @param $post Post object. + * + * @return string + */ + function siteorigin_yoast_video_render_page_builder( $content, $vid, $post ) { + if ( ! empty( $_POST['panels_data'] ) ) { + $content = SiteOrigin_Panels::renderer()->render( $post->ID ); + } + return $content; + + } + add_filter( 'wpseo_video_index_content', 'siteorigin_yoast_video_render_page_builder', 10, 3 ); +} \ No newline at end of file diff --git a/siteorigin-panels.php b/siteorigin-panels.php index 745731beb..e338292cf 100644 --- a/siteorigin-panels.php +++ b/siteorigin-panels.php @@ -202,8 +202,11 @@ public function init_compat() { require_once plugin_dir_path( __FILE__ ) . 'compat/widget-options.php'; } - // Compatibility with Yoast Sitemap. - if ( defined( 'WPSEO_FILE' ) ) { + // Compatibility with Yoast plugins. + if ( + defined( 'WPSEO_FILE' ) || + function_exists( 'yoast_wpseo_video_seo_init' ) + ) { require_once plugin_dir_path( __FILE__ ) . 'compat/yoast.php'; } From 97fc5b88e652df6d12f7389a2e01451a1c35e35b Mon Sep 17 00:00:00 2001 From: Alex S <17275120+AlexGStapleton@users.noreply.github.com> Date: Tue, 1 Feb 2022 21:14:51 +1000 Subject: [PATCH 2/4] Yoast Compat Formatting --- compat/yoast.php | 98 ++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/compat/yoast.php b/compat/yoast.php index 0119c643b..06b11c8bb 100644 --- a/compat/yoast.php +++ b/compat/yoast.php @@ -1,68 +1,70 @@ 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; -} - -// If Yoast OpenGraph is enabled, disable Page Builder as needed. 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 + * 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; + } + + // If Yoast OpenGraph is enabled, disable Page Builder as needed. add_filter( 'the_content', 'siteorigin_yoast_opengraph_panels_disable', 1 ); } -/** - * Returns a list of all images added using Page Builder. - * - * @param $images an array of all detected images used in the current post. - * @param $post_id the current post id. - * - * @return array - */ -function siteorigin_yoast_sitemap_images_compat( $images, $post_id ) { - if ( - get_post_meta( $post_id, 'panels_data', true ) && - extension_loaded( 'xml' ) && - class_exists( 'DOMDocument' ) - ) { - $content = SiteOrigin_Panels::renderer()->render( - $post_id, - false - ); +if ( defined( 'WPSEO_FILE' ) ) { + /** + * Returns a list of all images added using Page Builder to allow for their inclusion in the Yoast Sitemap. + * + * @param $images an array of all detected images used in the current post. + * @param $post_id the current post id. + * + * @return array + */ + function siteorigin_yoast_sitemap_images_compat( $images, $post_id ) { + if ( + get_post_meta( $post_id, 'panels_data', true ) && + extension_loaded( 'xml' ) && + class_exists( 'DOMDocument' ) + ) { + $content = SiteOrigin_Panels::renderer()->render( + $post_id, + false + ); - libxml_use_internal_errors( true ); - $dom = new DOMDocument(); - $dom->loadHTML( '' . $content ); - libxml_clear_errors(); + libxml_use_internal_errors( true ); + $dom = new DOMDocument(); + $dom->loadHTML( '' . $content ); + libxml_clear_errors(); - foreach ( $dom->getElementsByTagName( 'img' ) as $img ) { - $src = $img->getAttribute( 'src' ); + foreach ( $dom->getElementsByTagName( 'img' ) as $img ) { + $src = $img->getAttribute( 'src' ); - if ( ! empty( $src ) && $src == esc_url( $src ) ) { - $images[] = array( - 'src' => $src, - ); + if ( ! empty( $src ) && $src == esc_url( $src ) ) { + $images[] = array( + 'src' => $src, + ); + } } } + + return $images; } - return $images; + add_filter( 'wpseo_sitemap_urlimages', 'siteorigin_yoast_sitemap_images_compat', 10, 2 ); } -add_filter( 'wpseo_sitemap_urlimages', 'siteorigin_yoast_sitemap_images_compat', 10, 2 ); - if ( function_exists( 'yoast_wpseo_video_seo_init' ) ) { /** From beb3366e16ed98bf9aaa5b926ec18119be875b37 Mon Sep 17 00:00:00 2001 From: Alex S <17275120+AlexGStapleton@users.noreply.github.com> Date: Mon, 7 Feb 2022 20:45:41 +1000 Subject: [PATCH 3/4] Yoast Compat: Check for New Yoast Script --- inc/admin.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/admin.php b/inc/admin.php index ec11f1e80..b7e938adc 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -567,8 +567,9 @@ public function enqueue_seo_compat() { if ( defined( 'WPSEO_FILE' ) && ( - wp_script_is( 'yoast-seo-admin-global-script' ) || // => 14.6 - wp_script_is( 'yoast-seo-metabox' ) // <= 14.5 + wp_script_is( 'yoast-seo-metabox' ) || // <= 14.5. + wp_script_is( 'yoast-seo-admin-global-script' ) || // => 14.6 <= 17.9. + wp_script_is( 'yoast-seo-post-edit-classic' ) // => 18 ) ) { wp_enqueue_script( From 234edd2aa85d24028f23cae93f84dc19cd4d3fe6 Mon Sep 17 00:00:00 2001 From: Andrew Misplon Date: Mon, 7 Feb 2022 14:30:30 +0200 Subject: [PATCH 4/4] Updated changelog --- readme.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.txt b/readme.txt index 7f613d42c..4b19e87ca 100644 --- a/readme.txt +++ b/readme.txt @@ -107,6 +107,10 @@ SiteOrigin Premium includes access to our professional email support service, pe == Changelog == += 2.16.2 - 07 February 2022 = +* Added Yoast Video SEO plugin integration. +* Restored content analysis functionality for newer Yoast SEO versions. + = 2.16.1 - 26 January 2022 = * Sidebar Emulator: Accounted for a potential notice when setting widget ID. * Updated the `Tested up to tag` to `5.9`.