wp-cli / language-command

Installs, activates, and manages language packs.
MIT License
13 stars 21 forks source link

PHP notice on updating theme translations with no updates #58

Closed grappler closed 5 years ago

grappler commented 5 years ago

When running the update command and there are no updates there is a PHP warning with WP-CLI 2.0.1

wp language theme update twentysixteen
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 91
Warning: Invalid argument supplied for foreach() in phar:///bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 95
Success: Updated 0/0 translations.
schlessera commented 5 years ago

Additional information provided by @swissspidy in duplicate issue #60 :


I'm currently getting the following PHP warnings when updating language packs on a site:

PHP Warning:  Invalid argument supplied for foreach() in phar:///usr/bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 95
Warning: Invalid argument supplied for foreach() in phar:///usr/bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 95
Success: Updated 0/0 translations.

The code in question is here:

https://github.com/wp-cli/language-command/blob/b17cdd8a56579489c1c007e69a6b30254372789c/src/WP_CLI/CommandWithTranslation.php#L88-L103

Looks like the code currently doesn't check whether $available_updates is actually set or is an array. We could add a continue statement in that case.

ocean90 commented 5 years ago

@frozzare Did you forget to submit your change as a PR? 🙂

frozzare commented 5 years ago

@ocean90 yeah, sorry. Did get so late last night so I forgot about this 🙂