Skip to content

Commit

Permalink
Proper fix for is_list logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed May 1, 2024
1 parent 5d3ea2d commit fdfad95
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/Admin/Settings/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Plausible\Analytics\WP\Admin\Settings;

use Plausible\Analytics\WP\Ajax;
use Plausible\Analytics\WP\Helpers;

/**
Expand Down Expand Up @@ -581,23 +582,21 @@ public function render_group_field( array $group, $hide_header = false ) {
</header>
<?php endif; ?>
<?php if ( ! empty( $fields ) ): ?>
<?php $is_list = count( $fields ) > 1; ?>
<?php if ( $is_list ) {
foreach ( $fields as $field ) {
if ( $field[ 'type' ] === 'hook' ) {
continue;
}

if ( $field[ 'type' ] !== 'checkbox' ) {
$is_list = false;

break;
}
<?php
/**
* if $fields contains more than one checkbox field type, this is a list, which is treated different in @see Ajax::toggle_option()
*/
$is_list = array_filter(
$fields,
function ( $field ) {
return $field[ 'type' ] === 'checkbox';
}
);

foreach ( $fields as $field ) {
echo call_user_func( [ $this, "render_{$field['type']}_field" ], $field, count( $is_list ) > 1 );
}
foreach ( $fields as $field ): ?>
<?php echo call_user_func( [ $this, "render_{$field['type']}_field" ], $field, $is_list ); ?>
<?php endforeach; ?>
?>
<?php endif; ?>
</div>
<?php
Expand Down

0 comments on commit fdfad95

Please sign in to comment.