Code Modernization: Remove all code using a version_compare()
with a PHP version older than PHP 5.6.
Props jrf. Fixes #48074. git-svn-id: https://develop.svn.wordpress.org/trunk@46214 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
92d70ed696
commit
099adc0243
@ -8,16 +8,6 @@
|
|||||||
<!-- Default test suite to run all tests -->
|
<!-- Default test suite to run all tests -->
|
||||||
<testsuite name="default">
|
<testsuite name="default">
|
||||||
<directory suffix=".php">tests/phpunit/tests</directory>
|
<directory suffix=".php">tests/phpunit/tests</directory>
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/actions/closures.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/image/editor.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorGd.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorImagick.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/oembed/headers.php</file>
|
|
||||||
<exclude>tests/phpunit/tests/actions/closures.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/image/editor.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/image/editorGd.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/image/editorImagick.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/oembed/headers.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
|
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<!-- Sets the DOING_AUTOSAVE constant, so needs to be run last -->
|
<!-- Sets the DOING_AUTOSAVE constant, so needs to be run last -->
|
||||||
|
@ -1376,13 +1376,6 @@ final class WP_Customize_Manager {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// In PHP < 5.6 filesize() returns 0 for the temp files unless we clear the file status cache.
|
|
||||||
// Technically, PHP < 5.6.0 || < 5.5.13 || < 5.4.29 but no need to be so targeted.
|
|
||||||
// See https://bugs.php.net/bug.php?id=65701
|
|
||||||
if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
|
|
||||||
clearstatcache();
|
|
||||||
}
|
|
||||||
|
|
||||||
$attachment_id = media_handle_sideload( $file_array, 0, null, $attachment_post_data );
|
$attachment_id = media_handle_sideload( $file_array, 0, null, $attachment_post_data );
|
||||||
if ( is_wp_error( $attachment_id ) ) {
|
if ( is_wp_error( $attachment_id ) ) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -199,13 +199,8 @@ class WP_Locale {
|
|||||||
/* translators: $thousands_sep argument for https://secure.php.net/number_format, default is ',' */
|
/* translators: $thousands_sep argument for https://secure.php.net/number_format, default is ',' */
|
||||||
$thousands_sep = __( 'number_format_thousands_sep' );
|
$thousands_sep = __( 'number_format_thousands_sep' );
|
||||||
|
|
||||||
if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) {
|
// Replace space with a non-breaking space to avoid wrapping.
|
||||||
// Replace space with a non-breaking space to avoid wrapping.
|
$thousands_sep = str_replace( ' ', ' ', $thousands_sep );
|
||||||
$thousands_sep = str_replace( ' ', ' ', $thousands_sep );
|
|
||||||
} else {
|
|
||||||
// PHP < 5.4.0 does not support multiple bytes in thousands separator.
|
|
||||||
$thousands_sep = str_replace( array( ' ', ' ' ), ' ', $thousands_sep );
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep;
|
$this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep;
|
||||||
|
|
||||||
|
@ -5572,15 +5572,10 @@ function _print_emoji_detection_script() {
|
|||||||
* @return string The encoded content.
|
* @return string The encoded content.
|
||||||
*/
|
*/
|
||||||
function wp_encode_emoji( $content ) {
|
function wp_encode_emoji( $content ) {
|
||||||
$emoji = _wp_emoji_list( 'partials' );
|
$emoji = _wp_emoji_list( 'partials' );
|
||||||
$compat = version_compare( phpversion(), '5.4', '<' );
|
|
||||||
|
|
||||||
foreach ( $emoji as $emojum ) {
|
foreach ( $emoji as $emojum ) {
|
||||||
if ( $compat ) {
|
$emoji_char = html_entity_decode( $emojum );
|
||||||
$emoji_char = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
|
|
||||||
} else {
|
|
||||||
$emoji_char = html_entity_decode( $emojum );
|
|
||||||
}
|
|
||||||
if ( false !== strpos( $content, $emoji_char ) ) {
|
if ( false !== strpos( $content, $emoji_char ) ) {
|
||||||
$content = preg_replace( "/$emoji_char/", $emojum, $content );
|
$content = preg_replace( "/$emoji_char/", $emojum, $content );
|
||||||
}
|
}
|
||||||
@ -5616,14 +5611,9 @@ function wp_staticize_emoji( $text ) {
|
|||||||
|
|
||||||
// Quickly narrow down the list of emoji that might be in the text and need replacing.
|
// Quickly narrow down the list of emoji that might be in the text and need replacing.
|
||||||
$possible_emoji = array();
|
$possible_emoji = array();
|
||||||
$compat = version_compare( phpversion(), '5.4', '<' );
|
|
||||||
foreach ( $emoji as $emojum ) {
|
foreach ( $emoji as $emojum ) {
|
||||||
if ( false !== strpos( $text, $emojum ) ) {
|
if ( false !== strpos( $text, $emojum ) ) {
|
||||||
if ( $compat ) {
|
$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
|
||||||
$possible_emoji[ $emojum ] = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
|
|
||||||
} else {
|
|
||||||
$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6004,12 +6004,7 @@ function wp_allowed_protocols() {
|
|||||||
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
|
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
|
||||||
static $truncate_paths;
|
static $truncate_paths;
|
||||||
|
|
||||||
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) {
|
$trace = debug_backtrace( false );
|
||||||
$trace = debug_backtrace( false );
|
|
||||||
} else {
|
|
||||||
$trace = debug_backtrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
$caller = array();
|
$caller = array();
|
||||||
$check_class = ! is_null( $ignore_class );
|
$check_class = ! is_null( $ignore_class );
|
||||||
$skip_frames++; // skip this function
|
$skip_frames++; // skip this function
|
||||||
|
@ -465,12 +465,8 @@ class WpdbExposedMethodsForTesting extends wpdb {
|
|||||||
function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) {
|
function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) {
|
||||||
$saved_config = ini_get( 'pcre.backtrack_limit' );
|
$saved_config = ini_get( 'pcre.backtrack_limit' );
|
||||||
|
|
||||||
// Attempt to prevent PHP crashes. Adjust these lower when needed.
|
// Attempt to prevent PHP crashes. Adjust these lower when needed.
|
||||||
if ( version_compare( phpversion(), '5.4.8', '>' ) ) {
|
$limit = 1000000;
|
||||||
$limit = 1000000;
|
|
||||||
} else {
|
|
||||||
$limit = 20000; // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem.
|
// Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem.
|
||||||
for ( $i = 4; $i <= $limit; $i *= 2 ) {
|
for ( $i = 4; $i <= $limit; $i *= 2 ) {
|
||||||
|
@ -12,14 +12,6 @@
|
|||||||
<!-- Default test suite to run all tests -->
|
<!-- Default test suite to run all tests -->
|
||||||
<testsuite name="default">
|
<testsuite name="default">
|
||||||
<directory suffix=".php">tests</directory>
|
<directory suffix=".php">tests</directory>
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/actions/closures.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/image/editor.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorGd.php</file>
|
|
||||||
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorImagick.php</file>
|
|
||||||
<exclude>tests/phpunit/tests/actions/closures.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/image/editor.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/image/editorGd.php</exclude>
|
|
||||||
<exclude>tests/phpunit/tests/image/editorImagick.php</exclude>
|
|
||||||
<!-- Path relative to the checkout root, for PHPUnit 3.6.x -->
|
<!-- Path relative to the checkout root, for PHPUnit 3.6.x -->
|
||||||
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
|
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
|
||||||
<!-- Same path relative to the configuration file, for PHPUnit 4.0.0+ -->
|
<!-- Same path relative to the configuration file, for PHPUnit 4.0.0+ -->
|
||||||
|
@ -24,10 +24,6 @@ class Tests_Admin_WpPrivacyRequestsTable extends WP_UnitTestCase {
|
|||||||
* @return PHPUnit_Framework_MockObject_MockObject|WP_Privacy_Requests_Table $instance Mocked class instance.
|
* @return PHPUnit_Framework_MockObject_MockObject|WP_Privacy_Requests_Table $instance Mocked class instance.
|
||||||
*/
|
*/
|
||||||
public function get_mocked_class_instance() {
|
public function get_mocked_class_instance() {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
|
|
||||||
}
|
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'plural' => 'privacy_requests',
|
'plural' => 'privacy_requests',
|
||||||
'singular' => 'privacy_request',
|
'singular' => 'privacy_request',
|
||||||
|
@ -249,11 +249,6 @@ EOT;
|
|||||||
$this->markTestSkipped( 'The intl extension is not loaded. ResourceBundle not tested for is_countable().' );
|
$this->markTestSkipped( 'The intl extension is not loaded. ResourceBundle not tested for is_countable().' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
|
|
||||||
$this->markTestSkipped( 'ResourceBundle is only countable in PHP 5.4+' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertTrue( is_countable( new ResourceBundle( 'en', null ) ) );
|
$this->assertTrue( is_countable( new ResourceBundle( 'en', null ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1083,9 +1083,7 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add global namespace prefix to check #41488.
|
// Add global namespace prefix to check #41488.
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
|
$original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
|
||||||
$original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$args = $menus->filter_wp_nav_menu_args( $original_args );
|
$args = $menus->filter_wp_nav_menu_args( $original_args );
|
||||||
|
|
||||||
|
@ -482,10 +482,6 @@ class Tests_DB_Charset extends WP_UnitTestCase {
|
|||||||
* @ticket 21212
|
* @ticket 21212
|
||||||
*/
|
*/
|
||||||
function test_strip_invalid_text( $data, $expected, $message ) {
|
function test_strip_invalid_text( $data, $expected, $message ) {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) && stristr( php_uname( 's' ), 'win' ) ) {
|
|
||||||
$this->markTestSkipped( 'This test fails in PHP 5.2 on Windows. See https://core.trac.wordpress.org/ticket/31262' );
|
|
||||||
}
|
|
||||||
|
|
||||||
$charset = self::$_wpdb->charset;
|
$charset = self::$_wpdb->charset;
|
||||||
if ( isset( $data[0]['connection_charset'] ) ) {
|
if ( isset( $data[0]['connection_charset'] ) ) {
|
||||||
$new_charset = $data[0]['connection_charset'];
|
$new_charset = $data[0]['connection_charset'];
|
||||||
|
@ -918,10 +918,6 @@ class Tests_Functions extends WP_UnitTestCase {
|
|||||||
* @ticket 28786
|
* @ticket 28786
|
||||||
*/
|
*/
|
||||||
function test_wp_json_encode_depth() {
|
function test_wp_json_encode_depth() {
|
||||||
if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
|
|
||||||
$this->markTestSkipped( 'json_encode() supports the $depth parameter in PHP 5.5+' );
|
|
||||||
};
|
|
||||||
|
|
||||||
$data = array( array( array( 1, 2, 3 ) ) );
|
$data = array( array( array( 1, 2, 3 ) ) );
|
||||||
$json = wp_json_encode( $data, 0, 1 );
|
$json = wp_json_encode( $data, 0, 1 );
|
||||||
$this->assertFalse( $json );
|
$this->assertFalse( $json );
|
||||||
|
@ -705,11 +705,6 @@ class Tests_Post_Query extends WP_UnitTestCase {
|
|||||||
* @dataProvider set_found_posts_provider
|
* @dataProvider set_found_posts_provider
|
||||||
*/
|
*/
|
||||||
public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) {
|
public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$q = new WP_Query(
|
$q = new WP_Query(
|
||||||
array(
|
array(
|
||||||
'post_type' => 'wptests_pt',
|
'post_type' => 'wptests_pt',
|
||||||
|
@ -491,10 +491,6 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function test_has_valid_params_json_error() {
|
public function test_has_valid_params_json_error() {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' );
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->request->set_header( 'Content-Type', 'application/json' );
|
$this->request->set_header( 'Content-Type', 'application/json' );
|
||||||
$this->request->set_body( '{"invalid": JSON}' );
|
$this->request->set_body( '{"invalid": JSON}' );
|
||||||
|
|
||||||
@ -507,10 +503,6 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
|||||||
|
|
||||||
|
|
||||||
public function test_has_valid_params_empty_json_no_error() {
|
public function test_has_valid_params_empty_json_no_error() {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' );
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->request->set_header( 'Content-Type', 'application/json' );
|
$this->request->set_header( 'Content-Type', 'application/json' );
|
||||||
$this->request->set_body( '' );
|
$this->request->set_body( '' );
|
||||||
|
|
||||||
|
@ -126,10 +126,6 @@ class Tests_Theme_Custom_Header extends WP_UnitTestCase {
|
|||||||
$this->assertFalse( has_custom_header() );
|
$this->assertFalse( has_custom_header() );
|
||||||
$this->assertEmpty( $html );
|
$this->assertEmpty( $html );
|
||||||
|
|
||||||
// ReflectionMethod::setAccessible is only available in PHP 5.3+
|
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// The container should always be returned in the Customizer preview.
|
// The container should always be returned in the Customizer preview.
|
||||||
$this->_set_customize_previewing( true );
|
$this->_set_customize_previewing( true );
|
||||||
$html = get_custom_header_markup();
|
$html = get_custom_header_markup();
|
||||||
@ -226,11 +222,6 @@ class Tests_Theme_Custom_Header extends WP_UnitTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_header_script_is_enqueued_by_the_custom_header_markup_without_video_when_previewing_in_customizer() {
|
function test_header_script_is_enqueued_by_the_custom_header_markup_without_video_when_previewing_in_customizer() {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_add_theme_support(
|
$this->_add_theme_support(
|
||||||
array(
|
array(
|
||||||
'video' => true,
|
'video' => true,
|
||||||
|
@ -479,11 +479,6 @@ class Test_WP_Widget_Media extends WP_UnitTestCase {
|
|||||||
* @covers WP_Widget_Media::has_content()
|
* @covers WP_Widget_Media::has_content()
|
||||||
*/
|
*/
|
||||||
function test_has_content() {
|
function test_has_content() {
|
||||||
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
|
|
||||||
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available for PHP 5.3+' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$attachment_id = self::factory()->attachment->create_object(
|
$attachment_id = self::factory()->attachment->create_object(
|
||||||
array(
|
array(
|
||||||
'file' => DIR_TESTDATA . '/images/canola.jpg',
|
'file' => DIR_TESTDATA . '/images/canola.jpg',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user