Skip to content
This repository was archived by the owner on Aug 18, 2026. It is now read-only.
This repository was archived by the owner on Aug 18, 2026. It is now read-only.

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

Open

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

Activity

  1. grahamgrafx commented on Mar 12, 2026

    @grahamgrafx
    Author

    Full disclosure: This was a vibe coded fix. I've encountered the problem twice on two separate fresh installations.

    The first time I worked through the problem with an agent and produced this issue.

    The second time I tried fixing the issue manually using the specifics here, and struggled. I fed my agent the description and it fixed it immediately. I see the change, and it was specific to the $key variable in just the foreach loop (I accidentally went beyond the foreach loop when I did it manually).

    I edited/updated the description here accordingly.

  2. changed the title [-]Variable shadowing in get_reader_activation_labels() causes wp_localize_script notice[/-] [+]Reader-activation foreach variable overwrites method parameter (WP_Scripts::localize notice)[/+] on Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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