<?php
function is_wp_version_compatible( $required ) {
$wp_version = '6.4.1';
// Strip off any -alpha, -RC, -beta, -src suffixes.
list( $version ) = explode( '-', $wp_version );
if ( is_string( $required ) && substr_count( $required, '.' ) > 1 && str_ends_with( $required, '.0' ) ) {
error_log(__FUNCTION__ . '(): ' .
/* translators: s: version string sent to function */
sprintf( '`%s` Not a valid WordPress version string.', $required ) );
$required = rtrim( $required, '.0' );
}
return empty( $required ) || version_compare( $version, $required, '>=' );
}
echo is_wp_version_compatible('6.4');
echo is_wp_version_compatible('3.0');
echo is_wp_version_compatible('3.0.0');
echo is_wp_version_compatible('6.4.1');
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- 1111is_wp_version_compatible(): `3.0.0` Not a valid WordPress version string.
preferences:
67.75 ms | 406 KiB | 5 Q