Skip to content

feat(1314): add unclosed ob_start check#1318

Open
faisalahammad wants to merge 3 commits into
WordPress:trunkfrom
faisalahammad:enhancement/1314-unclosed-ob-start-check
Open

feat(1314): add unclosed ob_start check#1318
faisalahammad wants to merge 3 commits into
WordPress:trunkfrom
faisalahammad:enhancement/1314-unclosed-ob-start-check

Conversation

@faisalahammad
Copy link
Copy Markdown
Contributor

@faisalahammad faisalahammad commented May 24, 2026

Summary

Adds a new performance check to detect ob_start() calls that are not closed within the same scope. This prevents unpredictable behaviour caused by misaligned output buffers in shared environments.

Fixes #1314

Changes

includes/Checker/Checks/Performance/Unclosed_Ob_Start_Check.php

Before:

// File did not exist

After:

class Unclosed_Ob_Start_Check extends Abstract_File_Check {
	// ... (implements token parsing to track ob_start/close depth)
}

Why: A custom static analysis implementation utilizing token_get_all() accurately tracks block scope (T_FUNCTION, {, }) to ensure every ob_start() is reliably paired with a closing function on the same scope level.

includes/Checker/Default_Check_Repository.php

Before:

				'wp_functions_compatibility' => new Checks\Plugin_Repo\WP_Functions_Compatibility_Check(),
			)

After:

				'wp_functions_compatibility' => new Checks\Plugin_Repo\WP_Functions_Compatibility_Check(),
				'unclosed_ob_start'          => new Checks\Performance\Unclosed_Ob_Start_Check(),
			)

Why: Registers the newly created check to be automatically instantiated when scanning plugins.

Testing

Test 1: Unclosed ob_start Detection

  1. Create a dummy plugin calling ob_start(); at the root without closing it, and inside a function but conditionally closed inside an if block.
  2. Run wp plugin check <dummy-plugin>.
  3. Verify that the command flags the unpaired ob_start() calls on the specific lines as performance warnings.

Result: Works as expected

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: davidperezgar <davidperez@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@faisalahammad faisalahammad force-pushed the enhancement/1314-unclosed-ob-start-check branch from 2f01cac to 32eccbe Compare May 24, 2026 14:21
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.

Unclosed ob_start() usage

1 participant