Skip to content

Fatal error: Cannot access offset of type string on string in admin.php (PHP 8+ compatibility) #1055

@kushh23

Description

@kushh23

Description

Description:

A fatal error occurs when the plugin is used on a site where the service_data option is a non-array value (string), causing a TypeError on PHP 8+:

PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /wp-content/plugins/optimole-wp/inc/admin.php:1447

Expected:

  • Plugin handles corrupted or unexpected service_data values gracefully and does not crash.

Actual:

  • Plugin checks only !empty($service_data) and then accesses $service_data['domain_dns'], which fatals if $service_data is a string. This can occur if the WordPress option is unexpectedly stored as a string. Affected area: Optml_Admin->localize_dashboard_app.
  • Bug triggered in PHP 8+. In older PHP versions this was not fatal but in PHP 8+ it stops all plugin functionality with a hard error.

Step-by-step reproduction instructions

  1. Trigger a situation where the option service_data in wp_options is a string (corruption, failed write, or API/caching layer returns a string).
  2. Visit the Optimole dashboard or any admin page that triggers Optml_Admin->enqueue() and then Optml_Admin->localize_dashboard_app().
  3. Observe the fatal error in logs (TypeError: Cannot access offset of type string on string in admin.php line 1447).

Screenshots, screen recording, code snippet or Help Scout ticket

Error message from logs:

PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /wp-content/plugins/optimole-wp/inc/admin.php:1447
Stack trace:
#0 ... Optml_Admin->localize_dashboard_app()
...

Problem lines:
https://github.com/Codeinwp/optimole-wp/blob/master/inc/admin.php#L1447
https://github.com/Codeinwp/optimole-wp/blob/master/inc/admin.php#L1449

Suggested fix: Check with is_array($service_data) before accessing as array.

Reported here: https://secure.helpscout.net/conversation/3293257808/487980

Environment info

No response

Is the issue you are reporting a regression

No

Metadata

Metadata

Labels

bugThis label could be used to identify issues that are caused by a defect in the product.customer reportIndicates the request came from a customer.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions