Skip to content

Commit

Permalink
Merge pull request #74 from ndiego/fix/relative-hierarcy-rule-mutli-s…
Browse files Browse the repository at this point in the history
…elect

Fix multi-select bug in the Relative Hierarchy rule.
  • Loading branch information
ndiego authored Jul 14, 2023
2 parents 1217991 + b842f6e commit ae00ad6
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion block-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Block Visibility
* Plugin URI: https://www.blockvisibilitywp.com/
* Description: Provides visibility controls and scheduling functionality to all WordPress blocks.
* Version: 3.0.3
* Version: 3.0.4
* Requires at least: 6.0
* Requires PHP: 5.6
* Author: Nick Diego
Expand Down
2 changes: 1 addition & 1 deletion build/block-visibility-editor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-notices', 'wp-plugins', 'wp-primitives'), 'version' => 'cac7b5296df49b1e812c');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-notices', 'wp-plugins', 'wp-primitives'), 'version' => '98babb0bfe71941655a4');
30 changes: 15 additions & 15 deletions build/block-visibility-editor.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion includes/frontend/visibility-tests/location.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ function run_location_relative_hierarchy_test( $rule ) {
// Assume error and try to disprove.
$test_result = 'error';

$relative_id = $rule['value'];
// Account for a bug in v3 that allowed multiple values to be stored.
$relative_id = is_array( $rule['value'] ) ? $rule['value'][0] : $rule['value'];
$hierarchy = $rule['operator'];

$post_id = get_the_ID();
Expand Down
4 changes: 2 additions & 2 deletions languages/block-visibility.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the GPLv2.
msgid ""
msgstr ""
"Project-Id-Version: Block Visibility 3.0.3\n"
"Project-Id-Version: Block Visibility 3.0.4\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/block-visibility\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-06-04T16:39:57+00:00\n"
"POT-Creation-Date: 2023-07-14T11:42:12+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"
"X-Domain: block-visibility\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "block-visibility",
"version": "3.0.3",
"version": "3.0.4",
"description": "Provides visibility controls and scheduling functionality to all WordPress blocks.",
"author": "Nick Diego",
"license": "GPL-2.0-or-later",
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ The **one exception** to this is the Screen Size block controls. Visibility by s

== Changelog ===

= 3.0.4 - 2023-07-14 =

**Fixed**

* [Location] Fixed bug that prevented the Relative Hierarchy rule from working. The value field was set to multi-select when it should be a single selection.

= 3.0.3 - 2023-06-04 =

**Changed**
Expand Down
12 changes: 9 additions & 3 deletions src/components/rule-sets/async-rule-fields/posts-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default function PostsSelect( props ) {
postType,
triggerReset,
value,
valueType,
isMulti,
} = props;
const [ selectedValues, setSelectedValues ] = useState( false );
const [ searchValue, setSearchValue ] = useState( false );
Expand Down Expand Up @@ -106,7 +108,7 @@ export default function PostsSelect( props ) {
// selected values. Otherwise return an empty array.
if ( value.length !== 0 && ! selectedValues ) {
const selectedQuery = {
include: value.join( ',' ),
include: Array.isArray( value ) ? value.join( ',' ) : value,
per_page: -1,
status: 'publish,draft,private,pending',
_fields: 'id,title,status',
Expand Down Expand Up @@ -158,10 +160,14 @@ export default function PostsSelect( props ) {
}

const handleChange = ( values ) => {
// Need for value handling.
const valueHandling =
valueType === 'postSelect' ? 'select' : 'multiSelect';

setSelectedValues( values );
handleRuleChange(
values,
'multiSelect', // Need for value handling.
valueHandling,
fieldType,
fieldName,
triggerReset
Expand Down Expand Up @@ -205,7 +211,7 @@ export default function PostsSelect( props ) {
noOptionsMessage={ noOptionsMessage }
placeholder={ placeholder }
isLoading={ loadingAvailablePosts || loadingSavedPosts }
isMulti
isMulti={ isMulti }
/>
);
}
4 changes: 3 additions & 1 deletion src/components/rule-sets/rule-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default function RuleField( props ) {
{ ...props }
/>
);
} else if ( valueType === 'postsSelect' ) {
} else if ( valueType === 'postsSelect' || valueType === 'postSelect' ) {
let postType;

// A defined variant will take precedent.
Expand All @@ -208,6 +208,8 @@ export default function RuleField( props ) {
postType={ postType }
className={ className }
value={ value }
valueType={ valueType }
isMulti={ valueType === 'postsSelect' }
{ ...props }
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/controls/location/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export function GetAllFields() {
dependencyType: 'subField',
dependencyValues: postTypesHierarchicalList,
valueTypes: [
{ value: 'default', valueType: 'postsSelect' },
{ value: 'default', valueType: 'postSelect' },
],
},
],
Expand Down

0 comments on commit ae00ad6

Please sign in to comment.