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

Fixed PHP warning Trying to access array offset on value of type int in get_index_names(). #2580

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

sun
Copy link
Contributor

@sun sun commented Feb 1, 2022

Description of the Change

Problem

  • Running wp elasticpress get-indexes causes the following PHP warnings:
$ wp elasticpress get-indexes
PHP Warning:  Trying to access array offset on value of type int
  in /wp-content/plugins/elasticpress/includes/classes/Command.php on line 427
PHP Warning:  Trying to access array offset on value of type int
  in /wp-content/plugins/elasticpress/includes/classes/Command.php on line 430
["active-mysite-post-1"]

Cause

  • On non-multi-site installations, Command::get_index_names() uses a pseudo list of sites only containing the current/single site. The element in this array matches the expected structure of a WP_Site, but the outer array for the list is missing.

Proposed solution

  1. Fix the array structure to return a list of sites.

Alternate Designs

The fallback/pseudo list of sites on single-site installations could be embedded into Utils\get_sites().

Possible Drawbacks

Verification Process

The PHP warning is gone:

$ wp elasticpress get-indexes
["active-mysite-post-1"]

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Fixed PHP warning Trying to access array offset on value of type int in get_index_names().

Credits

Props @sun

@felipeelia felipeelia self-assigned this Mar 15, 2022
@felipeelia felipeelia added this to the 4.1.0 milestone Mar 15, 2022
@felipeelia felipeelia merged commit 93b2e70 into 10up:develop Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants