Skip to content

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

Description

@hammad-wpbrigade

馃悶 bug report

Behavior:

  • What is the issue? (*)
    On a fresh first opt-in for a free-only plugin ('has_paid_plans' => false), two problems occur:
  1. Warning: Undefined property: stdClass::$plan_id in .../freemius/includes/entities/class-fs-site.php on line 123
    FS_Site::__construct() reads $site->plan_id without checking the property exists.

  2. Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in .../freemius/includes/class-freemius.php:19847
    _store_plans() calls count( $this->_plans ) while $this->_plans is still its initial value false.

Reproduction: activate a free-only Freemius plugin on a clean WordPress install (PHP 8+) and complete the opt-in for the first time.

  • What is the expected behavior?
    Opt-in completes without warnings or fatal errors when the plugin has no paid plans / the install object has no plan_id.

Versions: (*)

  • Freemius SDK Version: 2.13.1 (code path also present in 2.13.4 / current develop)
  • WordPress Version: 6.9
  • PHP Version: 8.2

Plugin / Theme: (*)

  • Name: [redacted]
  • Slug: [redacted]
  • Freemius ID: [redacted]

Additional Information:

Image

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