From add9496dd9899e06d3fa58c3e9a0873a4c4953d8 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 11 Oct 2023 16:18:49 -0500 Subject: [PATCH 01/18] WIP: issue-57 From 139e5396107d7612799b6a1181471b85ce05dd89 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 12 Oct 2023 08:50:11 -0500 Subject: [PATCH 02/18] add file to control supported post types --- blocks/post/index.php | 7 +++ blocks/query/index.php | 6 +++ src/class-supported-post-types.php | 73 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/class-supported-post-types.php diff --git a/blocks/post/index.php b/blocks/post/index.php index c4f7d0af..c46586e6 100644 --- a/blocks/post/index.php +++ b/blocks/post/index.php @@ -5,10 +5,17 @@ * @package wp-curate */ +use Alley\WP\WP_Curate\Supported_Post_Types; + /** * Registers the wp-curate/post block using the metadata loaded from the `block.json` file. */ 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 ) ) { + return; + } + // Register the block by passing the location of block.json. register_block_type( __DIR__ diff --git a/blocks/query/index.php b/blocks/query/index.php index 719991a4..232aefd7 100644 --- a/blocks/query/index.php +++ b/blocks/query/index.php @@ -6,6 +6,7 @@ */ use Byline_Manager\Models\Profile; +use Alley\WP\WP_Curate\Supported_Post_Types; /** * Registers the block using the metadata loaded from the `block.json` file. @@ -15,6 +16,11 @@ * @see https://developer.wordpress.org/reference/functions/register_block_type/ */ 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 ) ) { + return; + } + // Register the block by passing the location of block.json. register_block_type( __DIR__, diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php new file mode 100644 index 00000000..9e6db788 --- /dev/null +++ b/src/class-supported-post-types.php @@ -0,0 +1,73 @@ +initialize_supported_post_types(); + } + + /** + * Initialize the supported post types. + */ + public function initialize_supported_post_types() { + // Get all post types. + $post_types = get_post_types( [], 'objects' ); + $supported_post_types = array_filter( $post_types, fn( $type ) => $type->public && use_block_editor_for_post_type( $type->name ) ); + $this->supported_post_types = ( wp_list_pluck( $supported_post_types, 'name' ) ); + } + + /** + * Get the supported post types. + * + * @return array + */ + public function get_supported_post_types() { + return apply_filters( 'wp_curate_supported_post_types', $this->supported_post_types ); + } + + /** + * Get the current post type. + * + * @return string + */ + public function get_current_post_type() { + $post_type = ''; + + // Ensure we are in the admin before proceeding. + if ( is_admin() ) { + global $pagenow; + + // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Recommended + if ( 'post.php' === $pagenow && ! empty( $_GET['post'] ) ) { + // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $post_id = absint( $_GET['post'] ); + $post_type = get_post_type( $post_id ); + // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Recommended + } elseif ( 'post-new.php' === $pagenow && ! empty( $_GET['post_type'] ) ) { + // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $post_type = sanitize_text_field( $_GET['post_type'] ); + } + } + return $post_type; + } +} From 06868f4cbdfa265c70a6597da5d7675b4a18be6e Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Tue, 24 Oct 2023 09:25:29 -0500 Subject: [PATCH 03/18] WIP: issue-73 From 3b566765d4264418afc8fc8fc141de1951bda576 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Tue, 24 Oct 2023 16:56:15 -0500 Subject: [PATCH 04/18] editor --- blocks/query/block.json | 20 +++++++++++ blocks/query/edit.tsx | 64 ++++++++++++++++++++++++++++++++++- blocks/query/types.ts | 4 +++ services/deduplicate/index.ts | 4 +-- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/blocks/query/block.json b/blocks/query/block.json index e63c62fc..5a0f498b 100644 --- a/blocks/query/block.json +++ b/blocks/query/block.json @@ -74,6 +74,26 @@ "type": "array" }, "type": "object" + }, + "termRelations": { + "default": {}, + "items": { + "default": "AND", + "enum": [ + "AND", + "OR" + ], + "type": "string" + }, + "type": "object" + }, + "taxRelation": { + "default": "AND", + "enum": [ + "AND", + "OR" + ], + "type": "string" } } } diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index 2b887286..40b90cf2 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -9,6 +9,7 @@ import { PanelRow, RadioControl, RangeControl, + SelectControl, TextControl, } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; @@ -59,6 +60,8 @@ export default function Edit({ postTypes = ['post'], searchTerm = '', terms = {}, + termRelations = {}, + taxRelation = 'AND', }, setAttributes, }: EditProps) { @@ -93,16 +96,27 @@ export default function Edit({ const [availableTaxonomies, setAvailableTaxonomies] = useState({}); const [availableTypes, setAvailableTypes] = useState({}); + const taxCount = allowedTaxonomies.reduce((acc: number, taxonomy: string) => { + const hasTax = terms[taxonomy]?.length > 0 ? 1 : 0; + return acc + hasTax; + }, 0); + let termQueryArgs = ''; if (Object.keys(availableTaxonomies).length > 0) { allowedTaxonomies.forEach((taxonomy) => { if (terms[taxonomy]?.length > 0) { const restBase = availableTaxonomies[taxonomy].rest_base; if (restBase) { - termQueryArgs += `&${restBase}=${terms[taxonomy].map((term) => term.id).join(',')}`; + termQueryArgs += `&${restBase}[terms]=${terms[taxonomy].map((term) => term.id).join(',')}`; + if (termRelations[taxonomy] !== '' && typeof termRelations[taxonomy] !== 'undefined') { + termQueryArgs += `&${restBase}[operator]=${termRelations[taxonomy]}`; + } } } }); + if (taxCount > 1) { + termQueryArgs += `&tax_relation=${taxRelation}`; + } } const manualPostIds = manualPosts.map((post) => (post ?? null)).join(','); @@ -200,6 +214,14 @@ export default function Edit({ setAttributes({ terms: newTermAttrs }); }); + const setTermRelation = ((type: string, relation: string) => { + const newTermRelationAttrs = { + ...termRelations, + [type]: relation, + }; + setAttributes({ termRelations: newTermRelationAttrs }); + }); + const setNumberOfPosts = (newValue?: number) => { setAttributes({ numberOfPosts: newValue, @@ -319,9 +341,49 @@ export default function Edit({ onSelect={(newCategories: Term[]) => setTerms(taxonomy, newCategories)} multiple /> + {terms[taxonomy]?.length > 1 ? ( + setTermRelation(taxonomy, newValue)} + value={termRelations[taxonomy]} + /> + ) : null} +
)) ) : null} + {taxCount > 1 ? ( + setAttributes({ taxRelation: newValue })} + value={taxRelation} + /> + ) : null } setAttributes({ searchTerm: next })} diff --git a/blocks/query/types.ts b/blocks/query/types.ts index df1ff4cc..d1d1a49c 100644 --- a/blocks/query/types.ts +++ b/blocks/query/types.ts @@ -15,6 +15,10 @@ interface EditProps { terms?: { [key: string]: any[]; }; + termRelations?: { + [key: string]: string; + }; + taxRelation?: string; }; setAttributes: (attributes: any) => void; } diff --git a/services/deduplicate/index.ts b/services/deduplicate/index.ts index 71442672..fbb6a09d 100644 --- a/services/deduplicate/index.ts +++ b/services/deduplicate/index.ts @@ -121,13 +121,13 @@ export function mainDedupe() { queryBlocks.forEach((queryBlock) => { const { attributes } = queryBlock; const { - backfillPosts = [], + backfillPosts = null, deduplication = 'inherit', posts = [], numberOfPosts = 5, postTypes = ['post'], } = attributes; - if (!backfillPosts.length) { + if (!backfillPosts) { return; } const postTypeString = postTypes.join(','); From f29010dc590647e217f9ce0aec3302c80aee36c1 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Tue, 24 Oct 2023 17:09:59 -0500 Subject: [PATCH 05/18] front end --- src/class-plugin-curated-posts.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/class-plugin-curated-posts.php b/src/class-plugin-curated-posts.php index 1a43bd95..acd0d549 100644 --- a/src/class-plugin-curated-posts.php +++ b/src/class-plugin-curated-posts.php @@ -51,7 +51,7 @@ public function with_query_context( array $context, array $attributes, WP_Block_ if ( isset( $attributes['terms'] ) && is_array( $attributes['terms'] ) && count( $attributes['terms'] ) > 0 ) { $args['tax_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - 'relation' => 'AND', + 'relation' => $attributes['taxRelation'] ?? 'AND', ]; foreach ( $attributes['terms'] as $taxonomy => $terms ) { @@ -59,6 +59,7 @@ public function with_query_context( array $context, array $attributes, WP_Block_ $args['tax_query'][] = [ 'taxonomy' => $taxonomy, 'terms' => array_column( $terms, 'id' ), + 'operator' => $attributes['termsRelation'][ $taxonomy ] ?? 'AND', ]; } } From 606f5741b0ed1d0c09d22cee564eac57c71c099e Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Tue, 24 Oct 2023 17:11:08 -0500 Subject: [PATCH 06/18] lint --- blocks/query/edit.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index 40b90cf2..4d2960c6 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -345,7 +345,7 @@ export default function Edit({ Date: Wed, 25 Oct 2023 23:21:31 -0500 Subject: [PATCH 07/18] phpstan --- src/class-plugin-curated-posts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-plugin-curated-posts.php b/src/class-plugin-curated-posts.php index acd0d549..3b6a9d78 100644 --- a/src/class-plugin-curated-posts.php +++ b/src/class-plugin-curated-posts.php @@ -59,7 +59,7 @@ public function with_query_context( array $context, array $attributes, WP_Block_ $args['tax_query'][] = [ 'taxonomy' => $taxonomy, 'terms' => array_column( $terms, 'id' ), - 'operator' => $attributes['termsRelation'][ $taxonomy ] ?? 'AND', + 'operator' => is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND', ]; } } From 73c289422cbf759747fa249143316fc75e27e914 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 25 Oct 2023 23:35:42 -0500 Subject: [PATCH 08/18] bump to 1.2.0 --- wp-curate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-curate.php b/wp-curate.php index a4abd0e5..986e4ee6 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.1.0 + * Version: 1.2.0 * Author: Alley Interactive * Author URI: https://github.com/alleyinteractive/wp-curate * Requires at least: 6.3 From 4266e7bbff85dfd20c4a1a7d90e35b1f84d7d8ad Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 11:23:40 -0500 Subject: [PATCH 09/18] code review feedback --- CHANGELOG.md | 10 ++++- blocks/query/edit.tsx | 63 +++++++++++----------------- services/buildTermQueryArgs/index.ts | 40 ++++++++++++++++++ 3 files changed, 73 insertions(+), 40 deletions(-) create mode 100644 services/buildTermQueryArgs/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index ff61d584..25a7f439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `WP Curate` will be documented in this file. -## 0.1.0 - 202X-XX-XX +## 1.2.0 - 2023-10-26 + +- Adds support for AND/OR operators in the Query Parameters, giving more control over what posts to show. + +## 1.1.0 - 2023-09-21 + +- Bug fix: prevents error if post type does not support meta. + +## 1.0.0 - 2023-09-19 - Initial release diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index 4d2960c6..71ce9d3b 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -31,6 +31,8 @@ import { mainDedupe, } from '../../services/deduplicate'; +import buildTermQueryArgs from '../../services/buildTermQueryArgs'; + import './index.scss'; interface Window { @@ -72,6 +74,17 @@ export default function Edit({ } = {}, } = (window as any as Window); + const andOrOptions = [ + { + label: __('AND', 'wp-curate'), + value: 'AND', + }, + { + label: __('OR', 'wp-curate'), + value: 'OR', + }, + ]; + // @ts-ignore const [isPostDeduplicating, postTypeObject] = useSelect( (select) => { @@ -101,23 +114,13 @@ export default function Edit({ return acc + hasTax; }, 0); - let termQueryArgs = ''; - if (Object.keys(availableTaxonomies).length > 0) { - allowedTaxonomies.forEach((taxonomy) => { - if (terms[taxonomy]?.length > 0) { - const restBase = availableTaxonomies[taxonomy].rest_base; - if (restBase) { - termQueryArgs += `&${restBase}[terms]=${terms[taxonomy].map((term) => term.id).join(',')}`; - if (termRelations[taxonomy] !== '' && typeof termRelations[taxonomy] !== 'undefined') { - termQueryArgs += `&${restBase}[operator]=${termRelations[taxonomy]}`; - } - } - } - }); - if (taxCount > 1) { - termQueryArgs += `&tax_relation=${taxRelation}`; - } - } + const termQueryArgs = buildTermQueryArgs( + allowedTaxonomies, + terms, + availableTaxonomies, + termRelations, + taxRelation, + ); const manualPostIds = manualPosts.map((post) => (post ?? null)).join(','); const postTypeString = postTypes.join(','); @@ -157,7 +160,7 @@ export default function Edit({ per_page: 20, }, ); - path += termQueryArgs; + path += `&${termQueryArgs}`; apiFetch({ path, @@ -348,18 +351,9 @@ export default function Edit({ availableTaxonomies[taxonomy].name || taxonomy, )} help={__('AND: Posts must have all selected terms. OR: Posts may have one or more selected terms.', 'wp-curate')} - options={[ - { - label: __('AND', 'wp-curate'), - value: 'AND', - }, - { - label: __('OR', 'wp-curate'), - value: 'OR', - }, - ]} + options={andOrOptions} onChange={(newValue) => setTermRelation(taxonomy, newValue)} - value={termRelations[taxonomy]} + value={termRelations[taxonomy] ?? 'OR'} /> ) : null}
@@ -370,16 +364,7 @@ export default function Edit({ setAttributes({ taxRelation: newValue })} value={taxRelation} /> diff --git a/services/buildTermQueryArgs/index.ts b/services/buildTermQueryArgs/index.ts new file mode 100644 index 00000000..2320a05d --- /dev/null +++ b/services/buildTermQueryArgs/index.ts @@ -0,0 +1,40 @@ +/** + * Builds the term query args for the WP REST API. + * + * @param string[] allowedTaxonomies The list of allowed taxonomies. + * @param { [key: string]: any[] } terms The selected terms. + * @param { [key: string]: any[] } availableTaxonomies The available taxonomies. + * @param { [key: string]: string } termRelations The AND/OR relation used for each taxonomy. + * @param string taxRelation The AND/OR relation used for all the terms. + * @returns string The term query args. + */ +export default function buildTermQueryArts( + allowedTaxonomies: string[], + terms: { [key: string]: any[] }, + availableTaxonomies: { [key: string]: any }, + termRelations: { [key: string]: string }, + taxRelation: string, +): string { + const taxCount = allowedTaxonomies.reduce((acc: number, taxonomy: string) => { + const hasTax = terms[taxonomy]?.length > 0 ? 1 : 0; + return acc + hasTax; + }, 0); + const termQueryArgs: string[] = []; + if (Object.keys(availableTaxonomies).length > 0) { + allowedTaxonomies.forEach((taxonomy) => { + if (terms[taxonomy]?.length > 0) { + const restBase = availableTaxonomies[taxonomy].rest_base; + if (restBase) { + termQueryArgs.push(`${restBase}[terms]=${terms[taxonomy].map((term) => term.id).join(',')}`); + if (termRelations[taxonomy] !== '' && typeof termRelations[taxonomy] !== 'undefined') { + termQueryArgs.push(`${restBase}[operator]=${termRelations[taxonomy]}`); + } + } + } + }); + if (taxCount > 1) { + termQueryArgs.push(`tax_relation=${taxRelation}`); + } + } + return termQueryArgs.join('&'); +} From aea131a07b5f3a2650c8ca8cd7497e3b4ae3488d Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 11:35:20 -0500 Subject: [PATCH 10/18] coderabbit suggestions --- blocks/query/edit.tsx | 5 +---- services/buildTermQueryArgs/index.ts | 8 +++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index 71ce9d3b..76cc7974 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -109,10 +109,7 @@ export default function Edit({ const [availableTaxonomies, setAvailableTaxonomies] = useState({}); const [availableTypes, setAvailableTypes] = useState({}); - const taxCount = allowedTaxonomies.reduce((acc: number, taxonomy: string) => { - const hasTax = terms[taxonomy]?.length > 0 ? 1 : 0; - return acc + hasTax; - }, 0); + const taxCount = allowedTaxonomies.filter((taxonomy: string) => terms[taxonomy]?.length > 0).length; // eslint-disable-line max-len const termQueryArgs = buildTermQueryArgs( allowedTaxonomies, diff --git a/services/buildTermQueryArgs/index.ts b/services/buildTermQueryArgs/index.ts index 2320a05d..52e17f41 100644 --- a/services/buildTermQueryArgs/index.ts +++ b/services/buildTermQueryArgs/index.ts @@ -8,17 +8,15 @@ * @param string taxRelation The AND/OR relation used for all the terms. * @returns string The term query args. */ -export default function buildTermQueryArts( +export default function buildTermQueryArgs( allowedTaxonomies: string[], terms: { [key: string]: any[] }, availableTaxonomies: { [key: string]: any }, termRelations: { [key: string]: string }, taxRelation: string, ): string { - const taxCount = allowedTaxonomies.reduce((acc: number, taxonomy: string) => { - const hasTax = terms[taxonomy]?.length > 0 ? 1 : 0; - return acc + hasTax; - }, 0); + const taxCount = allowedTaxonomies.filter((taxonomy: string) => terms[taxonomy]?.length > 0).length; // eslint-disable-line max-len + const termQueryArgs: string[] = []; if (Object.keys(availableTaxonomies).length > 0) { allowedTaxonomies.forEach((taxonomy) => { From 3fe4fe9db16697752ee607b58c34019fe103b7a4 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 11:44:57 -0500 Subject: [PATCH 11/18] add type for taxonomies --- services/buildTermQueryArgs/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/buildTermQueryArgs/index.ts b/services/buildTermQueryArgs/index.ts index 52e17f41..f38151d4 100644 --- a/services/buildTermQueryArgs/index.ts +++ b/services/buildTermQueryArgs/index.ts @@ -1,3 +1,11 @@ +interface Types { + [key: string]: { + name: string; + slug: string; + rest_base: string; + }; +} + /** * Builds the term query args for the WP REST API. * @@ -11,7 +19,7 @@ export default function buildTermQueryArgs( allowedTaxonomies: string[], terms: { [key: string]: any[] }, - availableTaxonomies: { [key: string]: any }, + availableTaxonomies: Types, termRelations: { [key: string]: string }, taxRelation: string, ): string { From 98f1a5891e7d75d08dcfc5cb08930f952442ba59 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 14:07:18 -0500 Subject: [PATCH 12/18] phpstan --- src/class-supported-post-types.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index 9e6db788..e2cc8998 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -14,7 +14,7 @@ final class Supported_Post_Types { /** * Stores the supported types. * - * @var array + * @var string[] */ private array $supported_post_types; @@ -29,7 +29,7 @@ public function __construct() { /** * Initialize the supported post types. */ - public function initialize_supported_post_types() { + public function initialize_supported_post_types(): void { // Get all post types. $post_types = get_post_types( [], 'objects' ); $supported_post_types = array_filter( $post_types, fn( $type ) => $type->public && use_block_editor_for_post_type( $type->name ) ); @@ -39,7 +39,7 @@ public function initialize_supported_post_types() { /** * Get the supported post types. * - * @return array + * @return string[] */ public function get_supported_post_types() { return apply_filters( 'wp_curate_supported_post_types', $this->supported_post_types ); @@ -48,9 +48,9 @@ public function get_supported_post_types() { /** * Get the current post type. * - * @return string + * @return string|false */ - public function get_current_post_type() { + public function get_current_post_type(): string | false { $post_type = ''; // Ensure we are in the admin before proceeding. From 04a858c07024e79cc7b9728e1d89c995b7562e8b Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 14:10:39 -0500 Subject: [PATCH 13/18] phpcs --- src/class-supported-post-types.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index e2cc8998..cc2e1c82 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -20,7 +20,6 @@ final class Supported_Post_Types { /** * Set up. - * */ public function __construct() { $this->initialize_supported_post_types(); From 544a1804cded4f40c08a7784cfeaef9834ac433b Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 14:16:34 -0500 Subject: [PATCH 14/18] phpcs --- src/class-supported-post-types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index cc2e1c82..02c5d10e 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -49,7 +49,7 @@ public function get_supported_post_types() { * * @return string|false */ - public function get_current_post_type(): string | false { + public function get_current_post_type(): string|false { $post_type = ''; // Ensure we are in the admin before proceeding. From 64bc804f2ee3b2ad5494391254805d6006cf03b0 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 14:26:20 -0500 Subject: [PATCH 15/18] conditionally load post meta --- config/post-meta.json | 8 -------- src/class-supported-post-types.php | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/post-meta.json b/config/post-meta.json index 1575f8d4..e69de29b 100644 --- a/config/post-meta.json +++ b/config/post-meta.json @@ -1,8 +0,0 @@ -{ - "wp_curate_deduplication": { - "post_types": [ - "all" - ], - "type": "boolean" - } -} diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index 02c5d10e..fdeb7f15 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -33,6 +33,7 @@ public function initialize_supported_post_types(): void { $post_types = get_post_types( [], 'objects' ); $supported_post_types = array_filter( $post_types, fn( $type ) => $type->public && use_block_editor_for_post_type( $type->name ) ); $this->supported_post_types = ( wp_list_pluck( $supported_post_types, 'name' ) ); + $this->register_post_meta(); } /** @@ -69,4 +70,18 @@ public function get_current_post_type(): string|false { } return $post_type; } + + /** + * Register the post meta on the supported post types. + */ + public function register_post_meta(): void { + register_meta_helper( + 'post', + $this->get_supported_post_types(), + 'wp_curate_deduplication', + [ + 'type' => 'boolean', + ] + ); + } } From a4742633a82b3bc4a0f8dd9b33a9ced8d5254da5 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 16:01:47 -0500 Subject: [PATCH 16/18] Update src/class-supported-post-types.php Co-authored-by: Renato Alves <19148962+renatonascalves@users.noreply.github.com> --- src/class-supported-post-types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-supported-post-types.php b/src/class-supported-post-types.php index fdeb7f15..f1aa5396 100644 --- a/src/class-supported-post-types.php +++ b/src/class-supported-post-types.php @@ -41,7 +41,7 @@ public function initialize_supported_post_types(): void { * * @return string[] */ - public function get_supported_post_types() { + public function get_supported_post_types(): array { return apply_filters( 'wp_curate_supported_post_types', $this->supported_post_types ); } From 201a34e06356d06d84c3ece992b9c7b2d7984ce3 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 16:04:59 -0500 Subject: [PATCH 17/18] bump version and readme --- CHANGELOG.md | 5 +++++ wp-curate.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25a7f439..130dcfba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to `WP Curate` will be documented in this file. ## 1.2.0 - 2023-10-26 +- Only show the blocks and register the meta on supported post types. +- Supported post types defaults to all Block Editor post types, but can be filtered by filtering `wp_curate_supported_post_types`. + +## 1.2.0 - 2023-10-26 + - Adds support for AND/OR operators in the Query Parameters, giving more control over what posts to show. ## 1.1.0 - 2023-09-21 diff --git a/wp-curate.php b/wp-curate.php index 986e4ee6..f72c32ea 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.2.0 + * Version: 1.3.0 * Author: Alley Interactive * Author URI: https://github.com/alleyinteractive/wp-curate * Requires at least: 6.3 From 5e15228f207abdac9c73b91ed347abbbc042e33f Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 26 Oct 2023 16:08:29 -0500 Subject: [PATCH 18/18] fix version number in readme --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 130dcfba..9def8fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to `WP Curate` will be documented in this file. -## 1.2.0 - 2023-10-26 +## 1.3.0 - 2023-10-26 - Only show the blocks and register the meta on supported post types. - Supported post types defaults to all Block Editor post types, but can be filtered by filtering `wp_curate_supported_post_types`.