Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line 63 added to prevent boolean type from being passed to array_merge #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public function get_key() {
* @return mixed Whatever is in those fields.
*/
public function get( $field = null, $default = null ) {
$option_array = get_option( $this->key, array() );
$option_array = gettype($option_array) != "array" ? [] : $option_array;
Copy link
Contributor

Choose a reason for hiding this comment

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

Short array syntax [] available since PHP 5.4, what is doesn't fit the WordPress' minimal requirements.

Choose a reason for hiding this comment

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

It would probably be simpler to just cast to array:

$option_array = (array) get_option( $this->key, array() );

or more simply wrote:

$data = array_merge( $this->defaults, (array) get_option( $this->key, array() ) );

Copy link
Author

Choose a reason for hiding this comment

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

My first change, forgot to include the last line for $option_array. I agree, a cast would be easier.

$data = array_merge( $this->defaults, get_option( $this->key, array() ) );

Choose a reason for hiding this comment

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

You might need to use $option_array on this line. Otherwise the PR doesn't do anything.


return scbForms::get_value( $field, $data, $default );
Copy link
Author

Choose a reason for hiding this comment

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

// should be
$data = array_merge( $this->defaults, $option_array );

}

Expand Down