wp-cli / i18n-command

Provides internationalization tools for WordPress projects.
MIT License
96 stars 52 forks source link

PHP Warning: foreach() argument must be of type array|object, #375

Closed helgatheviking closed 7 months ago

helgatheviking commented 8 months ago

Bug Report

Describe the current, buggy behavior

Missing strings when generating .pot file. Seeing a notice about a PHP Warning.

Describe how other contributors can replicate this bug

wp --allow-root i18n make-pot . languages/wc-mnm-quickview.pot --slug=wc-mnm-quickview --exclude=".github,.wordpress-org,node_modules,vendor,build,deploy"  '--skip-audit'

and the output in the command line. the .pot file is missing strings not in the main plugin file.

Plugin file detected.
PHP Warning:  foreach() argument must be of type array|object, string given in /home/helga/Sites/sandbox/wp-content/plugins/wc-mnm-quickview/vendor/wp-cli/i18n-command/src/MakePotCommand.php on line 969

Describe what you would expect as the correct outcome

A clear and concise description of what you expected to happen (or code).

Let us know what environment you are running this on

OS:     Linux 6.2.0-33-generic #33-Ubuntu SMP PREEMPT_DYNAMIC Tue Sep  5 14:49:19 UTC 2023 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php8.1
PHP version:    8.1.12-1ubuntu4.3
php.ini used:   /etc/php/8.1/cli/php.ini
MySQL binary:
MySQL version:
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/helga/Sites/sandbox/wp-content/plugins/wc-mnm-quickview
WP-CLI packages dir:
WP-CLI cache dir:       /home/helga/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.9.0

Provide a possible solution

If you happen to have a suggestion on how to fix this bug, please tell us in here.

Just leave this section out if you don't know how to fix it.

Provide additional context/Screenshots

swissspidy commented 8 months ago

Thanks a lot for your report.

With your provided command I don't see how this would be possible, unless something weird is going on with parsing the command line arguments.

Does this also happen when you just run wp --allow-root i18n make-pot .?

Is your wc-mnm-quickview code perhaps public somewhere so I could try to reproduce this myself?

helgatheviking commented 7 months ago

Ok, I am fairly certain the problem is that I am trying to add some headers but struggling with the JSON format. So this isn't a bug, but it would be handy to add an example to the readme.

'--headers=[\"Report-Msgid-Bugs-To: https://somesite.com/my-account/tickets/\"]'
swissspidy commented 7 months ago

Here‘s an example from the tests:

wp i18n make-pot wp-content/plugins/hello-world wp-content/plugins/hello-world/languages/hello-world.pot --headers='{"Report-Msgid-Bugs-To":"https://github.com/hello-world/hello-world/"}'

Any PRs updating the examples in the PHP code are of course welcome.