Skip to content

Commit

Permalink
Merge pull request #630 from WordPress/improve-required-plugins-header
Browse files Browse the repository at this point in the history
Co-authored-by: ernilambar <[email protected]>
Co-authored-by: davidperezgar <[email protected]>
Co-authored-by: swissspidy <[email protected]>
  • Loading branch information
4 people authored Sep 13, 2024
2 parents 4964dfc + a5b65ed commit 7b3bfa4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function run( Check_Result $result ) {
}

if ( ! empty( $plugin_header['RequiresPlugins'] ) ) {
if ( ! preg_match( '/^[a-z0-9-]+(?:,[a-z0-9-]+)*$/', $plugin_header['RequiresPlugins'] ) ) {
if ( ! preg_match( '/^[a-z0-9-]+(?:,\s*[a-z0-9-]+)*$/', $plugin_header['RequiresPlugins'] ) ) {
$this->add_result_warning_for_file(
$result,
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-unfiltered-uploads-errors
* Requires Plugins: woocommerce, contact-form-7
*
* @package test-plugin-unfiltered-uploads-errors
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,23 @@ public function test_run_with_errors() {
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) );
}
}

public function test_run_with_valid_requires_plugins_header() {
/*
* Test plugin has following valid header.
* Requires Plugins: woocommerce, contact-form-7
*/

$check = new Plugin_Header_Fields_Check();
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-unfiltered-uploads-with-errors/load.php' );
$check_result = new Check_Result( $check_context );

$check->run( $check_result );

$warnings = $check_result->get_warnings();

if ( is_wp_version_compatible( '6.5' ) ) {
$this->assertCount( 0, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) );
}
}
}

0 comments on commit 7b3bfa4

Please sign in to comment.