Skip to content

Undefined Array Key versions in class-beta-optin.php #308

@RRyanHoward

Description

@RRyanHoward

File: includes/modules/version-control/class-beta-optin.php
Line: ~106
PHP Version: 8.1+

Description:

When the get_plugin_info() call returns an array without the versions key (due to a missing or stale transient, or failed remote fetch), the following warning appears:

Warning: Undefined array key "versions" in .../class-beta-optin.php on line 106

How to Reproduce:

  1. Programmatically clear the update_plugins site transient and rank_math_trunk_version transient.
  2. Load the Plugins screen or any admin screen that triggers Beta_Optin::get_available_versions().
  3. If the transient isn't yet repopulated fully, the versions key may be missing — triggering the warning.

Suggested Fix:

Replace line:

php foreach ( (array) $plugin_info['versions'] as $version => $url ) {

With:

php foreach ( (array) ($plugin_info['versions'] ?? []) as $version => $url ) {

This makes it compatible with PHP 8+ and avoids noise when the plugin info is incomplete.

This error only affects environments with strict PHP error reporting or uninitialized update transients, but it's easy to fix and safe to patch.

Thanks for the great plugin!

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