WPDB: Call `wp_load_translations_early()` in `wpdb::query()` and `wpdb::process_fields()`.

For consistency and simplification, replaces the `function_exists( '__' )` checks with `wp_load_translations_early()` to make sure i18n functions are available. This change removes the extra code introduced in [52176] for using non-translated error messages when `__()` is not available.

Improves the plural versions of the error messages.

For performance, when there are more than one problem field, uses `reset()` to populate the field in the error message.

Follow-up to [52176], [52195].

Props sergeybiryukov, hellofromTonya.
Fixes #32315.
Built from https://develop.svn.wordpress.org/trunk@52218


git-svn-id: http://core.svn.wordpress.org/trunk@51810 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-11-19 19:00:00 +00:00
parent dc1136b94e
commit 807cba060e
2 changed files with 18 additions and 22 deletions

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-52217';
$wp_version = '5.9-alpha-52218';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -2017,11 +2017,9 @@ class wpdb {
$this->insert_id = 0;
$this->last_query = $query;
if ( function_exists( '__' ) ) {
wp_load_translations_early();
$this->last_error = __( 'WordPress database error: Could not perform query because it contains invalid data.' );
} else {
$this->last_error = 'WordPress database error: Could not perform query because it contains invalid data.';
}
return false;
}
@ -2550,23 +2548,21 @@ class wpdb {
}
}
if ( 1 === count( $problem_fields ) ) {
if ( function_exists( '__' ) ) {
/* translators: %s Database field where the error occurred. */
$message = __( 'WordPress database error: Processing the value for the following field failed: %s. The supplied value may be too long or contains invalid data.' );
} else {
$message = 'WordPress database error: Processing the value for the following field failed: %s. The supplied value may be too long or contains invalid data.';
}
} else {
if ( function_exists( '__' ) ) {
/* translators: %s Database fields where the error occurred. */
$message = __( 'WordPress database error: Processing the value for the following fields failed: %s. The supplied value may be too long or contains invalid data.' );
} else {
$message = 'WordPress database error: Processing the value for the following fields failed: %s. The supplied value may be too long or contains invalid data.';
}
}
wp_load_translations_early();
$this->last_error = sprintf( $message, implode( ', ', $problem_fields ) );
if ( 1 === count( $problem_fields ) ) {
$this->last_error = sprintf(
/* translators: %s: Database field where the error occurred. */
__( 'WordPress database error: Processing the value for the following field failed: %s. The supplied value may be too long or contains invalid data.' ),
reset( $problem_fields )
);
} else {
$this->last_error = sprintf(
/* translators: %s: Database fields where the error occurred. */
__( 'WordPress database error: Processing the values for the following fields failed: %s. The supplied values may be too long or contain invalid data.' ),
implode( ', ', $problem_fields )
);
}
return false;
}