Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate donate link #808

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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 @@
}
}

/**
* 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(

Check warning on line 627 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php#L624-L627

Added lines #L624 - L627 were not covered by tests
/* 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
);

Check warning on line 638 in includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php#L629-L638

Added lines #L629 - L638 were not covered by tests
}
}

/**
* 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
Loading