Skip to content

Commit

Permalink
Check restricted plugin header fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Sep 26, 2024
1 parent 59b89db commit d002386
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 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 @@ -229,6 +229,41 @@ public function run( Check_Result $result ) {
}
}

$restricted_headers = array(
'BitbucketPluginURI' => 'Bitbucket Plugin URI',
'GistPluginURI' => 'Gist Plugin URI',
'GiteaPluginURI' => 'Gitea Plugin URI',
'GitHubPluginURI' => 'GitHub Plugin URI',
'GitLabPluginURI' => 'GitLab Plugin URI',
);

$plugin_data = get_file_data( $plugin_main_file, $restricted_headers, 'plugin' );

$found_headers = array();

foreach ( $restricted_headers as $restricted_key => $restricted_label ) {
if ( array_key_exists( $restricted_key, $plugin_data ) && ! empty( $plugin_data[ $restricted_key ] ) ) {
$found_headers[ $restricted_key ] = $restricted_label;
}
}

if ( ! empty( $found_headers ) ) {
$this->add_result_error_for_file(
$result,
sprintf(
/* translators: %s: header fields */
__( 'Restricted plugin header field(s) found: %s', 'plugin-check' ),
"'" . implode( "', '", array_values( $found_headers ) ) . "'"
),
'plugin_header_restricted_fields',
$plugin_main_file,
0,
0,
'',
7
);
}

if ( ! $result->plugin()->is_single_file_plugin() ) {
if ( ! empty( $plugin_header['TextDomain'] ) ) {
$plugin_slug = $result->plugin()->slug();
Expand Down

0 comments on commit d002386

Please sign in to comment.