Skip to content

Commit

Permalink
Merge pull request #808 from WordPress/807-validate-donate-link
Browse files Browse the repository at this point in the history
Validate donate link
  • Loading branch information
ernilambar authored Nov 26, 2024
2 parents f68dc26 + 095eb9d commit 68f97ca
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ protected function check_files( Check_Result $result, array $files ) {
// Check the readme file for warnings.
$this->check_for_warnings( $result, $readme_file, $parser );

// Check the readme file for donate link.
$this->check_for_donate_link( $result, $readme_file, $parser );

// Check the readme file for contributors.
$this->check_for_contributors( $result, $readme_file );
}
Expand Down Expand Up @@ -601,6 +604,41 @@ private function check_for_warnings( Check_Result $result, string $readme_file,
}
}

/**
* Checks the readme file for donate link.
*
* @since 1.3.0
*
* @param Check_Result $result The Check Result to amend.
* @param string $readme_file Readme file.
* @param Parser $parser The Parser object.
*/
private function check_for_donate_link( Check_Result $result, string $readme_file, Parser $parser ) {
$donate_link = $parser->donate_link;

// Bail if empty donate link.
if ( empty( $donate_link ) ) {
return;
}

if ( ! ( filter_var( $donate_link, FILTER_VALIDATE_URL ) === $donate_link && str_starts_with( $donate_link, 'http' ) ) ) {
$this->add_result_warning_for_file(
$result,
sprintf(
/* translators: %s: plugin header field */
__( 'The "%s" header in the readme file must be a valid URL.', 'plugin-check' ),
'Donate link'
),
'readme_invalid_donate_link',
$readme_file,
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/#readme-header-information',
6
);
}
}

/**
* Checks the readme file for contributors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Stable tag: trunk
License: Oculus VR Inc. Software Development Kit License
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, testing, security
Donate link: not-a-valid-url

Here is a short description of the plugin.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public function test_run_md_with_errors() {

$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'mismatched_plugin_name' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'readme_invalid_contributors' ) ) );
$this->assertCount( 1, wp_list_filter( $warnings['readme.md'][0][0], array( 'code' => 'readme_invalid_donate_link' ) ) );
}

public function test_single_file_plugin_without_error_for_trademarks() {
Expand Down

0 comments on commit 68f97ca

Please sign in to comment.