Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce wp_trigger_error() #5122

Closed
wants to merge 4 commits into from

Conversation

azaozz
Copy link
Contributor

@azaozz azaozz commented Aug 30, 2023

Trac ticket: https://core.trac.wordpress.org/ticket/57686


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

and use it in _doing_it_wrong().
as it seems it may not work very well since PHP 7.
@azaozz
Copy link
Contributor Author

azaozz commented Aug 30, 2023

TODO/TBD: Wondering if it's worth it to add a simple backtrace when WP_DEVELOPMENT_MODE is true. Tested with only printing function names, no args as they can be huge sometimes. The code for it would be like:

	if ( WP_DEVELOPMENT_MODE ) {
		// Output a simple backtrace.
		ob_start();
		debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
		$backtrace = ob_get_contents();
		ob_end_clean();

		// This may be called very early. See above about use of `__()`.
		if ( function_exists( 'esc_html' ) ) {
			$backtrace = esc_html( $backtrace );
		}

		// Space it a bit for better readability.
		$backtrace = str_replace( "\n", "\n\n", $backtrace );

		echo '<p style="white-space: pre-wrap;">';
		echo $backtrace;
		echo '</p>';
	}

return;
}

if ( function_exists( '__' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why translate PHP errors / warnings / notices / deprecations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. These are translated in doing_it_wrong, was just using that code as example.
As these errors are intended only for developers and not for the end users, translation is probably not needed.

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Sep 26, 2023

Closing in favor of a wrapper approach in #5144, that was committed instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants