Skip to content

Fix fatal in add_notice() outside wp-admin - #27

Merged
mzakash merged 1 commit into
release/v1.2.3from
rajkiranb/sur-5958-licensing-sdk-settingsadd_notice-fatals-outside-wp-admin
Oct 21, 2026
Merged

mzakash merged 1 commit into
release/v1.2.3from
rajkiranb/sur-5958-licensing-sdk-settingsadd_notice-fatals-outside-wp-admin

Conversation

@RajkiranBagal

Copy link
Copy Markdown
Contributor

Fixes SUR-5958 (surecart/surecart-wp#4463).

What changes

1. Skip notices when add_settings_error() isn't loaded
get_activation() adds a notice on any API error, and add_notice() called add_settings_error() without a check. That function is defined in wp-admin/includes/template.php, which the SDK never loads. Calling get_activation() on init, the front end, REST, cron or WP-CLI fataled with Call to undefined function SureCart\Licensing\add_settings_error() whenever the license API returned an error. A developer bundling the SDK hit this in production through a plugin that checks the license on init.

add_notice() now returns early when the function doesn't exist. The settings page still shows the notice, because it calls get_activation() again while rendering, when template.php is loaded.

2. Bump to 1.2.3

3. README note on bundled copies
Every plugin that bundles the SDK shares the SureCart\Licensing namespace, so the first copy to load serves all of them, and an older copy can override fixes. The README now recommends prefixing the namespace with Strauss or PHP-Scoper.

Testing

No unit test: SettingsFormTest already loads template.php, so add_settings_error() can't be made missing in the PHPUnit process. I verified with a standalone script that loads the real SDK files, makes the activation request return a WP_Error, and doesn't load template.php:

Error Before (1.2.2) After (1.2.3)
http_request_failed Fatal at Settings.php:416 Returns (object) ['id' => 'act_123'], options unchanged
not_found Fatal at Settings.php:416 Returns false, options unchanged

php -l passes on both files. phpcs wasn't run.

Not included: loading the highest-versioned copy when several plugins bundle the SDK. That's a separate follow-up.

🤖 Generated with Claude Code

get_activation() adds a notice on any API error, and add_settings_error()
only exists in wp-admin. Calling it on init, the front end, REST, cron or
WP-CLI fataled whenever the license API failed.

Also bump to 1.2.3 and note in the README that bundled copies share one
namespace.
@mzakash
mzakash changed the base branch from main to release/v1.2.3 October 21, 2026 07:41
@mzakash
mzakash merged commit 45c17a0 into release/v1.2.3 Oct 21, 2026
2 checks passed
@mzakash
mzakash deleted the rajkiranb/sur-5958-licensing-sdk-settingsadd_notice-fatals-outside-wp-admin branch October 21, 2026 07:42
@mzakash mzakash mentioned this pull request Oct 21, 2026
3 tasks
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