Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump minimum required PHP version to 7.0 and minimum required WP version to 6.3 #851

Merged
merged 8 commits into from Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -7,7 +7,7 @@ Thank you for your interest in contributing to the Performance Lab plugin! Compl
In general, all code must follow the [WordPress Coding Standards and best practices](https://developer.wordpress.org/coding-standards/). All code in the Performance Lab plugin must follow these requirements:

- **WordPress**: As of Performance Lab v1.6.0, released October 17, 2022, the plugin's minimum WordPress version requirement is 6.0.
- **PHP**: Always match the latest WordPress version. The minimum required version right now is 5.6.
- **PHP**: Always match the latest WordPress version. The minimum required version right now is 7.0.


## Guidelines
Expand Down
4 changes: 2 additions & 2 deletions bin/plugin/commands/build-plugins.js
Expand Up @@ -137,8 +137,8 @@ async function updatePluginHeader( settings ) {
* Plugin Name: ${ name }
* Plugin URI: https://github.com/WordPress/performance/tree/trunk/modules/${ modulePath }
* Description: ${ description }
* Requires at least: 6.1
* Requires PHP: 5.6
* Requires at least: 6.3
* Requires PHP: 7.0
* Version: ${ version }
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -16,7 +16,6 @@
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/extension-installer": "^1.3.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^4|^5|^6|^7|^8|^9",
"squizlabs/php_codesniffer": "^3.5",
"szepeviktor/phpstan-wordpress": "^1.3.0",
"wp-coding-standards/wpcs": "^3.0.0",
Expand All @@ -28,7 +27,7 @@
},
"require": {
"composer/installers": "~1.0",
"php": ">=5.6|^7|^8"
"php": ">=7|^8"
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
},
"scripts": {
"phpstan": "phpstan analyze --ansi --memory-limit=2048M",
Expand Down
224 changes: 116 additions & 108 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions load.php
Expand Up @@ -3,8 +3,8 @@
* Plugin Name: Performance Lab
* Plugin URI: https://github.com/WordPress/performance
* Description: Performance plugin from the WordPress Performance Team, which is a collection of standalone performance modules.
* Requires at least: 6.1
* Requires PHP: 5.6
* Requires at least: 6.3
* Requires PHP: 7.0
* Version: 2.6.1
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
Expand Down
78 changes: 0 additions & 78 deletions modules/images/dominant-color-images/hooks.php
Expand Up @@ -153,84 +153,6 @@ function dominant_color_img_tag_add_dominant_color( $filtered_image, $context, $
}
add_filter( 'wp_content_img_tag', 'dominant_color_img_tag_add_dominant_color', 20, 3 );

// We don't need to use this filter anymore as the filter wp_content_img_tag is used instead.
if ( version_compare( '6', $GLOBALS['wp_version'], '>=' ) ) {

/**
* Filter the content to allow us to filter the image tags.
*
* @since 1.2.0
*
* @param string $content The content to filter.
* @param string $context The context of the content.
* @return string The updated $content.
*/
function dominant_color_filter_content_tags( $content, $context = null ) {
if ( null === $context ) {
$context = current_filter();
}

if ( ! preg_match_all( '/<(img)\s[^>]+>/', $content, $matches, PREG_SET_ORDER ) ) {
return $content;
}

// List of the unique `img` tags found in $content.
$images = array();

foreach ( $matches as $match ) {
list( $tag, $tag_name ) = $match;

switch ( $tag_name ) {
case 'img':
if ( preg_match( '/wp-image-([0-9]+)/i', $tag, $class_id ) ) {
$attachment_id = absint( $class_id[1] );

if ( $attachment_id ) {
// If exactly the same image tag is used more than once, overwrite it.
// All identical tags will be replaced later with 'str_replace()'.
$images[ $tag ] = $attachment_id;
break;
}
}
$images[ $tag ] = 0;
break;
}
}

// Reduce the array to unique attachment IDs.
$attachment_ids = array_unique( array_filter( array_values( $images ) ) );

if ( count( $attachment_ids ) > 1 ) {
/*
* Warm the object cache with post and meta information for all found.
* images to avoid making individual database calls.
*/
_prime_post_caches( $attachment_ids, false, true );
}

foreach ( $matches as $match ) {
// Filter an image match.
if ( empty( $images[ $match[0] ] ) ) {
continue;
}

$filtered_image = $match[0];
$attachment_id = $images[ $match[0] ];
$filtered_image = dominant_color_img_tag_add_dominant_color( $filtered_image, $context, $attachment_id );

if ( null !== $filtered_image && $filtered_image !== $match[0] ) {
$content = str_replace( $match[0], $filtered_image, $content );
}
}
return $content;
}

$filters = array( 'the_content', 'the_excerpt', 'widget_text_content', 'widget_block_content' );
foreach ( $filters as $filter ) {
add_filter( $filter, 'dominant_color_filter_content_tags', 20 );
}
}

/**
* Add CSS needed for to show the dominant color as an image background.
*
Expand Down
4 changes: 2 additions & 2 deletions modules/images/dominant-color-images/readme.txt
@@ -1,9 +1,9 @@
=== Dominant Color Images ===

Contributors: wordpressdotorg
Requires at least: 6.1
Requires at least: 6.3
Tested up to: 6.3
Requires PHP: 5.6
Requires PHP: 7.0
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
4 changes: 2 additions & 2 deletions modules/images/fetchpriority/readme.txt
@@ -1,9 +1,9 @@
=== Fetchpriority ===

Contributors: wordpressdotorg
Requires at least: 6.1
Requires at least: 6.3
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
Tested up to: 6.3
Requires PHP: 5.6
Requires PHP: 7.0
Stable tag: 1.1.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
14 changes: 4 additions & 10 deletions modules/images/webp-uploads/hooks.php
Expand Up @@ -745,26 +745,20 @@ function webp_uploads_get_image_sizes_additional_mime_type_support() {
/**
* Updates the quality of WebP image sizes generated by WordPress to 82.
*
* Prior to WordPress 6.1, the MIME type was not correctly provided to this filter, so for those versions this function
* simply returns 82 universally (since all other MIME types already use 82 anyway).
*
* @since 1.7.0
*
* @global string $wp_version The WordPress version string.
* @since n.e.x.t Bump minimum WP to 6.3 so remove WP 6.1 related checks.
*
* @param int $quality Quality level between 1 (low) and 100 (high).
* @param string $mime_type Image mime type.
* @return int The updated quality for mime types.
*/
function webp_uploads_modify_webp_quality( $quality, $mime_type ) {
global $wp_version;

// Below WP 6.1 or for WebP images, always return 82 (other MIME types were already using 82 by default anyway).
if ( version_compare( $wp_version, '6.1', '<' ) || 'image/webp' === $mime_type ) {
// For WebP images, always return 82 (other MIME types were already using 82 by default anyway).
if ( 'image/webp' === $mime_type ) {
return 82;
}

// Return default quality for non-WebP images in WP 6.1+.
// Return default quality for non-WebP images in WP.
return $quality;
}
add_filter( 'wp_editor_set_quality', 'webp_uploads_modify_webp_quality', 10, 2 );
Expand Down
4 changes: 0 additions & 4 deletions modules/images/webp-uploads/image-edit.php
Expand Up @@ -433,10 +433,6 @@ function webp_uploads_restore_image( $attachment_id, $data ) {
* @return bool True if editing image thumbnails is enabled, false otherwise.
*/
function webp_uploads_image_edit_thumbnails_separately() {
if ( version_compare( get_bloginfo( 'version' ), '6.3', '<' ) ) {
return true;
}

/** This filter is documented in wp-admin/includes/image-edit.php */
return (bool) apply_filters( 'image_edit_thumbnails_separately', false );
}
4 changes: 2 additions & 2 deletions modules/images/webp-uploads/readme.txt
@@ -1,9 +1,9 @@
=== WebP Uploads ===

Contributors: wordpressdotorg
Requires at least: 6.1
Requires at least: 6.3
Tested up to: 6.3
Requires PHP: 5.6
Requires PHP: 7.0
Stable tag: 1.0.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Expand Up @@ -3,7 +3,7 @@
<description>Sniffs for WordPress plugins, with minor modifications for Performance</description>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.6-"/>
<config name="testVersion" value="7.0-"/>

<rule ref="WordPress-Docs"/>
<rule ref="WordPress-Extra">
Expand Down
2 changes: 1 addition & 1 deletion plugin-tests/composer.json
Expand Up @@ -10,7 +10,7 @@
},
"require": {
"composer/installers": "~1.0",
"php": ">=5.6|^7|^8"
"php": ">=7|^8"
},
"config": {
"allow-plugins": {
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
@@ -1,9 +1,9 @@
=== Performance Lab ===

Contributors: wordpressdotorg
Requires at least: 6.1
Requires at least: 6.3
Tested up to: 6.3
Requires PHP: 5.6
Requires PHP: 7.0
Stable tag: 2.6.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
3 changes: 1 addition & 2 deletions server-timing/defaults.php
Expand Up @@ -304,8 +304,7 @@ static function ( $hook_name ) use ( $hooks_to_measure ) {
)
);
},
// phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
defined( 'PHP_INT_MIN' ) ? PHP_INT_MIN : ~PHP_INT_MAX
PHP_INT_MIN
);
}

Expand Down
7 changes: 1 addition & 6 deletions tests/modules/images/webp-uploads/load-tests.php
Expand Up @@ -977,12 +977,7 @@ public function it_should_return_correct_quality_for_mime_types() {
global $wp_version;
$this->assertSame( 82, webp_uploads_modify_webp_quality( 90, 'image/webp' ), 'WebP image quality should always be 82.' );
$this->assertSame( 82, webp_uploads_modify_webp_quality( 82, 'image/webp' ), 'WebP image quality should always be 82.' );

if ( version_compare( $wp_version, '6.1', '<' ) ) {
$this->assertSame( 82, webp_uploads_modify_webp_quality( 86, 'image/jpeg' ), 'JPEG image quality should always return 82 quality for WP version lower than 6.1.' );
} else {
$this->assertSame( 80, webp_uploads_modify_webp_quality( 80, 'image/jpeg' ), 'JPEG image quality should return default quality provided from WP filter wp_editor_set_quality.' );
}
$this->assertSame( 80, webp_uploads_modify_webp_quality( 80, 'image/jpeg' ), 'JPEG image quality should return default quality provided from WP filter wp_editor_set_quality.' );
}

/**
Expand Down