Skip to content

Commit abba5c0

Browse files
davidperezgarernilambardavidperezgardd32
authored
Merge pull request #1289 from WordPress/1287-relax-update-uri-check
Allow WordPress.org `Update URI` when slug matches plugin directory Co-authored-by: ernilambar <nilambar@git.wordpress.org> Co-authored-by: davidperezgar <davidperez@git.wordpress.org> Co-authored-by: dd32 <dd32@git.wordpress.org>
2 parents 61f2c08 + 5fcaee7 commit abba5c0

3 files changed

Lines changed: 62 additions & 12 deletions

File tree

includes/Checker/Checks/Plugin_Repo/Plugin_Updater_Check.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ protected function check_files( Check_Result $result, array $files ) {
9898
}
9999

100100
/**
101-
* Looks for UpdateURI in plugin header and amends the given result with an error if found.
101+
* Looks for UpdateURI in plugin header and amends the given result with an error if invalid.
102+
*
103+
* Plugins on WordPress.org should not use this header, but the same URI formats as in the
104+
* directory API are accepted here: a wordpress.org or w.org plugin URL whose slug matches
105+
* this plugin passes; any other value is flagged.
102106
*
103107
* @since 1.0.0
104108
*
@@ -110,19 +114,34 @@ protected function look_for_update_uri_header( Check_Result $result ) {
110114
}
111115

112116
$plugin_main_file = $result->plugin()->main_file();
117+
$plugin_slug = $result->plugin()->slug();
113118
$plugin_header = get_plugin_data( $plugin_main_file );
114-
if ( ! empty( $plugin_header['UpdateURI'] ) ) {
115-
$this->add_result_error_for_file(
116-
$result,
117-
__( '<strong>Including An Update Checker / Changing Updates functionality.</strong><br>Plugin Updater detected. Use of the Update URI header is not allowed in plugins hosted on WordPress.org.', 'plugin-check' ),
118-
'plugin_updater_detected',
119-
$plugin_main_file,
120-
0,
121-
0,
122-
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#update-checker',
123-
9
124-
);
119+
120+
if ( empty( $plugin_header['UpdateURI'] ) ) {
121+
return;
122+
}
123+
124+
$update_uri_matches = array();
125+
$update_uri_valid = (bool) preg_match(
126+
'!^(https?://)?(wordpress.org|w.org)/plugins?/(?P<slug>[^/]+)/?$!i',
127+
$plugin_header['UpdateURI'],
128+
$update_uri_matches
129+
);
130+
131+
if ( $update_uri_valid && isset( $update_uri_matches['slug'] ) && $update_uri_matches['slug'] === $plugin_slug ) {
132+
return;
125133
}
134+
135+
$this->add_result_error_for_file(
136+
$result,
137+
__( '<strong>Including An Update Checker / Changing Updates functionality.</strong><br>Plugin Updater detected. Use of the Update URI header is not allowed in plugins hosted on WordPress.org.', 'plugin-check' ),
138+
'plugin_updater_detected',
139+
$plugin_main_file,
140+
0,
141+
0,
142+
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#update-checker',
143+
9
144+
);
126145
}
127146

128147
/**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Plugin Name: Test Plugin Update URI WordPress.org OK
4+
* Plugin URI: https://github.com/WordPress/plugin-check
5+
* Description: Update URI matches the plugin WordPress.org listing (allowed).
6+
* Requires at least: 6.0
7+
* Requires PHP: 5.6
8+
* Version: 1.0.0
9+
* Author: WordPress Performance Team
10+
* Author URI: https://make.wordpress.org/performance/
11+
* License: GPLv2 or later
12+
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
13+
* Text Domain: test-plugin-update-uri-w-org-ok
14+
* Update URI: https://wordpress.org/plugins/test-plugin-update-uri-w-org-ok/
15+
*
16+
* @package test-plugin-update-uri-w-org-ok
17+
*/

tests/phpunit/tests/Checker/Checks/Plugin_Updater_Check_Tests.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,18 @@ public function test_run_without_any_errors() {
122122
$this->assertEquals( 0, $check_result->get_error_count() );
123123
$this->assertEquals( 0, $check_result->get_warning_count() );
124124
}
125+
126+
/**
127+
* Update URI may point at this plugin’s WordPress.org URL; that must not be flagged.
128+
*/
129+
public function test_run_update_uri_wordpress_org_matching_slug_no_error() {
130+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-update-uri-w-org-ok/load.php' );
131+
$check_result = new Check_Result( $check_context );
132+
133+
$check = new Plugin_Updater_Check( Plugin_Updater_Check::TYPE_PLUGIN_UPDATE_URI_HEADER );
134+
$check->run( $check_result );
135+
136+
$this->assertEmpty( $check_result->get_errors() );
137+
$this->assertSame( 0, $check_result->get_error_count() );
138+
}
125139
}

0 commit comments

Comments
 (0)