From ef78481ea68a01ee6391e2482fa83bcb22f82b2d Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 14 Aug 2024 13:14:34 -0400 Subject: [PATCH 1/4] Add some utilities to allow checking for GB and core versions. --- composer.json | 3 ++- includes/utilities.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 includes/utilities.php diff --git a/composer.json b/composer.json index d23833f..9be7448 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ }, "files": [ "includes/enqueues.php", - "includes/query-loop.php" + "includes/query-loop.php", + "includes/utilities.php" ] }, "require-dev": { diff --git a/includes/utilities.php b/includes/utilities.php new file mode 100644 index 0000000..a046d72 --- /dev/null +++ b/includes/utilities.php @@ -0,0 +1,36 @@ +=' ); + } + return false; +} + +/** + * Helper to determine is the current WP install is at or higher than a given version. + * + * @param string $version The version to check for. + + * @return boolean. + */ +function is_core_version_or_higher( string $version ) { + $core = get_bloginfo( 'version' ); + return version_compare( $core, $version, '>=' ); +} + From 331ecda646094a55951013ff5e5dd942b7919edd Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 14 Aug 2024 13:15:13 -0400 Subject: [PATCH 2/4] Create and expose a new internal slot so we can re-insert the legacy controls. --- src/slots/aql-legacy-controls.js | 25 +++++++++++++++++++++++++ src/variations/controls.js | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/slots/aql-legacy-controls.js diff --git a/src/slots/aql-legacy-controls.js b/src/slots/aql-legacy-controls.js new file mode 100644 index 0000000..2ca7d13 --- /dev/null +++ b/src/slots/aql-legacy-controls.js @@ -0,0 +1,25 @@ +/** + * WordPress dependencies + */ +import { createSlotFill } from '@wordpress/components'; + +/** + * Create our Slot and Fill components + */ +const { Fill, Slot } = createSlotFill( 'AQLLegacyControls' ); + +/** + * This slot is not exposed and is used to try to maintain the same UI + */ + +const AQLLegacyControls = ( { children } ) => { children }; + +AQLLegacyControls.Slot = ( { fillProps } ) => ( + + { ( fills ) => { + return fills.length ? fills : null; + } } + +); + +export default AQLLegacyControls; diff --git a/src/variations/controls.js b/src/variations/controls.js index 9a604d5..e55a69c 100644 --- a/src/variations/controls.js +++ b/src/variations/controls.js @@ -12,8 +12,7 @@ import { createBlock } from '@wordpress/blocks'; import { AQL } from '.'; import AQLControls from '../slots/aql-controls'; import AQLControlsInheritedQuery from '../slots/aql-controls-inherited-query'; -import { PostCountControls } from '../components/post-count-controls'; -import { PostOffsetControls } from '../components/post-offset-controls'; +import AQLLegacyControls from '../slots/aql-legacy-controls'; import { PostMetaQueryControls } from '../components/post-meta-query-controls'; import { PostDateQueryControls } from '../components/post-date-query-controls'; import { MultiplePostSelect } from '../components/multiple-post-select'; @@ -56,9 +55,10 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => { 'advanced-query-loop' ) } > + - - From 24f689ba440635f7c471b7a79d27c4cc7b3c81bb Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 14 Aug 2024 13:15:37 -0400 Subject: [PATCH 3/4] Create new file and entry point for the GB 19 changes. --- src/legacy-controls/pre-gb-19.js | 28 ++++++++++++++++++++++++++++ webpack.config.js | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/legacy-controls/pre-gb-19.js diff --git a/src/legacy-controls/pre-gb-19.js b/src/legacy-controls/pre-gb-19.js new file mode 100644 index 0000000..51d2280 --- /dev/null +++ b/src/legacy-controls/pre-gb-19.js @@ -0,0 +1,28 @@ +/** + * WordPress dependencies + */ +import { registerPlugin } from '@wordpress/plugins'; + +/** + * Internal dependencies + */ +import AQLLegacyControls from '../slots/aql-legacy-controls'; +import { PostCountControls } from '../components/post-count-controls'; +import { PostOffsetControls } from '../components/post-offset-controls'; + +registerPlugin( 'aql-pre-gb-19-controls', { + render: () => { + return ( + <> + + { ( props ) => ( + <> + + + + ) } + + + ); + }, +} ); diff --git a/webpack.config.js b/webpack.config.js index f805079..c3dcf7b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,6 +10,7 @@ module.exports = { entry: { ...getWebpackEntryPoints(), variations: './src/variations/index.js', + 'legacy-pre-gb-19': './src/legacy-controls/pre-gb-19.js', }, output: { ...defaultConfig.output, From 4d4ccdd97806153fe3d70ae386167ac4bd72c9bd Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 14 Aug 2024 13:15:52 -0400 Subject: [PATCH 4/4] Add a check to see if we need to add the legacy controls. --- includes/enqueues.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/includes/enqueues.php b/includes/enqueues.php index 443e14f..c5ebbcf 100644 --- a/includes/enqueues.php +++ b/includes/enqueues.php @@ -7,6 +7,9 @@ namespace AdvancedQueryLoop; +use function AdvancedQueryLoop\Utils\{ is_gutenberg_plugin_version_or_higher,is_core_version_or_higher }; + + // Bail on unit tests. if ( ! function_exists( 'add_action' ) ) { return; @@ -33,5 +36,23 @@ function () { // Allow for translation. wp_set_script_translations( 'advanced-query-loop', 'advanced-query-loop' ); } + + // Per Page, Offset, and Max count controls where merged into GB 19. + if ( ! is_gutenberg_plugin_version_or_higher( '19' ) && ! is_core_version_or_higher( '6.7' ) ) { + // Enqueue the legacy controls. + $pre_gb_19_assets_file = BUILD_DIR_PATH . 'legacy-pre-gb-19.asset.php'; + + if ( file_exists( $pre_gb_19_assets_file ) ) { + $pre_gb_19_assets = include $pre_gb_19_assets_file; + + \wp_enqueue_script( + 'advanced-query-loop-legacy-pre-gb-19', + BUILD_DIR_URL . 'legacy-pre-gb-19.js', + array_merge( array( 'advanced-query-loop' ), $pre_gb_19_assets['dependencies'] ), + $pre_gb_19_assets['version'], + true + ); + } + } } );