[wp-trac] [WordPress Trac] #50787: Consolidate the logic for displaying WP & PHP compatibility messages for themes
WordPress Trac
noreply at wordpress.org
Wed Oct 14 21:55:47 UTC 2020
#50787: Consolidate the logic for displaying WP & PHP compatibility messages for
themes
-------------------------------------------------+-------------------------
Reporter: SergeyBiryukov | Owner:
| SergeyBiryukov
Type: enhancement | Status: accepted
Priority: normal | Milestone: 5.6
Component: Site Health | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback needs- | Focuses:
testing | administration
-------------------------------------------------+-------------------------
Comment (by hellofromTonya):
Revising my performance note above.
The last 3 string elements are dynamic, i.e. build from the injected
`$name`. if no name is passed to the function, then we can skip building
those last 3 elements. It's a tiny tiny performance boost. Pulling it all
together, the function might look like this:
{{{
/**
* Return the requested compatibility string, when available.
*
* @since 5.6.0
*
* @param string $key The key for the particular string.
* Default is false.
* @param string $name Plugin or theme name.
*
* @return string The appropriate compatibilty string.
*/
function wp_get_compatibility_string( $key = false, $name = '' ) {
static $strings = [];
if ( empty( $string ) ) {
$strings = [
'theme_incompatible_wp_php' => __( 'This
theme doesn’t work with your versions of WordPress and PHP.' ),
'plugin_incompatible_wp_php' => __( 'This
plugin doesn’t work with your versions of WordPress and PHP.' ),
'core_update_incompatible_wp_php' => __( 'This
update doesn’t work with your versions of WordPress and PHP.' ),
'theme_incompatible_wp' => __( 'This
theme doesn’t work with your version of WordPress.' ),
'plugin_incompatible_wp' => __( 'This
plugin doesn’t work with your version of WordPress.' ),
'core_update_incompatible_wp' => __( 'This
update doesn’t work with your version of WordPress.' ),
'theme_incompatible_php' => __( 'This
theme doesn’t work with your version of PHP.' ),
'plugin_incompatible_php' => __( 'This
plugin doesn’t work with your version of PHP.' ),
'core_update_incompatible_php' => __( 'This
update doesn’t work with your version of PHP.' ),
];
}
if ( array_key_exists( $key, $strings ) ) {
return $strings[ $key ];
}
if ( $name ) {
$names = [
/* translators: 1: plugin or theme name */
'update_incompatible_wp_php' => sprintf( __(
'There is a new version of %s available, but it doesn’t work with
your versions of WordPress and PHP.' ), $name ),
/* translators: 1: plugin or theme name */
'update_incompatible_wp' => sprintf( __(
'There is a new version of %s available, but it doesn’t work with
your version of WordPress.' ), $name ),
/* translators: 1: plugin or theme name */
'update_incompatible_php' => sprintf( __(
'There is a new version of %s available, but it doesn’t work with
your version of PHP.' ), $name ),
];
if ( array_key_exists( $key, $names ) ) {
return $names[ $key ];
}
}
return '';
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50787#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list