Skip to content

Commit

Permalink
Merge pull request #81 from ryanwelcher/feature/deprecate-controls-fo…
Browse files Browse the repository at this point in the history
…r-gb-1

Deprecate controls that were merged into Gutenberg 19
  • Loading branch information
ryanwelcher authored Oct 9, 2024
2 parents a089b26 + 06b2aa9 commit 7bafb48
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"files": [
"includes/enqueues.php",
"includes/query-loop.php"
"includes/query-loop.php",
"includes/utilities.php"
]
},
"require-dev": {
Expand Down
21 changes: 21 additions & 0 deletions includes/enqueues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
);
}
}
}
);
36 changes: 36 additions & 0 deletions includes/utilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Handles enqueueing of assets for the plugin.
*
* @package AdvancedQueryLoop/Utils
*/

namespace AdvancedQueryLoop\Utils;

/**
* Helper to determine if the Gutenberg plugin is installed and if so, if it is at or higher a given version.
*
* @param string $version The version to check for.
*
* @return boolean.
*/
function is_gutenberg_plugin_version_or_higher( string $version ) {
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && defined( 'GUTENBERG_VERSION' ) ) {
// This means the plugin is installed
return version_compare( GUTENBERG_VERSION, $version, '>=' );
}
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, '>=' );
}

28 changes: 28 additions & 0 deletions src/legacy-controls/pre-gb-19.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<AQLLegacyControls>
{ ( props ) => (
<>
<PostCountControls { ...props } />
<PostOffsetControls { ...props } />
</>
) }
</AQLLegacyControls>
</>
);
},
} );
25 changes: 25 additions & 0 deletions src/slots/aql-legacy-controls.js
Original file line number Diff line number Diff line change
@@ -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 } ) => <Fill>{ children }</Fill>;

AQLLegacyControls.Slot = ( { fillProps } ) => (
<Slot fillProps={ fillProps }>
{ ( fills ) => {
return fills.length ? fills : null;
} }
</Slot>
);

export default AQLLegacyControls;
8 changes: 4 additions & 4 deletions src/variations/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,10 +57,11 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => {
'advanced-query-loop'
) }
>
<AQLLegacyControls.Slot
fillProps={ { ...props } }
/>
<PaginationToggle { ...props } />
<MultiplePostSelect { ...props } />
<PostCountControls { ...props } />
<PostOffsetControls { ...props } />
<PostOrderControls { ...props } />
<PostExcludeControls { ...props } />
<ExcludeTaxonomies { ...props } />
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7bafb48

Please sign in to comment.