Describe the bug
With WP_DEBUG on, I get a notice on the homepage: "Function WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array."
It's coming from class-reader-activation.php line 199. The get_reader_activation_labels() method is supposed to return an array when called with no args, but it's returning a string. The cause is variable shadowing — the foreach on line 336 uses $key as the loop variable, which overwrites the method's $key parameter. After the loop, $key is the last array key instead of null, so the method hits the wrong return path and returns a single label string instead of the full array.
To Reproduce
- Enable WP_DEBUG and WP_DEBUG_LOG in wp-config.php
- Activate Newspack with Reader Activation enabled
- Visit the homepage
- Check debug.log or the page output for the notice
Expected behavior
No notice. The reader auth script should get the full labels array as intended.
Fix: Rename just the foreach variable from $key to $label_key in includes/reader-activation/class-reader-activation.php:336; Update the references inside the loop accordingly.
Environment: WordPress 6.9.4, Newspack 6.32.0, PHP 8.3.29
Describe the bug
With WP_DEBUG on, I get a notice on the homepage: "Function WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array."
It's coming from
class-reader-activation.phpline 199. Theget_reader_activation_labels()method is supposed to return an array when called with no args, but it's returning a string. The cause is variable shadowing — the foreach on line 336 uses$keyas the loop variable, which overwrites the method's$keyparameter. After the loop,$keyis the last array key instead of null, so the method hits the wrong return path and returns a single label string instead of the full array.To Reproduce
Expected behavior
No notice. The reader auth script should get the full labels array as intended.
Fix: Rename just the foreach variable from
$keyto$label_keyin includes/reader-activation/class-reader-activation.php:336; Update the references inside the loop accordingly.Environment: WordPress 6.9.4, Newspack 6.32.0, PHP 8.3.29