From 99646663d6a81f3237bf35aa94f28b589dbd0d4b Mon Sep 17 00:00:00 2001 From: sandros Date: Sat, 26 Sep 2026 22:32:01 +0200 Subject: [PATCH] Wordpress 7+ --- .github/workflows/tests.yml | 2 +- CHANGELOG.md | 7 ++++++- RoboFile.php | 2 +- composer.json | 4 ++-- laps.php | 9 +++++---- src/Manager/Asset_Manager.php | 2 +- tests/Manager/AssetTest.php | 24 ++++++++++++++++++++++++ 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 919a636..f05b839 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.2' + php-version: '7.4' tools: phpunit:8,psalm:4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ecb89b..5bf3366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Changed +- raised minimum required PHP version to 7.4 to align with WordPress 7.0+ +- added `Requires at least: 7.0` to plugin header +- checked user permissions (`laps_can_see`) before enqueueing assets in `Asset_Manager` + ## 3.3.7 - 2022-06-16 ### Fixed @@ -225,4 +230,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## 1.0 - 2013-04-22 ### Added - - Initial public release \ No newline at end of file + - Initial public release diff --git a/RoboFile.php b/RoboFile.php index 9f761f0..9c09fc9 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -82,7 +82,7 @@ class RoboFile extends \Robo\Tasks { * * @param string $php PHP version to target. */ - public function makeArchive( $php = '7.2.5' ): void { + public function makeArchive( $php = '7.4' ): void { $composer = json_decode( file_get_contents( __DIR__ . '/composer.json' ) ); $package = $composer->name; diff --git a/composer.json b/composer.json index 241f6dd..ecf32e7 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } }, "require" : { - "php" : "^7.2.5 || ^8", + "php" : "^7.4 || ^8", "composer/installers": "^1.6 || ^2", "symfony/stopwatch" : "^4.2.1", "mustache/mustache" : "^2.14.1", @@ -55,7 +55,7 @@ "composer/installers": true }, "platform": { - "php": "7.2.5" + "php": "7.4" } } } diff --git a/laps.php b/laps.php index 7dd21d2..6c2d240 100644 --- a/laps.php +++ b/laps.php @@ -5,9 +5,10 @@ Plugin Name: Laps Plugin URI: https://github.com/Rarst/laps Description: Light WordPress profiler. Author: Andrey “Rarst” Savchenko -Version: 3.3.7 +Version: 3.3.7 Author URI: https://www.rarst.net/ -Requires PHP: 7.1.3 +Requires at least: 7.0 +Requires PHP: 7.4 Update URI: false License: MIT */ @@ -20,8 +21,8 @@ if ( ! class_exists( '\Rarst\Laps\Plugin' ) ) { trigger_error( 'Laps not fully installed! Please install with Composer or download full release archive.', E_USER_ERROR ); } -if ( PHP_VERSION_ID < 70103 ) { - trigger_error( 'Laps requires PHP version >=7.1.3.', E_USER_ERROR ); +if ( PHP_VERSION_ID < 70400 ) { + trigger_error( 'Laps requires PHP version >=7.4.', E_USER_ERROR ); } $laps = new \Rarst\Laps\Plugin(); diff --git a/src/Manager/Asset_Manager.php b/src/Manager/Asset_Manager.php index f5bea3c..dcfc758 100644 --- a/src/Manager/Asset_Manager.php +++ b/src/Manager/Asset_Manager.php @@ -26,7 +26,7 @@ class Asset_Manager { wp_register_script( 'laps', plugins_url( "public/js/laps{$suffix}.js", dirname( __DIR__ ) ), [ 'jquery' ], '3.4.0', true ); wp_register_style( 'laps', plugins_url( "public/css/laps{$suffix}.css", dirname( __DIR__ ) ) ); - if ( is_admin_bar_showing() ) { + if ( is_admin_bar_showing() && apply_filters( 'laps_can_see', current_user_can( 'manage_options' ) ) ) { wp_enqueue_script( 'laps' ); wp_enqueue_style( 'laps' ); } diff --git a/tests/Manager/AssetTest.php b/tests/Manager/AssetTest.php index 53b1c9f..25c5121 100644 --- a/tests/Manager/AssetTest.php +++ b/tests/Manager/AssetTest.php @@ -36,9 +36,33 @@ class AssetTest extends LapsTestCase { Functions\expect( 'wp_register_style' )->once(); Functions\expect( 'plugins_url' )->zeroOrMoreTimes(); Functions\expect( 'is_admin_bar_showing' )->once()->andReturn( true ); + Functions\expect( 'current_user_can' ) + ->once() + ->with( 'manage_options' ) + ->andReturn( true ); Functions\expect( 'wp_enqueue_script' )->once(); Functions\expect( 'wp_enqueue_style' )->once(); $manager->enqueue_scripts(); } + + /** + * @covers ::enqueue_scripts + * @depends test__construct + */ + public function testEnqueue_scripts_hidden( Asset_Manager $manager ) { + + Functions\expect( 'wp_register_script' )->once(); + Functions\expect( 'wp_register_style' )->once(); + Functions\expect( 'plugins_url' )->zeroOrMoreTimes(); + Functions\expect( 'is_admin_bar_showing' )->once()->andReturn( true ); + Functions\expect( 'current_user_can' ) + ->once() + ->with( 'manage_options' ) + ->andReturn( false ); + Functions\expect( 'wp_enqueue_script' )->never(); + Functions\expect( 'wp_enqueue_style' )->never(); + + $manager->enqueue_scripts(); + } }