From 90e57ec1d2dfa0f1233384f872e2737036da4696 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 4 Sep 2024 15:36:52 -0500 Subject: [PATCH 1/6] Revert "Adds filter to control max number of posts in query block" --- blocks/query/block.json | 4 ++++ blocks/query/edit.tsx | 7 +++---- blocks/query/index.php | 8 -------- blocks/query/types.ts | 1 + 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/blocks/query/block.json b/blocks/query/block.json index 8080ee99..94a577bd 100644 --- a/blocks/query/block.json +++ b/blocks/query/block.json @@ -31,6 +31,10 @@ ], "type": "string" }, + "maxNumberOfPosts": { + "default": 10, + "type": "number" + }, "minNumberOfPosts": { "default": 1, "type": "number" diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index dcdba75e..08439766 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -47,7 +47,6 @@ interface Window { allowedPostTypes: Array; allowedTaxonomies: Array; parselyAvailable: string, - maxPosts: number, }; } @@ -63,6 +62,7 @@ export default function Edit({ attributes: { backfillPosts = [], deduplication = 'inherit', + maxNumberOfPosts = 10, minNumberOfPosts = 1, numberOfPosts = 5, offset = 0, @@ -82,7 +82,6 @@ export default function Edit({ allowedPostTypes = [], allowedTaxonomies = [], parselyAvailable = 'false', - maxPosts = 10, } = {}, } = (window as any as Window); @@ -327,14 +326,14 @@ export default function Edit({ title={__('Setup', 'wp-curate')} initialOpen > - {minNumberOfPosts !== undefined && minNumberOfPosts !== maxPosts ? ( + {minNumberOfPosts !== undefined && minNumberOfPosts !== maxNumberOfPosts ? ( ) : null} $allowed_post_types, 'allowedTaxonomies' => $allowed_taxonomies, 'parselyAvailable' => $parsely_available ? 'true' : 'false', - 'maxPosts' => $max_posts, ] ); } diff --git a/blocks/query/types.ts b/blocks/query/types.ts index a442b45f..947fde22 100644 --- a/blocks/query/types.ts +++ b/blocks/query/types.ts @@ -2,6 +2,7 @@ interface EditProps { attributes: { backfillPosts?: number[]; deduplication?: string; + maxNumberOfPosts?: number; minNumberOfPosts?: number; numberOfPosts?: number; offset?: number; From 0cdc3bb1f2890c2d7440b4fa8dc1532a866d4a5f Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 4 Sep 2024 15:53:24 -0500 Subject: [PATCH 2/6] allows max_posts to be filtered by php, but also set in block attributes --- blocks/query/block.json | 1 - blocks/query/edit.tsx | 7 ++++++- blocks/query/index.php | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/blocks/query/block.json b/blocks/query/block.json index 94a577bd..73c80f52 100644 --- a/blocks/query/block.json +++ b/blocks/query/block.json @@ -32,7 +32,6 @@ "type": "string" }, "maxNumberOfPosts": { - "default": 10, "type": "number" }, "minNumberOfPosts": { diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index 08439766..8516b36c 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -47,6 +47,7 @@ interface Window { allowedPostTypes: Array; allowedTaxonomies: Array; parselyAvailable: string, + maxPosts: number, }; } @@ -62,7 +63,7 @@ export default function Edit({ attributes: { backfillPosts = [], deduplication = 'inherit', - maxNumberOfPosts = 10, + maxNumberOfPosts: maxNumberOfPostsAttr, minNumberOfPosts = 1, numberOfPosts = 5, offset = 0, @@ -82,6 +83,7 @@ export default function Edit({ allowedPostTypes = [], allowedTaxonomies = [], parselyAvailable = 'false', + maxPosts = 10, } = {}, } = (window as any as Window); @@ -89,6 +91,9 @@ export default function Edit({ setAttributes({ postTypes: allowedPostTypes }); } + const maxNumberOfPosts = !maxNumberOfPostsAttr + || maxNumberOfPostsAttr > maxPosts ? maxPosts : maxNumberOfPostsAttr; + const andOrOptions = [ { label: __('AND', 'wp-curate'), diff --git a/blocks/query/index.php b/blocks/query/index.php index 090cee01..ecf9d464 100644 --- a/blocks/query/index.php +++ b/blocks/query/index.php @@ -43,6 +43,13 @@ function wp_curate_query_block_init(): void { */ $allowed_taxonomies = apply_filters( 'wp_curate_allowed_taxonomies', [ 'category', 'post_tag' ] ); + /** + * Filter the maximum number of posts that can be displayed in the Query block. + * + * @param integer $max_posts The maximum number of posts to display. + */ + $max_posts = apply_filters( 'wp_curate_max_posts', 10 ); + /** * Filter whether to use Parsely. * @@ -56,6 +63,7 @@ function wp_curate_query_block_init(): void { 'allowedPostTypes' => $allowed_post_types, 'allowedTaxonomies' => $allowed_taxonomies, 'parselyAvailable' => $parsely_available ? 'true' : 'false', + 'maxPosts' => $max_posts, ] ); } From 7ea7260b6c378f1ad0d354e241b7d9c95a315f79 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Wed, 4 Sep 2024 16:07:27 -0500 Subject: [PATCH 3/6] wp_localize_script converts to string --- blocks/query/edit.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/blocks/query/edit.tsx b/blocks/query/edit.tsx index 8516b36c..6cadef64 100644 --- a/blocks/query/edit.tsx +++ b/blocks/query/edit.tsx @@ -47,7 +47,7 @@ interface Window { allowedPostTypes: Array; allowedTaxonomies: Array; parselyAvailable: string, - maxPosts: number, + maxPosts: string, }; } @@ -83,7 +83,7 @@ export default function Edit({ allowedPostTypes = [], allowedTaxonomies = [], parselyAvailable = 'false', - maxPosts = 10, + maxPosts = '10', } = {}, } = (window as any as Window); @@ -92,7 +92,7 @@ export default function Edit({ } const maxNumberOfPosts = !maxNumberOfPostsAttr - || maxNumberOfPostsAttr > maxPosts ? maxPosts : maxNumberOfPostsAttr; + || maxNumberOfPostsAttr > parseInt(maxPosts, 10) ? parseInt(maxPosts, 10) : maxNumberOfPostsAttr; // eslint-disable-line max-len const andOrOptions = [ { @@ -278,6 +278,10 @@ export default function Edit({ }); }; + if (numberOfPosts > maxNumberOfPosts) { + setNumberOfPosts(maxNumberOfPosts); + } + for (let i = 0; i < numberOfPosts; i += 1) { if (!manualPosts[i]) { manualPosts[i] = null; // eslint-disable-line no-param-reassign From 99fb8d7ab32fe529a40a990e88c7162fbb521a9d Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 12 Sep 2024 14:58:22 -0500 Subject: [PATCH 4/6] version bump --- CHANGELOG.md | 4 ++++ wp-curate.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a634cdec..fb36a09b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `WP Curate` will be documented in this file. +## 2.3.3 - 2024-09-12 + +- Restore maxNumberOfPosts attribute with a default filterable value of maxPosts. + ## 2.3.2 - 2024-09-09 - Bug Fix: Prevent block transforms from crashing the Query block. diff --git a/wp-curate.php b/wp-curate.php index 6aed2a5c..dfe046e0 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: 2.3.2 + * Version: 2.3.3 * Author: Alley Interactive * Author URI: https://github.com/alleyinteractive/wp-curate * Requires at least: 6.4 From 9a2a8a3bc440c760640c71543e2ae14d1f4eabfc Mon Sep 17 00:00:00 2001 From: Matthew Ell Date: Thu, 10 Oct 2024 15:15:32 -0600 Subject: [PATCH 5/6] Move maxNumberOfPosts into QueryControls --- blocks/query/block.json | 3 ++- components/QueryControls/index.tsx | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/blocks/query/block.json b/blocks/query/block.json index d258829c..19b22285 100644 --- a/blocks/query/block.json +++ b/blocks/query/block.json @@ -32,7 +32,8 @@ "type": "string" }, "maxNumberOfPosts": { - "type": "number" + "type": "number", + "default": 10 }, "minNumberOfPosts": { "default": 1, diff --git a/components/QueryControls/index.tsx b/components/QueryControls/index.tsx index 221e7ddf..dc30c148 100644 --- a/components/QueryControls/index.tsx +++ b/components/QueryControls/index.tsx @@ -32,6 +32,7 @@ type QueryControlsProps = { isPostDeduplicating: boolean; manualPosts: Array; maxPosts: number; + maxNumberOfPosts: number; minNumberOfPosts: number; numberOfPosts: number; offset: number; @@ -59,6 +60,7 @@ export default function QueryControls({ isPostDeduplicating, manualPosts, maxPosts, + maxNumberOfPosts: maxNumberOfPostsAttr, minNumberOfPosts, numberOfPosts, offset, @@ -84,6 +86,8 @@ export default function QueryControls({ }, ]; + const maxNumberOfPosts = !maxNumberOfPostsAttr || maxNumberOfPostsAttr > maxPosts ? maxPosts : maxNumberOfPostsAttr; // eslint-disable-line max-len + const setTerms = ((type: string, newTerms: Term[]) => { const cleanedTerms = newTerms.map((term) => ( { @@ -110,7 +114,7 @@ export default function QueryControls({ const setNumberOfPosts = (newValue?: number) => { setAttributes({ - numberOfPosts: newValue, + numberOfPosts: (newValue && newValue > maxNumberOfPosts) ? maxNumberOfPosts : newValue, posts: manualPosts.slice(0, newValue), }); }; @@ -132,14 +136,14 @@ export default function QueryControls({ title={__('Setup', 'wp-curate')} initialOpen > - {minNumberOfPosts !== undefined && minNumberOfPosts !== maxPosts ? ( + {minNumberOfPosts !== undefined && minNumberOfPosts !== maxNumberOfPosts ? ( ) : null} Date: Thu, 10 Oct 2024 15:20:56 -0600 Subject: [PATCH 6/6] Control maxNumberOfPosts via block attributes --- blocks/subquery/block.json | 6 +++++- blocks/subquery/edit.tsx | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/blocks/subquery/block.json b/blocks/subquery/block.json index 2fb3af2c..a0937451 100644 --- a/blocks/subquery/block.json +++ b/blocks/subquery/block.json @@ -29,6 +29,10 @@ ], "type": "string" }, + "maxNumberOfPosts": { + "type": "number", + "default": 10 + }, "minNumberOfPosts": { "default": 1, "type": "number" @@ -103,4 +107,4 @@ "type": "string" } } -} \ No newline at end of file +} diff --git a/blocks/subquery/edit.tsx b/blocks/subquery/edit.tsx index 5b758e9a..e36999af 100644 --- a/blocks/subquery/edit.tsx +++ b/blocks/subquery/edit.tsx @@ -52,6 +52,7 @@ export default function Edit({ attributes: { backfillPosts = [], deduplication = 'inherit', + maxNumberOfPosts = 10, minNumberOfPosts = 1, numberOfPosts = 5, offset = 0, @@ -258,6 +259,7 @@ export default function Edit({ isPostDeduplicating={isPostDeduplicating} manualPosts={manualPosts} maxPosts={maxPosts} + maxNumberOfPosts={maxNumberOfPosts} minNumberOfPosts={minNumberOfPosts} numberOfPosts={numberOfPosts} offset={offset}