Fix fatal error on first opt-in when plugin has no paid plans#880
Open
hammad-wpbrigade wants to merge 1 commit into
Open
Fix fatal error on first opt-in when plugin has no paid plans#880hammad-wpbrigade wants to merge 1 commit into
hammad-wpbrigade wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_idwithout anisset()guard,causing
Undefined property: stdClass::$plan_idwhen the install object hasno
plan_id._store_plans()calledcount( $this->_plans )while_planswas still itsinitial
falsevalue, causing aTypeErroron PHP 8+.Changes
includes/entities/class-fs-site.php: only assignplan_idwhen the property is set.includes/class-freemius.php: only iterate_plansin_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