Skip to content

Conversation

DanieleAlessandra
Copy link
Collaborator

…mposer loads (Bedrock/Altis)

When the SDK is autoloaded via Composer before WP finishes bootstrapping (e.g., Bedrock/Altis), the “latest SDK” selection logic can call WP functions that aren’t available yet (e.g. get_theme_root()), causing a fatal. This change introduces a guard that, when FS__SKIP_LATEST_SDK_LOADING is defined and true, skips that logic entirely and exposes a minimal fs_dynamic_init() no-op to avoid undefined-function errors.

Details:
• Guard placed right after the ABSPATH check in start.php.
• If the flag is set, define a stub fs_dynamic_init() and return; early.
• Keeps default behavior unchanged for all other environments.
• Helps integrators who load the SDK from vendor/ before WP is ready.
• Version bumped to 2.12.2.1.

Notes:
• The constant must be defined before the SDK is loaded (e.g., in wp-config.php or via Composer autoload.files preload in Bedrock).
• Follow-up: document usage and caveats.

…mposer loads (Bedrock/Altis)

When the SDK is autoloaded via Composer before WP finishes bootstrapping (e.g., Bedrock/Altis), the “latest SDK” selection logic can call WP functions that aren’t available yet (e.g. get_theme_root()), causing a fatal.
This change introduces a guard that, when FS__SKIP_LATEST_SDK_LOADING is defined and true, skips that logic entirely and exposes a minimal fs_dynamic_init() no-op to avoid undefined-function errors.

Details:
	•	Guard placed right after the ABSPATH check in start.php.
	•	If the flag is set, define a stub fs_dynamic_init() and return; early.
	•	Keeps default behavior unchanged for all other environments.
	•	Helps integrators who load the SDK from vendor/ before WP is ready.
	•	Version bumped to 2.12.2.1.

Notes:
	•	The constant must be defined before the SDK is loaded (e.g., in wp-config.php or via Composer autoload.files preload in Bedrock).
	•	Follow-up: document usage and caveats.
@DanieleAlessandra DanieleAlessandra marked this pull request as ready for review September 25, 2025 06:41
… and debug templates

- Added guarded initialization of `$fs` in multiple SDK templates (`form.php`, `retry-skip.php`, `optout.php`, `debug.php`, etc.)
- Replaced direct `freemius($VARS['id'])` calls with conditional checks for `function_exists('freemius')`
- Fallback to `Freemius::get_instance_by_id()` when the helper function is not yet defined
- Added early `return` when `$fs` could not be resolved to prevent fatal errors

# NOTE:
This workaround is **not a viable long-term solution**, as it requires patching numerous template files across the SDK.
It introduces code duplication and increases the risk of maintenance errors.
A centralized solution should be implemented instead (e.g., ensuring `freemius()` is always loaded before rendering templates).
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.

2 participants