---
title: "OptionTree \"Trying to access array offset on false\" in class-ot-settings.php"
canonical: "https://techwiki.co.uk/cms/optiontree-array-offset-on-false-class-ot-settings"
author: "Adam Birds"
article_type: "documentation"
published: "2026-10-31T15:37:18.907Z"
updated: "2026-10-31T15:37:18.907Z"
categories: ["Cms"]
tags: ["optiontree","php","wordpress"]
---**With OptionTree active on modern PHP, the error log gets a pair of warnings on admin requests, including background `admin-ajax.php` calls.**

```text
PHP Warning:  Trying to access array offset on false in <wordpress-root>/wp-content/plugins/option-tree/includes/class-ot-settings.php on line 395
PHP Warning:  Trying to access array offset on false in <wordpress-root>/wp-content/plugins/option-tree/includes/class-ot-settings.php on line 396
```

## Cause

This is a bug in the plugin, not bad data in the database. `get_sections()` returns `false` for a settings page with no sections, and `add_sections()` loops over the result with an array cast:

```php
foreach ( (array) $this->get_sections( $page ) as $section ) {
```

Casting `false` to an array gives `[ false ]`, not an empty array. The loop runs once with `$section` set to `false`, then reads `$section['id']` and `$section['title']`.

## Fix

Use a must-use plugin so that the fix survives plugin updates. Must-use plugins load first, and OptionTree only defines `ot_register_settings()` if it does not already exist, so this version takes its place. It uses an anonymous subclass that returns an empty array instead of `false`.

Create `wp-content/mu-plugins/optiontree-fixes.php`:

```php
<?php
/**
 * Plugin Name: OptionTree fixes
 * Description: Stops OptionTree warnings in the PHP log without editing the plugin.
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'ot_register_settings' ) ) {
	function ot_register_settings( $args ) {
		if ( ! $args || ! class_exists( 'OT_Settings' ) ) {
			return;
		}

		new class( $args ) extends OT_Settings {
			public function get_sections( $page = array() ) {
				return parent::get_sections( $page ) ?: array();
			}
		};
	}
}
```

## Verify

Confirm that WordPress is using the replacement function:

```bash
wp eval 'echo (new ReflectionFunction("ot_register_settings"))->getFileName(), PHP_EOL;'
```

The output should end in `mu-plugins/optiontree-fixes.php`. Then trigger an admin request and check that the log has no new warnings. An anonymous POST is enough, because `admin-ajax.php` runs `admin_init`:

```bash
curl -s -o /dev/null -w '%{http_code}\n' -X POST -d 'action=noop' https://<your-domain>/wp-admin/admin-ajax.php
```

A `400` response is expected here. Run the same request before adding the fix to confirm that it reproduces the warnings on your site.

## Notes

- The fix depends on OptionTree's `function_exists` guard around `ot_register_settings()`. If a future version removed that guard, PHP would stop with a fatal redeclare error. Deleting the must-use plugin would resolve it.
- If nothing on the site uses OptionTree, deactivating it is simpler. Check the theme and other plugins for `ot_get_option` calls first.
- Tested with OptionTree 2.7.3 and PHP 8.5.
