Code Modernization: Use wp_trigger_error() instead of trigger_error().

Replaces `trigger_error()` with `wp_trigger_error()`.

The usage of `wp_trigger_error()` avoids generating `E_USER` family errors unless `WP_DEBUG` is on. In doing so, users should not see these messages in normal production.

Notes:
* Removes `E_USER_NOTICE` when passed as an argumnent, as it's the default error level.
* An empty string is passed for the function name when its name is already in the error message or does not add value to the error message.
* Externally maintained libraries are not included.

Follow-up to [55204], [25956], [29630], [38883], [52062], [52049], [54272], [38883], [55245], [51599], [14452], [38883], [24976].

Props prasadkarmalkar, rajinsharwar, thelovekesh, hellofromTonya, swissspidy. 
Fixes #59652.
Built from https://develop.svn.wordpress.org/trunk@58409


git-svn-id: http://core.svn.wordpress.org/trunk@57858 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2024-06-13 20:50:14 +00:00
parent 2889f4d90e
commit b5ec907fb0
17 changed files with 39 additions and 25 deletions

View File

@ -2795,7 +2795,7 @@ function wp_opcache_invalidate_directory( $dir ) {
__( '%s expects a non-empty string.' ), __( '%s expects a non-empty string.' ),
'<code>wp_opcache_invalidate_directory()</code>' '<code>wp_opcache_invalidate_directory()</code>'
); );
trigger_error( $error_message ); wp_trigger_error( '', $error_message );
} }
return; return;
} }

View File

