Skip to content

Fix fatal error on first opt-in when plugin has no paid plans#880

Open
hammad-wpbrigade wants to merge 1 commit into
Freemius:masterfrom
hammad-wpbrigade:fix/store-plans-count-guard-on-first-optin
Open

Fix fatal error on first opt-in when plugin has no paid plans#880
hammad-wpbrigade wants to merge 1 commit into
Freemius:masterfrom
hammad-wpbrigade:fix/store-plans-count-guard-on-first-optin

Conversation

@hammad-wpbrigade

Copy link
Copy Markdown

Summary

Fixes a warning + fatal error during the first opt-in of a free-only plugin
('has_paid_plans' => false).

  • FS_Site::__construct() read $site->plan_id without an isset() guard,
    causing Undefined property: stdClass::$plan_id when the install object has
    no plan_id.
  • _store_plans() called count( $this->_plans ) while _plans was still its
    initial false value, causing a TypeError on PHP 8+.

Changes

  • includes/entities/class-fs-site.php: only assign plan_id when the property is set.
  • includes/class-freemius.php: only iterate _plans in _store_plans() when it is an array.

Both are minimal, backward-compatible guards consistent with existing patterns
(e.g. the array checks already used in _store_licenses()).

Resolved Issue

Fatal error on first opt-in when plugin has no paid plans (count() on bool _plans)

Test plan

  • Fresh activation + first opt-in of a free-only plugin on PHP 8.x — no warning, no fatal.
  • Existing installs with plans still store/encrypt plans as before.

FS_Site::__construct() read \->plan_id without checking the
property exists, emitting an ''Undefined property'' warning when the
install object returned on first opt-in has no plan_id.

_store_plans() then called count() on \->_plans while it was still
its initial bool false value, triggering a fatal TypeError on PHP 8+
(count(): Argument Freemius#1 must be of type Countable|array, bool given).

Guard both: only copy plan_id when set, and only iterate _plans when it
is an array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant