From decd8afa094c41082f71bb4bd98b777b88dc4cc3 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Mon, 29 Apr 2024 11:14:10 -0400 Subject: [PATCH 1/5] Only load site-content plugin on post-new.php --- includes/class-coblocks-site-content.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/class-coblocks-site-content.php b/includes/class-coblocks-site-content.php index 0588330dd2d..6f45634851b 100644 --- a/includes/class-coblocks-site-content.php +++ b/includes/class-coblocks-site-content.php @@ -20,6 +20,15 @@ class CoBlocks_Site_Content { */ public function __construct() { + global $pagenow; + + // Ensure Site Content only loads if within the post editor. + if ( + ! isset( $pagenow ) || strpos( $pagenow, 'post-new.php' ) === false + ) { + return; + } + add_action( 'init', array( $this, 'register_settings' ), 11 ); add_filter( 'wp_insert_post_empty_content', array( $this, 'allow_empty_post_content' ), 10, 2 ); From b1486326e1acc807b1a7f9746e5e2df9d690fa95 Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Mon, 29 Apr 2024 11:36:25 -0400 Subject: [PATCH 2/5] Only load site-content plugin on post-new.php --- includes/class-coblocks-site-content.php | 9 --------- src/extensions/site-content/index.js | 4 ++++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/includes/class-coblocks-site-content.php b/includes/class-coblocks-site-content.php index 6f45634851b..0588330dd2d 100644 --- a/includes/class-coblocks-site-content.php +++ b/includes/class-coblocks-site-content.php @@ -20,15 +20,6 @@ class CoBlocks_Site_Content { */ public function __construct() { - global $pagenow; - - // Ensure Site Content only loads if within the post editor. - if ( - ! isset( $pagenow ) || strpos( $pagenow, 'post-new.php' ) === false - ) { - return; - } - add_action( 'init', array( $this, 'register_settings' ), 11 ); add_filter( 'wp_insert_post_empty_content', array( $this, 'allow_empty_post_content' ), 10, 2 ); diff --git a/src/extensions/site-content/index.js b/src/extensions/site-content/index.js index abb2f8524e5..e254d44ff14 100644 --- a/src/extensions/site-content/index.js +++ b/src/extensions/site-content/index.js @@ -45,6 +45,10 @@ export const CoBlocksSiteContent = ( props ) => { const { postTypes } = props; + if ( ! window.location.pathname.includes( 'post-new.php' ) ) { + return; + } + return ( Date: Mon, 29 Apr 2024 11:41:24 -0400 Subject: [PATCH 3/5] Add comment --- src/extensions/site-content/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extensions/site-content/index.js b/src/extensions/site-content/index.js index e254d44ff14..674ac5b60ca 100644 --- a/src/extensions/site-content/index.js +++ b/src/extensions/site-content/index.js @@ -45,6 +45,7 @@ export const CoBlocksSiteContent = ( props ) => { const { postTypes } = props; + // Prevent Site Content from loading outside of post-new.php pages. if ( ! window.location.pathname.includes( 'post-new.php' ) ) { return; } From a0acd54bb4b15fcea6afb1581bc5372a770f054e Mon Sep 17 00:00:00 2001 From: Evan Herman Date: Mon, 29 Apr 2024 11:49:15 -0400 Subject: [PATCH 4/5] Move conditional --- src/extensions/site-content/index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/extensions/site-content/index.js b/src/extensions/site-content/index.js index 674ac5b60ca..810741e2911 100644 --- a/src/extensions/site-content/index.js +++ b/src/extensions/site-content/index.js @@ -45,11 +45,6 @@ export const CoBlocksSiteContent = ( props ) => { const { postTypes } = props; - // Prevent Site Content from loading outside of post-new.php pages. - if ( ! window.location.pathname.includes( 'post-new.php' ) ) { - return; - } - return ( { + // Prevent Site Content from loading outside of post-new.php pages. + const isPostEditor = window.location.pathname.includes( 'post-new.php' ) const [ siteContentEnabled ] = useEntityProp( 'root', 'site', SITE_CONTENT_FEATURE_ENABLED_KEY ); // In the context of `widgets.php` site content is incompatible due to missing dependencies. const isCompatible = !! selectWithoutHooks( 'core/editor' ); - return siteContentEnabled && isCompatible; + return isPostEditor && siteContentEnabled && isCompatible; } ), withSelect( ( select ) => { const { From 5e4597080e3772d3f3004f1a594fe6f66d40e25e Mon Sep 17 00:00:00 2001 From: aledesma-godaddy Date: Tue, 30 Apr 2024 10:35:15 -0700 Subject: [PATCH 5/5] lint fix --- src/extensions/site-content/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/site-content/index.js b/src/extensions/site-content/index.js index 810741e2911..ea48e043f06 100644 --- a/src/extensions/site-content/index.js +++ b/src/extensions/site-content/index.js @@ -75,7 +75,7 @@ registerPlugin( PLUGIN_NAME, { render: compose( [ ifCondition( () => { // Prevent Site Content from loading outside of post-new.php pages. - const isPostEditor = window.location.pathname.includes( 'post-new.php' ) + const isPostEditor = window.location.pathname.includes( 'post-new.php' ); const [ siteContentEnabled ] = useEntityProp( 'root', 'site', SITE_CONTENT_FEATURE_ENABLED_KEY ); // In the context of `widgets.php` site content is incompatible due to missing dependencies. const isCompatible = !! selectWithoutHooks( 'core/editor' );