Skip to content

Commit

Permalink
Merge pull request #675 from WordPress/add-network-header-validation
Browse files Browse the repository at this point in the history
Add validation for Network plugin header field
  • Loading branch information
davidperezgar authored Sep 27, 2024
2 parents ed396c3 + aefc44b commit e6b4c1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ public function run( Check_Result $result ) {
}
}

if ( ! empty( $plugin_header['Network'] ) ) {
if ( 'true' !== strtolower( $plugin_header['Network'] ) ) {
$this->add_result_warning_for_file(
$result,
sprintf(
/* translators: %s: plugin header field */
__( 'The "%s" header in the plugin file is not valid. Can only be set to true, and should be left out when not needed.', 'plugin-check' ),
esc_html( $labels['Network'] )
),
'plugin_header_invalid_network',
$plugin_main_file,
0,
0,
'https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields',
6
);
}
}

if ( ! empty( $plugin_header['RequiresWP'] ) ) {
if ( ! preg_match( '!^\d+\.\d(\.\d+)?$!', $plugin_header['RequiresWP'] ) ) {
$this->add_result_warning_for_file(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-mismathed-textdomain-here
* Domain Path: /nonexistent-folder
* Network: random-value
* GitHub Plugin URI: johndoe/package
* Requires Plugins: Example Plugin, OtherPlugin
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function test_run_with_errors() {
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_php' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'textdomain_mismatch' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_nonexistent_domain_path' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_network' ) ) );

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

0 comments on commit e6b4c1d

Please sign in to comment.