From b11c38da99c461c33e93591efa52fc43334533d9 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 1 Nov 2023 08:49:53 -0500 Subject: [PATCH 1/3] allow block when no post type defined --- blocks/post/index.php | 2 +- blocks/query/index.php | 2 +- src/assets.php | 27 --------------------------- src/class-supported-post-types.php | 9 +++++++++ 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/blocks/post/index.php b/blocks/post/index.php index c46586e6..57999c84 100644 --- a/blocks/post/index.php +++ b/blocks/post/index.php @@ -12,7 +12,7 @@ */ function wp_curate_post_block_init(): void { $supported_post_types = new Supported_Post_Types(); - if ( ! in_array( $supported_post_types->get_current_post_type(), $supported_post_types->get_supported_post_types(), true ) ) { + if ( ! $supported_post_types->should_register_block() ) { return; } diff --git a/blocks/query/index.php b/blocks/query/index.php index 492d9ba6..4eac746a 100644 --- a/blocks/query/index.php +++ b/blocks/query/index.php @@ -17,7 +17,7 @@ function wp_curate_query_block_init(): void { $supported_post_types = new Supported_Post_Types(); - if ( ! in_array( $supported_post_types->get_current_post_type(), $supported_post_types->get_supported_post_types(), true ) ) { + if ( ! $supported_post_types->should_register_block() ) { return; } diff --git a/src/assets.php b/src/assets.php index 28e92f07..1da95160 100644 --- a/src/assets.php +++ b/src/assets.php @@ -31,15 +31,6 @@ function action_wp_enqueue_scripts(): void { | https://github.com/alleyinteractive/wp-asset-manager | */ - - // wp_enqueue_script( - // 'wp-curate-example-entry', - // get_entry_asset_url( 'example-entry' ), - // get_asset_dependency_array( 'example-entry' ), - // get_asset_version( 'example-entry' ), - // true - // ); - // wp_set_script_translations( 'wp-curate-example-entry', 'wp-curate' ); } /** @@ -55,15 +46,6 @@ function action_admin_enqueue_scripts(): void { | assets that are loaded only in the WordPress admin. | */ - - // wp_enqueue_script( - // 'wp-curate-admin-handle', - // get_entry_asset_url( 'admin-handle' ), - // get_asset_dependency_array( 'admin-handle' ), - // get_asset_version( 'admin-handle' ), - // true - // ); - // wp_set_script_translations( 'wp-curate-admin-handle', 'wp-curate' ); } /** @@ -79,15 +61,6 @@ function action_enqueue_block_editor_assets(): void { | enqueue assets that are loaded in the block editor. | */ - - // wp_enqueue_script( - // 'wp-curate-slotfills', - // get_entry_asset_url( 'slotfills' ), - // get_asset_dependency_array( 'slotfills' ), - // get_asset_version( 'slotfills' ), - // true - // ); - // wp_set_script_translations( 'wp-curate-slotfills', 'wp-curate' ); } /** diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index 756eed29..1867d41a 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -93,4 +93,13 @@ public function register_post_meta(): void { ] ); } + + /** + * Should we register the block in the current context. + * + * @return boolean + */ + public function should_register_block() { + return empty( $this->get_current_post_type() ) || in_array( $this->get_current_post_type(), $this->get_supported_post_types(), true ); + } } From 7ad1e80b2c90c3fc41b915c58d904928d8469ca1 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 1 Nov 2023 08:53:11 -0500 Subject: [PATCH 2/3] bump version --- CHANGELOG.md | 4 ++++ wp-curate.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce48c8c2..6d35094b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `WP Curate` will be documented in this file. +## 1.4.1 - 2023-11-01 + +- Bug fix: allow blocks when no post type is defined. + ## 1.4.0 - 2023-10-30 - Bug fix: prevents error if `termRelations` attribute is not set. diff --git a/wp-curate.php b/wp-curate.php index b2958a35..cef7dae5 100644 --- a/wp-curate.php +++ b/wp-curate.php @@ -3,7 +3,7 @@ * Plugin Name: WP Curate * Plugin URI: https://github.com/alleyinteractive/wp-curate * Description: Plugin to curate homepages and other landing pages - * Version: 1.4.0 + * Version: 1.4.1 * Author: Alley Interactive * Author URI: https://github.com/alleyinteractive/wp-curate * Requires at least: 6.3 From 04c57cff43f4e033d2433781d5062692389e25d8 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 1 Nov 2023 10:00:38 -0500 Subject: [PATCH 3/3] code review feedback --- entries/slotfills/index.php | 2 +- src/class-supported-post-types.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/entries/slotfills/index.php b/entries/slotfills/index.php index 34361583..e7917f36 100644 --- a/entries/slotfills/index.php +++ b/entries/slotfills/index.php @@ -22,7 +22,7 @@ function register_slotfills_scripts(): void { $allowed_post_types = apply_filters( 'wp_curate_duduplication_slotfill_post_types', [ 'page', 'post' ] ); $supported_post_types = new Supported_Post_Types(); - if ( ! in_array( $supported_post_types->get_current_post_type(), $allowed_post_types, true ) ) { + if ( ! $supported_post_types->should_register_block() ) { return; } diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index 1867d41a..ca0f814c 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -99,7 +99,7 @@ public function register_post_meta(): void { * * @return boolean */ - public function should_register_block() { + public function should_register_block(): bool { return empty( $this->get_current_post_type() ) || in_array( $this->get_current_post_type(), $this->get_supported_post_types(), true ); } }