gocodebox / gocodebox/lifterlms

Multiselects with 0 in the values array auto-select 0 by default

Open
#690 4 comments 0 reactions 1 assignee Claimed by @thomasplevy View on GitHub
good first issue hacktoberfest help wanted Status: Has PR Type: Bug
Dominant language
PHP
Stars
212
Forks
140
Avg merge
2d 14h
Merged PRs (30d)
19

Description

### 1. Reproduction Steps

Add a new multiselect field to a LLMS settings section, like:

```
function test_course_lesson_metabox( $fields ) {

$values = array(
array(
'key' => '1',
'title' => '1',
),
array(
'key' => '2',
'title' => '2',
),
array(
'key' => 'Three',
'title' => 'Three',
),
array(
'key' => '0',
'title' => '0',
)
);

$selected = array( '1', 'Three' );

$fields['test'] = array( 'title' => 'Test', 'fields' => array() );

$fields['test']['fields'][] = array(
'id' => 'test',
'label' => 'Test',
'multi' => '1',
'type' => 'select',
'value' => $values,
'selected' => $selected
);

return $fields;

}

add_filter( 'llms_metabox_fields_lifterlms_course_options', 'test_course_lesson_metabox' );

```

### 2. Expected Behavior

+ The multiselect should show selected values of "1" and "Three"

### 3. Actual Behavior

+ Multiselect shows selected values of "0", "1", and "Three"

### 4. Solution
+ In llms.class.meta.box.select.php at line 67, change `if ( in_array( $option['key'], $selected ) ) {` to `if ( in_array( $option['key'], $selected, true ) ) {` so numbers aren't compared with strings.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.