@ -174,7 +174,8 @@ function plugins_api( $action, $args = array() ) {
if ( $ssl && is_wp_error( $request ) ) { if ( $ssl && is_wp_error( $request ) ) {
if ( ! wp_is_json_request() ) { if ( ! wp_is_json_request() ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),

View File

@ -568,7 +568,8 @@ function themes_api( $action, $args = array() ) {
if ( $ssl && is_wp_error( $request ) ) { if ( $ssl && is_wp_error( $request ) ) {
if ( ! wp_doing_ajax() ) { if ( ! wp_doing_ajax() ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),

View File

@ -59,7 +59,8 @@ function translations_api( $type, $args = null ) {
$request = wp_remote_post( $url, $options ); $request = wp_remote_post( $url, $options );
if ( $ssl && is_wp_error( $request ) ) { if ( $ssl && is_wp_error( $request ) ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),

View File

@ -145,7 +145,8 @@ function get_core_checksums( $version, $locale ) {
$response = wp_remote_get( $url, $options ); $response = wp_remote_get( $url, $options );
if ( $ssl && is_wp_error( $response ) ) { if ( $ssl && is_wp_error( $response ) ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),

View File

@ -78,7 +78,7 @@ function endElement( $parser, $tag_name ) { // phpcs:ignore WordPress.NamingConv
// Create an XML parser. // Create an XML parser.
if ( ! function_exists( 'xml_parser_create' ) ) { if ( ! function_exists( 'xml_parser_create' ) ) {
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); wp_trigger_error( '', __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
} }

View File

@ -252,7 +252,7 @@ function _filter_block_template_part_area( $type ) {
$type, $type,
WP_TEMPLATE_PART_AREA_UNCATEGORIZED WP_TEMPLATE_PART_AREA_UNCATEGORIZED
); );
trigger_error( $warning_message, E_USER_NOTICE ); wp_trigger_error( __FUNCTION__, $warning_message );
return WP_TEMPLATE_PART_AREA_UNCATEGORIZED; return WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
} }

View File

@ -504,7 +504,7 @@ class WP_Theme_JSON_Resolver {
$json_decoding_error = json_last_error(); $json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) { if ( JSON_ERROR_NONE !== $json_decoding_error ) {
trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() ); wp_trigger_error( __METHOD__, 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
/** /**
* Filters the data provided by the user for global styles & settings. * Filters the data provided by the user for global styles & settings.
* *

View File

@ -3775,7 +3775,8 @@ class WP_Theme_JSON {
|| ! is_numeric( $spacing_scale['mediumStep'] ) || ! is_numeric( $spacing_scale['mediumStep'] )
|| ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ) { || ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ) {
if ( ! empty( $spacing_scale ) ) { if ( ! empty( $spacing_scale ) ) {
trigger_error( wp_trigger_error(
__METHOD__,
sprintf( sprintf(
/* translators: 1: theme.json, 2: settings.spacing.spacingScale */ /* translators: 1: theme.json, 2: settings.spacing.spacingScale */
__( 'Some of the %1$s %2$s values are invalid' ), __( 'Some of the %1$s %2$s values are invalid' ),

View File

@ -587,7 +587,7 @@ function prep_atom_text_construct( $data ) {
} }
if ( ! function_exists( 'xml_parser_create' ) ) { if ( ! function_exists( 'xml_parser_create' ) ) {
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); wp_trigger_error( '', __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
return array( 'html', "<![CDATA[$data]]>" ); return array( 'html', "<![CDATA[$data]]>" );
} }

View File

@ -5518,10 +5518,11 @@ function wp_strip_all_tags( $text, $remove_breaks = false ) {
if ( ! is_scalar( $text ) ) { if ( ! is_scalar( $text ) ) {
/* /*
* To maintain consistency with pre-PHP 8 error levels, * To maintain consistency with pre-PHP 8 error levels,
* trigger_error() is used to trigger an E_USER_WARNING, * wp_trigger_error() is used to trigger an E_USER_WARNING,
* rather than _doing_it_wrong(), which triggers an E_USER_NOTICE. * rather than _doing_it_wrong(), which triggers an E_USER_NOTICE.
*/ */
trigger_error( wp_trigger_error(
'',
sprintf( sprintf(
/* translators: 1: The function name, 2: The argument number, 3: The argument name, 4: The expected type, 5: The provided type. */ /* translators: 1: The function name, 2: The argument number, 3: The argument name, 4: The expected type, 5: The provided type. */
__( 'Warning: %1$s expects parameter %2$s (%3$s) to be a %4$s, %5$s given.' ), __( 'Warning: %1$s expects parameter %2$s (%3$s) to be a %4$s, %5$s given.' ),

View File

@ -4611,7 +4611,8 @@ function wp_json_file_decode( $filename, $options = array() ) {
$filename = wp_normalize_path( realpath( $filename ) ); $filename = wp_normalize_path( realpath( $filename ) );
if ( ! $filename ) { if ( ! $filename ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Path to the JSON file. */ /* translators: %s: Path to the JSON file. */
__( "File %s doesn't exist!" ), __( "File %s doesn't exist!" ),
@ -4625,7 +4626,8 @@ function wp_json_file_decode( $filename, $options = array() ) {
$decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] ); $decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] );
if ( JSON_ERROR_NONE !== json_last_error() ) { if ( JSON_ERROR_NONE !== json_last_error() ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: 1: Path to the JSON file, 2: Error message. */ /* translators: 1: Path to the JSON file, 2: Error message. */
__( 'Error when decoding a JSON file at path %1$s: %2$s' ), __( 'Error when decoding a JSON file at path %1$s: %2$s' ),
@ -8757,7 +8759,8 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul
*/ */
function clean_dirsize_cache( $path ) { function clean_dirsize_cache( $path ) {
if ( ! is_string( $path ) || empty( $path ) ) { if ( ! is_string( $path ) || empty( $path ) ) {
trigger_error( wp_trigger_error(
'',
sprintf( sprintf(
/* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */ /* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */
__( '%1$s only accepts a non-empty path string, received %2$s.' ), __( '%1$s only accepts a non-empty path string, received %2$s.' ),

View File

@ -147,7 +147,8 @@ function ms_subdomain_constants() {
); );
if ( $subdomain_error_warn ) { if ( $subdomain_error_warn ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: 1: VHOST, 2: SUBDOMAIN_INSTALL */ /* translators: 1: VHOST, 2: SUBDOMAIN_INSTALL */
__( '<strong>Conflicting values for the constants %1$s and %2$s.</strong> The value of %2$s will be assumed to be your subdomain configuration setting.' ), __( '<strong>Conflicting values for the constants %1$s and %2$s.</strong> The value of %2$s will be assumed to be your subdomain configuration setting.' ),

View File

@ -63,7 +63,8 @@ class MagpieRSS {
# Check if PHP xml isn't compiled # Check if PHP xml isn't compiled
# #
if ( ! function_exists('xml_parser_create') ) { if ( ! function_exists('xml_parser_create') ) {
return trigger_error( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ); wp_trigger_error( '', "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." );
return;
} }
$parser = xml_parser_create(); $parser = xml_parser_create();
@ -387,7 +388,7 @@ class MagpieRSS {
function error( $errormsg, $lvl = E_USER_WARNING ) { function error( $errormsg, $lvl = E_USER_WARNING ) {
if ( MAGPIE_DEBUG ) { if ( MAGPIE_DEBUG ) {
trigger_error( $errormsg, $lvl); wp_trigger_error('', $errormsg, $lvl);
} else { } else {
error_log( $errormsg, 0); error_log( $errormsg, 0);
} }
@ -823,7 +824,7 @@ class RSSCache {
function error ($errormsg, $lvl=E_USER_WARNING) { function error ($errormsg, $lvl=E_USER_WARNING) {
$this->ERROR = $errormsg; $this->ERROR = $errormsg;
if ( MAGPIE_DEBUG ) { if ( MAGPIE_DEBUG ) {
trigger_error( $errormsg, $lvl); wp_trigger_error( '', $errormsg, $lvl);
} }
else { else {
error_log( $errormsg, 0); error_log( $errormsg, 0);

View File

@ -514,7 +514,7 @@ function search_theme_directories( $force = false ) {
// Start with directories in the root of the active theme directory. // Start with directories in the root of the active theme directory.
$dirs = @ scandir( $theme_root ); $dirs = @ scandir( $theme_root );
if ( ! $dirs ) { if ( ! $dirs ) {
trigger_error( "$theme_root is not readable", E_USER_NOTICE ); wp_trigger_error( __FUNCTION__, "$theme_root is not readable" );
continue; continue;
} }
foreach ( $dirs as $dir ) { foreach ( $dirs as $dir ) {
@ -538,7 +538,7 @@ function search_theme_directories( $force = false ) {
*/ */
$sub_dirs = @ scandir( $theme_root . '/' . $dir ); $sub_dirs = @ scandir( $theme_root . '/' . $dir );
if ( ! $sub_dirs ) { if ( ! $sub_dirs ) {
trigger_error( "$theme_root/$dir is not readable", E_USER_NOTICE ); wp_trigger_error( __FUNCTION__, "$theme_root/$dir is not readable" );
continue; continue;
} }
foreach ( $sub_dirs as $sub_dir ) { foreach ( $sub_dirs as $sub_dir ) {

View File

@ -202,7 +202,8 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) {
$response = wp_remote_post( $url, $options ); $response = wp_remote_post( $url, $options );
if ( $ssl && is_wp_error( $response ) ) { if ( $ssl && is_wp_error( $response ) ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -440,7 +441,8 @@ function wp_update_plugins( $extra_stats = array() ) {
$raw_response = wp_remote_post( $url, $options ); $raw_response = wp_remote_post( $url, $options );
if ( $ssl && is_wp_error( $raw_response ) ) { if ( $ssl && is_wp_error( $raw_response ) ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
@ -721,7 +723,8 @@ function wp_update_themes( $extra_stats = array() ) {
$raw_response = wp_remote_post( $url, $options ); $raw_response = wp_remote_post( $url, $options );
if ( $ssl && is_wp_error( $raw_response ) ) { if ( $ssl && is_wp_error( $raw_response ) ) {
trigger_error( wp_trigger_error(
__FUNCTION__,
sprintf( sprintf(
/* translators: %s: Support forums URL. */ /* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-beta2-58408'; $wp_version = '6.6-beta2-58409';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.