Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/enqueues.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function () {
// Add inline script.
wp_add_inline_script(
'advanced-query-loop',
'aql.allowedControls = "' . implode( ',', Query_Params_Generator::get_allowed_controls() ) . '";'
'window.aql = window.aql || {}; window.aql.allowedControls = "' . implode( ',', Query_Params_Generator::get_allowed_controls() ) . '";'
);
}

Expand Down
24 changes: 22 additions & 2 deletions src/variations/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ const isAdvancedQueryLoop = ( props ) => {
return namespace && namespace === AQL;
};

/**
* Fallback list of all control identifiers, used when window.aql.allowedControls
* is not available (e.g. due to script loading order issues from caching plugins).
*/
const ALL_CONTROLS = [
'additional_post_types',
'taxonomy_query_builder',
'post_meta_query',
'post_order',
'exclude_current_post',
'include_posts',
'child_items_only',
'date_query_dynamic_range',
'date_query_relationship',
'pagination',
'exclude_posts',
'enable_caching',
];

/**
* Custom controls
*
Expand All @@ -71,9 +90,10 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => {

// If the is the correct variation, add the custom controls.
if ( isAdvancedQueryLoop( props ) ) {
const { allowedControls } = window?.aql;
const { allowedControls } = window?.aql ?? {};
const { attributes } = props;
const allowedControlsArray = allowedControls.split( ',' );
const allowedControlsArray =
allowedControls?.split( ',' ) ?? ALL_CONTROLS;
const propsWithControls = {
...props,
allowedControls: allowedControlsArray,
Expand Down
Loading