Skip to content

Reader-activation foreach variable overwrites method parameter (WP_Scripts::localize notice) #4560

@grahamgrafx

Description

@grahamgrafx

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

  1. Enable WP_DEBUG and WP_DEBUG_LOG in wp-config.php
  2. Activate Newspack with Reader Activation enabled
  3. Visit the homepage
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions