Skip to content

Refactor: Prevent some undefined array key warnings. #104

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

Merged
merged 6 commits into from
Apr 10, 2025

Conversation

cbravobernal
Copy link
Contributor

@cbravobernal cbravobernal commented Apr 7, 2025

What

While working on SCF. I have been receiving several warnings that made field creation difficult. Something like this:

Screenshot 2025-04-07 at 18 10 13
Screenshot 2025-04-07 at 18 10 19

Test

  • Check that you have similar warnings than the ones shown in the screenshot when you try to create custom fields.
  • Check that with the PR they are gone.

continue;
}
// bail early if choice already exists
if ( in_array( $esc_value, $this->_values, true ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

was this intentionally changed to a strict comparison?

Copy link
Contributor Author

@cbravobernal cbravobernal Apr 8, 2025

Choose a reason for hiding this comment

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

Yep, otherwise phpcs was complaining about it. It should not be risky. As both values come from esc_attrfunctions, which should return a string.

@pkevan
Copy link
Contributor

pkevan commented Apr 8, 2025

I wonder if it might be best to have a helper function for all these isset checks, as it makes the code harder to read as a result?

@cbravobernal cbravobernal self-assigned this Apr 8, 2025
@cbravobernal
Copy link
Contributor Author

I wonder if it might be best to have a helper function for all these isset checks, as it makes the code harder to read as a result?

I found indeed an acf_maybe_get function.

@cbravobernal cbravobernal merged commit e31d212 into trunk Apr 10, 2025
5 checks passed
@kraftbj kraftbj deleted the refactor/fix-array-keys-undefined-warnings branch April 14, 2025 14:27
@kraftbj kraftbj added this to the 6.5.0 milestone Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants