diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index ba9c7b859..ab949b49f 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -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 ); } @@ -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. * diff --git a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-md-with-errors/readme.md b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-md-with-errors/readme.md index a6e6ce7e9..68637e562 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-md-with-errors/readme.md +++ b/tests/phpunit/testdata/plugins/test-plugin-plugin-readme-md-with-errors/readme.md @@ -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. diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php index 275da69c0..a478c22f6 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Readme_Check_Tests.php @@ -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() {