Skip to content

Commit da6ca8b

Browse files
authored
Merge pull request #24 from vektor-inc/fix/custom-field-default-rule
[ Change version ] 0.4.2 [ Bug fix ] Fixed bug in conditional branchi…
2 parents 3bbebf9 + 4099bd1 commit da6ca8b

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

readme.txt

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ However, by nesting Dynamic If Blocks, various conditional branching can be hand
3535

3636
== Changelog ==
3737

38+
= 0.4.2 =
39+
* [ Bug fix ] Fixed bug in conditional branching based on custom field values
40+
3841
= 0.4.1 =
3942
* Update descriptions
4043

src/block.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"customFieldRule": {
2121
"type": "string",
22-
"default": ""
22+
"default": "valueExists"
2323
},
2424
"customFieldValue": {
2525
"type": "string",

src/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function vk_dynamic_if_block_render( $attributes, $content ) {
8282

8383
if ( get_the_ID() ) {
8484
$get_value = get_post_meta( get_the_ID(), $attributes['customFieldName'], true );
85-
if ( 'valueExists' === $attributes['customFieldRule'] ) {
85+
if ( 'valueExists' === $attributes['customFieldRule'] || empty( $attributes['customFieldRule'] ) ) {
8686
if ( $get_value || '0' === $get_value ) {
8787
$display_by_custom_field = true;
8888
} else {

tests/test-dynamic-if.php

+18
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,24 @@ public function test_vk_dynamic_if_block_render() {
593593
'content' => 'Custom Field value not match',
594594
'expected' => '',
595595
),
596+
array(
597+
'name' => 'Custom Field value not match',
598+
'go_to' => get_permalink( $test_posts['event_post_id'] ),
599+
'attribute' => array(
600+
'ifPageType' => 'none',
601+
'ifPostType' => 'none',
602+
'customFieldName' => 'price',
603+
'customFieldRule' => null,
604+
'customFieldValue' => '100',
605+
),
606+
'test_meta' => array(
607+
'post_id' => $test_posts['event_post_id'],
608+
'meta_key' => 'price',
609+
'meta_value' => '100',
610+
),
611+
'content' => 'customFieldRule not set',
612+
'expected' => 'customFieldRule not set',
613+
),
596614
);
597615

598616
foreach ( $tests as $test ) {

vk-dynamic-if-block.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* Description: A dynamic block displays its Inner Blocks based on specified conditions, such as whether the current page is the front page or a single post, the post type, or the value of a Custom Field.
66
* Author: Vektor,Inc.
77
* Author URI: https://vektor-inc.co.jp/en/
8-
* Version: 0.4.1
9-
* Stable tag: 0.4.1
8+
* Version: 0.4.2
9+
* Stable tag: 0.4.2
1010
* License: GPL-2.0-or-later
1111
* Text Domain: vk-dynamic-if-block
1212
*

0 commit comments

Comments
 (0)