From 6a0e7bf0dac3ba1d87f3541e5c52a745353a29e9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Sep 2026 20:38:36 +0000 Subject: [PATCH] chore: sync funkycommerce-headless from monorepo Source: coded-letter/coded-letter-monorepo@4468ad3ce07b72c1b264ebd3042e4a91779e7c0b --- .monorepo-source.json | 2 +- build/archive-settings.test.mjs | 72 +++++++++++++++++++++++++ build/archive-settings.test.php | 96 +++++++++++++++++++++++++++++++++ functions.php | 5 +- inc/archive-settings.php | 77 ++++++++++++++++++++++++++ inc/control-center-schema.php | 2 +- inc/native-shortcodes.php | 10 ++-- inc/native-woocommerce.php | 11 ---- package-lock.json | 4 +- package.json | 2 +- readme.txt | 9 +++- style.css | 2 +- 12 files changed, 269 insertions(+), 23 deletions(-) create mode 100644 build/archive-settings.test.mjs create mode 100644 build/archive-settings.test.php create mode 100644 inc/archive-settings.php diff --git a/.monorepo-source.json b/.monorepo-source.json index 6a243d9..188e56e 100644 --- a/.monorepo-source.json +++ b/.monorepo-source.json @@ -1,7 +1,7 @@ { "productId": "funkycommerce-headless", "repository": "coded-letter/superfunky-theme", - "source": "coded-letter/coded-letter-monorepo@7d65229487a558b1e2d5a1316ced1022f462fead", + "source": "coded-letter/coded-letter-monorepo@4468ad3ce07b72c1b264ebd3042e4a91779e7c0b", "sourcePath": "workspace/backend/wordpress/themes/free/funkycommerce-headless", "installSlug": "funkycommerce-headless", "kind": "theme", diff --git a/build/archive-settings.test.mjs b/build/archive-settings.test.mjs new file mode 100644 index 0000000..058fa5b --- /dev/null +++ b/build/archive-settings.test.mjs @@ -0,0 +1,72 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { spawnSync } from "node:child_process"; +import { fileURLToPath } from "node:url"; +import test from "node:test"; +import { Engine } from "php-parser"; + +const source = (name) => readFileSync(new URL(`../${name}`, import.meta.url), "utf8"); +const settings = source("inc/archive-settings.php"); +const functions = source("functions.php"); +const nativeGrid = source("inc/native-shortcodes.php"); +const parser = new Engine({ parser: { suppressErrors: false } }); + +test("native PHP resolves settings, filter precedence, GraphQL, and option invalidation", (context) => { + const result = spawnSync(process.env.PHP_BINARY || "php", [ + fileURLToPath(new URL("archive-settings.test.php", import.meta.url)), + ], { encoding: "utf8" }); + if (result.error?.code === "ENOENT" && !process.env.PHP_BINARY) { + context.skip("PHP is unavailable; set PHP_BINARY to run native behavior assertions."); + return; + } + assert.ifError(result.error); + assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`); + assert.match(result.stdout, /Archive settings behavior passed/); +}); + +test("archive settings parse and load independently of native/headless rendering mode", () => { + assert.doesNotThrow(() => parser.parseCode(settings)); + assert.match(functions, /require_once .*\/inc\/archive-settings\.php/); + assert.doesNotMatch(settings, /funkycommerce_is_headless_mode/); + assert.doesNotMatch(source("inc/native-woocommerce.php"), /function funkycommerce_native_products_per_page/); +}); + +test("GraphQL exposes independent WordPress and effective WooCommerce sizes including unlimited", () => { + assert.match(settings, /get_option\( 'posts_per_page', 10 \)/); + assert.match(settings, /apply_filters\( 'loop_shop_per_page', wc_get_default_products_per_row\(\) \* wc_get_default_product_rows_per_page\(\) \)/); + assert.match(settings, /-1 === \$count \|\| \$count > 0/); + assert.match(settings, /'funkycommerceArchiveSettings'/); + assert.match(settings, /'resolve' => 'funkycommerce_archive_settings'/); + for (const field of ["postsPerPage", "productsPerPage"]) { + assert.match(settings, new RegExp(`'${field}'\\s*=> array\\( 'type' => array\\( 'non_null' => 'Int' \\)`)); + } +}); + +test("saved positive overrides remain shared while an absent override inherits WooCommerce", () => { + assert.match(settings, /\$settings\['products_per_page'\] \?\? 0/); + assert.match(settings, /add_filter\( 'loop_shop_per_page', 'funkycommerce_native_products_per_page', 20 \)/); + const field = source("inc/control-center-schema.php").split("'products_per_page' =>")[1].split("\n")[0]; + assert.match(field, /'default' => '0'/); + assert.match(field, /'min' => '0'/); +}); + +test("reading and WooCommerce option changes invalidate prerender settings and schedule rebuilding", () => { + for (const option of ["posts_per_page", "woocommerce_catalog_columns", "woocommerce_catalog_rows"]) { + assert.ok(settings.includes(`'${option}'`)); + } + for (const hook of ["updated_option", "added_option", "deleted_option"]) { + assert.ok(settings.includes(`add_action( '${hook}', 'funkycommerce_collect_archive_setting_change', 30 )`)); + } + assert.match(settings, /funkycommerce_schedule_content_build\(\)/); + assert.match(settings, /array\( 'config:storefront' \)/); + assert.match(source("inc/artifact-invalidation.php"), /function funkycommerce_collect_control_center_change[\s\S]*funkycommerce_schedule_content_build\(\)/); +}); + +test("native and headless grid markers inherit settings unless the editor specifies a positive size", () => { + const grid = functions.split("'grid' => array(")[1].split("'offset'")[0]; + assert.match(grid, /'page_size'\s*=> array\( 'default' => 0, 'type' => 'integer', 'min' => 0, 'max' => 48 \)/); + assert.match(nativeGrid, /\$a\['page_size'\] > 0 \? \(int\) \$a\['page_size'\] : \$settings\[ 'product' === \$type \? 'productsPerPage' : 'postsPerPage' \]/); + assert.match(nativeGrid, /'offset'\s*=> -1 === \$per_page \? 0/); + assert.match(nativeGrid, /array_slice\( \$result\['ids'\], \$base_offset \)/); + assert.match(nativeGrid, /-1 !== \$per_page \? \(int\) ceil/); +}); diff --git a/build/archive-settings.test.php b/build/archive-settings.test.php new file mode 100644 index 0000000..1e0492e --- /dev/null +++ b/build/archive-settings.test.php @@ -0,0 +1,96 @@ + 10, 'productsPerPage' => 12 ), funkycommerce_archive_settings(), 'No-Woo defaults' ); +$options['posts_per_page'] = '7'; +enable_woocommerce_fixture(); +$options['woocommerce_catalog_columns'] = 5; +$options['woocommerce_catalog_rows'] = 3; +expect_same( array( 'postsPerPage' => 7, 'productsPerPage' => 15 ), funkycommerce_archive_settings(), 'Native settings are independent' ); + +$options['funkycommerce_control_center'] = array( 'products_per_page' => '0' ); +expect_same( 15, funkycommerce_archive_settings()['productsPerPage'], 'Zero inherits Woo' ); +$options['funkycommerce_control_center']['products_per_page'] = '9'; +expect_same( 9, funkycommerce_archive_settings()['productsPerPage'], 'Saved overrides remain effective' ); +expect_same( 9, apply_filters( 'loop_shop_per_page', 15 ), 'Native and headless loops agree' ); +add_filter( 'loop_shop_per_page', static function ( $count ) { return $count * 2; }, 30 ); +expect_same( 18, funkycommerce_archive_settings()['productsPerPage'], 'Later Woo filters still apply' ); +add_filter( 'loop_shop_per_page', static function () { return -1; }, 40 ); +$options['posts_per_page'] = -1; +expect_same( array( 'postsPerPage' => -1, 'productsPerPage' => -1 ), funkycommerce_archive_settings(), 'Unlimited native archives' ); +expect_same( 250, funkycommerce_archive_page_size( '250', 10 ), 'Visual size is not capped to transport batch size' ); +expect_same( 10, funkycommerce_archive_page_size( 'invalid', 10 ), 'Invalid settings log and use the documented default' ); + +foreach ( $hooks['graphql_register_types'][10] as $callback ) { + $callback(); +} +$field = $GLOBALS['graphql_fields']['RootQuery']['funkycommerceArchiveSettings']; +expect_same( array( 'non_null' => 'FunkyCommerceArchiveSettings' ), $field['type'], 'GraphQL field contract' ); +expect_same( funkycommerce_archive_settings(), call_user_func( $field['resolve'] ), 'GraphQL executes the shared resolver' ); + +foreach ( array( 'updated_option', 'added_option', 'deleted_option' ) as $hook ) { + foreach ( $hooks[ $hook ][30] as $callback ) { + $callback( 'unrelated_option' ); + foreach ( array( 'posts_per_page', 'woocommerce_catalog_columns', 'woocommerce_catalog_rows' ) as $option ) { + $callback( $option ); + } + } +} +expect_same( 9, $builds, 'Only native archive option changes schedule builds' ); +expect_same( 9, count( $invalidations ), 'Each relevant change invalidates hydration' ); +foreach ( $invalidations as $invalidation ) { + expect_same( array( array( 'config:storefront' ), 'archive_settings_changed' ), $invalidation, 'Settings dependency is invalidated' ); +} +echo "Archive settings behavior passed\n"; diff --git a/functions.php b/functions.php index 1a1b0fc..2fc4bf7 100644 --- a/functions.php +++ b/functions.php @@ -9,7 +9,7 @@ exit; } -define( 'FUNKYCOMMERCE_HEADLESS_VERSION', '1.2.38' ); +define( 'FUNKYCOMMERCE_HEADLESS_VERSION', '1.2.39' ); /** * Whether Superfunky Pro is active and licensed. @@ -171,6 +171,7 @@ function funkycommerce_frontend_url( $path = '' ) { require_once get_template_directory() . '/inc/admin-view-links.php'; require_once get_template_directory() . '/inc/frontend-theme.php'; require_once get_template_directory() . '/inc/custom-404.php'; +require_once get_template_directory() . '/inc/archive-settings.php'; require_once get_template_directory() . '/inc/native-woocommerce.php'; require_once get_template_directory() . '/inc/native-shortcodes.php'; require_once get_template_directory() . '/inc/build-webhooks.php'; @@ -533,7 +534,7 @@ function funkycommerce_content_shortcode_schemas() { 'card_variant' => array( 'default' => 'default', 'enum' => array( 'default', 'compact', 'editorial', 'minimal', 'gallery', 'simple', 'variation', 'expandable' ) ), 'layout' => array( 'default' => 'standard', 'enum' => array( 'standard', 'compact', 'editorial', 'masonry' ) ), 'columns' => array( 'default' => 3, 'type' => 'integer', 'min' => 1, 'max' => 6 ), - 'page_size' => array( 'default' => 12, 'type' => 'integer', 'min' => 1, 'max' => 48 ), + 'page_size' => array( 'default' => 0, 'type' => 'integer', 'min' => 0, 'max' => 48 ), 'offset' => funkycommerce_collection_shortcode_offset_definition(), 'paginated' => array( 'default' => 'true', 'type' => 'boolean' ), 'include' => array( 'default' => '' ), diff --git a/inc/archive-settings.php b/inc/archive-settings.php new file mode 100644 index 0000000..0117ea4 --- /dev/null +++ b/inc/archive-settings.php @@ -0,0 +1,77 @@ + 0 ) ) { + return $count; + } + error_log( 'FunkyCommerce: invalid native archive page size; using the default.' ); + return $fallback; +} + +function funkycommerce_native_products_per_page( $count ) { + $settings = (array) get_option( 'funkycommerce_control_center', array() ); + $value = $settings['products_per_page'] ?? 0; + return 0 === $value || '0' === $value + ? $count + : funkycommerce_archive_page_size( $value, $count ); +} +add_filter( 'loop_shop_per_page', 'funkycommerce_native_products_per_page', 20 ); + +function funkycommerce_archive_settings() { + $products_per_page = 12; + if ( function_exists( 'wc_get_default_products_per_row' ) && function_exists( 'wc_get_default_product_rows_per_page' ) ) { + $products_per_page = funkycommerce_archive_page_size( + apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ), + 12 + ); + } + return array( + 'postsPerPage' => funkycommerce_archive_page_size( get_option( 'posts_per_page', 10 ), 10 ), + 'productsPerPage' => $products_per_page, + ); +} + +function funkycommerce_register_archive_settings_graphql() { + register_graphql_object_type( + 'FunkyCommerceArchiveSettings', + array( + 'fields' => array( + 'postsPerPage' => array( 'type' => array( 'non_null' => 'Int' ) ), + 'productsPerPage' => array( 'type' => array( 'non_null' => 'Int' ) ), + ), + ) + ); + register_graphql_field( + 'RootQuery', + 'funkycommerceArchiveSettings', + array( + 'type' => array( 'non_null' => 'FunkyCommerceArchiveSettings' ), + 'resolve' => 'funkycommerce_archive_settings', + ) + ); +} +add_action( 'graphql_register_types', 'funkycommerce_register_archive_settings_graphql' ); + +function funkycommerce_collect_archive_setting_change( $option ) { + if ( ! in_array( $option, array( 'posts_per_page', 'woocommerce_catalog_columns', 'woocommerce_catalog_rows' ), true ) ) { + return; + } + funkycommerce_schedule_content_build(); + funkycommerce_collect_artifact_changes( + array( 'config:storefront' ), + 'archive_settings_changed' + ); +} +add_action( 'updated_option', 'funkycommerce_collect_archive_setting_change', 30 ); +add_action( 'added_option', 'funkycommerce_collect_archive_setting_change', 30 ); +add_action( 'deleted_option', 'funkycommerce_collect_archive_setting_change', 30 ); diff --git a/inc/control-center-schema.php b/inc/control-center-schema.php index d32b3dd..b21fbf8 100644 --- a/inc/control-center-schema.php +++ b/inc/control-center-schema.php @@ -563,7 +563,7 @@ function funkycommerce_control_center_sections() { 'currency_rate_mode' => array( 'label' => __( 'Currency rate mode', 'funkycommerce-headless' ), 'type' => 'select', 'tier' => 'pro', 'default' => 'automatic', 'options' => array( 'automatic' => __( 'Automatic public rates', 'funkycommerce-headless' ), 'manual' => __( 'Manual rates', 'funkycommerce-headless' ) ) ), 'currency_manual_rates' => array( 'label' => __( 'Manual currency rates', 'funkycommerce-headless' ), 'type' => 'json', 'tier' => 'pro', 'default' => '{}', 'description' => __( 'JSON object keyed by ISO currency code, for example {"USD":1.08}.', 'funkycommerce-headless' ) ), 'order_prefix' => array( 'label' => __( 'Order number prefix', 'funkycommerce-headless' ), 'type' => 'text', 'tier' => 'pro', 'default' => '#' ), - 'products_per_page' => array( 'label' => __( 'Products per page', 'funkycommerce-headless' ), 'type' => 'number', 'tier' => 'free', 'default' => '12', 'min' => '1', 'max' => '100', 'step' => '1' ), + 'products_per_page' => array( 'label' => __( 'Products per page override', 'funkycommerce-headless' ), 'type' => 'number', 'tier' => 'free', 'default' => '0', 'min' => '0', 'max' => '100', 'step' => '1', 'description' => __( '0 follows native WooCommerce products per row and rows per page. A positive value overrides both native and headless product archives.', 'funkycommerce-headless' ) ), 'stock_badge_enabled' => array( 'label' => __( 'Stock-status badges', 'funkycommerce-headless' ), 'type' => 'toggle', 'tier' => 'free', 'default' => 'yes' ), 'reviews_enabled' => array( 'label' => __( 'Product reviews and ratings', 'funkycommerce-headless' ), 'type' => 'toggle', 'tier' => 'free', 'default' => 'yes' ), 'products_no_price_behavior' => array( 'label' => __( 'Products without a price', 'funkycommerce-headless' ), 'type' => 'select', 'tier' => 'free', 'default' => 'free', 'options' => array( 'free' => __( 'Treat as free', 'funkycommerce-headless' ), 'inquiry' => __( 'Show an inquiry form', 'funkycommerce-headless' ) ) ), diff --git a/inc/native-shortcodes.php b/inc/native-shortcodes.php index dc3f953..cf81518 100644 --- a/inc/native-shortcodes.php +++ b/inc/native-shortcodes.php @@ -1264,7 +1264,8 @@ function funkycommerce_native_render_grid( $atts ) { $type = in_array( $a['type'], array( 'product', 'post', 'community-article' ), true ) ? $a['type'] : 'product'; $page = isset( $_GET['fcp'] ) ? max( 1, absint( wp_unslash( $_GET['fcp'] ) ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $per_page = max( 1, (int) $a['page_size'] ); + $settings = funkycommerce_archive_settings(); + $per_page = $a['page_size'] > 0 ? (int) $a['page_size'] : $settings[ 'product' === $type ? 'productsPerPage' : 'postsPerPage' ]; $base_offset = max( 0, (int) $a['offset'] ); // WP_Query treats any explicitly-set `offset` (including 0) as overriding @@ -1277,10 +1278,13 @@ function funkycommerce_native_render_grid( $atts ) { $filters['limit'] = $per_page; $overrides = array( 'posts_per_page' => $per_page, - 'offset' => $base_offset + ( ( $page - 1 ) * $per_page ), + 'offset' => -1 === $per_page ? 0 : $base_offset + ( ( $page - 1 ) * $per_page ), ); $result = funkycommerce_native_query_by_type( $type, $filters, $overrides ); + if ( -1 === $per_page && $base_offset > 0 ) { + $result['ids'] = array_slice( $result['ids'], $base_offset ); + } $cards = ''; foreach ( $result['ids'] as $id ) { $cards .= funkycommerce_native_card_for_type( $type, $id, $a['card_variant'] ); @@ -1291,7 +1295,7 @@ function funkycommerce_native_render_grid( $atts ) { } $remaining = max( 0, $result['found'] - $base_offset ); - $max_pages = $remaining > 0 ? (int) ceil( $remaining / $per_page ) : 0; + $max_pages = $remaining > 0 && -1 !== $per_page ? (int) ceil( $remaining / $per_page ) : 0; $pagination = ''; if ( ! empty( $a['paginated'] ) && $max_pages > 1 ) { diff --git a/inc/native-woocommerce.php b/inc/native-woocommerce.php index 263a70d..395f24d 100644 --- a/inc/native-woocommerce.php +++ b/inc/native-woocommerce.php @@ -90,17 +90,6 @@ function funkycommerce_native_woocommerce_body_classes( $classes ) { } add_filter( 'body_class', 'funkycommerce_native_woocommerce_body_classes' ); -/** - * Reuse the catalogue "Products per page" setting across the shop archive and - * every product taxonomy archive. - */ -function funkycommerce_native_products_per_page( $count ) { - $settings = funkycommerce_native_woocommerce_settings(); - $value = absint( $settings['products_per_page'] ?? 0 ); - return $value > 0 ? $value : $count; -} -add_filter( 'loop_shop_per_page', 'funkycommerce_native_products_per_page', 20 ); - /** * Whether product reviews and ratings are enabled from the Control Center. */ diff --git a/package-lock.json b/package-lock.json index f618848..f26ad0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "funkycommerce-headless-theme", - "version": "1.2.38", + "version": "1.2.39", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "funkycommerce-headless-theme", - "version": "1.2.38", + "version": "1.2.39", "devDependencies": { "autoprefixer": "^10.4.20", "esbuild": "^0.28.2", diff --git a/package.json b/package.json index 9bd6e8a..d91e2aa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "funkycommerce-headless-theme", "private": true, - "version": "1.2.38", + "version": "1.2.39", "description": "Tailwind/build tooling for the FunkyCommerce Headless WordPress theme's native frontend assets (block templates, template parts, loader, and Spotify slot).", "scripts": { "build:css": "tailwindcss -i ./assets/css/theme-source.css -o ./assets/dist/theme.css --minify", diff --git a/readme.txt b/readme.txt index cb971f7..d99dd77 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: headless, woocommerce, wpgraphql, full-site-editing Requires at least: 6.7 Tested up to: 6.8 Requires PHP: 7.4 -Stable tag: 1.2.38 +Stable tag: 1.2.39 License: GPL-2.0-or-later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -15,6 +15,13 @@ Control Center, the theme also ships a complete native WordPress rendering path "Native frontend theme" below) with accessible header/footer/navigation templates and core front/home/singular/archive/search/404 routes styled to match the storefront. +== 1.2.39 highlights == + +* Shares native WordPress posts-per-page and effective WooCommerce products-per-page settings with headless archive grids and pagination. +* Makes grid shortcodes inherit those settings by default; explicit positive page_size values remain editorial overrides. +* Defaults Products per page override to 0 (inherit WooCommerce); existing saved positive overrides remain effective in both rendering modes. +* Schedules storefront rebuilding and settings invalidation when native pagination settings change. + == 1.2.38 highlights == * Restores configured, debounced storefront builds for CMS changes in shadow and artifact modes so new Tailwind utilities compile. diff --git a/style.css b/style.css index 0416954..ec3c50d 100644 --- a/style.css +++ b/style.css @@ -7,7 +7,7 @@ Description: A minimal, content-first block theme for polished WordPress preview Requires at least: 6.7 Tested up to: 6.8 Requires PHP: 7.4 -Version: 1.2.38 +Version: 1.2.39 Update URI: https://github.com/coded-letter/superfunky-theme License: GPL-2.0-or-later License URI: https://www.gnu.org/licenses/gpl-2.0.html