Skip to content
Merged
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
73 changes: 41 additions & 32 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,52 +959,61 @@ function ppom_get_editing_tools( $editing_tools ) {
**/
function ppom_has_posted_field_value( $posted_fields, $field ) {

$has_value = false;

$data_name = sanitize_key( $field['data_name'] );
$type = $field['type'];

$matching_keys = array();
if ( ! empty( $posted_fields ) ) {
foreach ( $posted_fields as $field_key => $value ) {
$field_key = explode( '__clone_', $field_key );
$key_parts = explode( '__clone_', $field_key );

if ( in_array( $data_name, $field_key, true ) ) {
if ( in_array( $data_name, $key_parts, true ) ) {
$matching_keys[ $field_key ] = $value;
}
}
}

switch ( $type ) {
if ( empty( $matching_keys ) ) {
return apply_filters( 'ppom_has_posted_field_value', false, $posted_fields, $field );
}

case 'quantities':
$quantities_field = $value;
$quantity = 0;
foreach ( $quantities_field as $option => $qty ) {
$quantity += intval( $qty );
}
// Every instance (the original field AND every clone) must have a value.
$has_value = true;
foreach ( $matching_keys as $instance_value ) {

if ( $quantity > 0 ) {
$has_value = true;
}
$instance_has_value = false;

break;

case 'fonts':
if ( isset( $value['font'] ) && $value['font'] != '' ) {
$has_value = true;
}
switch ( $type ) {

break;
case 'quantities':
$quantity = 0;
foreach ( (array) $instance_value as $qty ) {
$quantity += intval( $qty );
}
if ( $quantity > 0 ) {
$instance_has_value = true;
}
break;

default:
if ( $value != '' ) {
$has_value = true;
}
break;
case 'fonts':
if ( isset( $instance_value['font'] ) && '' !== $instance_value['font'] ) {
$instance_has_value = true;
}
break;

default:
if ( is_array( $instance_value ) ) {
$instance_has_value = ! empty( $instance_value );
} elseif ( '' !== trim( (string) $instance_value ) ) {
$instance_has_value = true;
}
break;

}

if ( $has_value ) {
break;
}
}
if ( ! $instance_has_value ) {
$has_value = false;
break;
}
}
Comment on lines +980 to 1018
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters required-field validation semantics for cloned fields (now requiring all instances to have values). Given validation is a core path, please add/update PHPUnit coverage for ppom_has_posted_field_value() with at least one cloned-field case (including a failing clone instance) to prevent regressions.

Copilot uses AI. Check for mistakes.

Expand Down Expand Up @@ -2517,7 +2526,7 @@ function ppom_posted_field_max_min_value_validation( $posted_fields, $field ) {
$has_field_value = isset( $posted_fields[ $data_name ] );
if ( ! $has_field_value ) {
foreach ( $posted_fields as $field_key => $field_value ) {
$field_key = explode( '__clone__', $field_key );
$field_key = explode( '__clone_', $field_key );
if ( in_array( $data_name, $field_key, true ) ) {
$has_field_value = true;
break;
Expand All @@ -2538,7 +2547,7 @@ function ppom_posted_field_max_min_value_validation( $posted_fields, $field ) {
}

foreach ( $posted_fields as $field_key => $field_value ) {
$field_key = explode( '__clone__', $field_key );
$field_key = explode( '__clone_', $field_key );

if ( in_array( $data_name, $field_key, true ) && is_array( $field_value ) ) {
$count = count( $field_value );
Expand Down
Loading