Skip to content

Commit 55fd049

Browse files
committed
feat(config): add PLUGIN_REPORT_IGNORE constant
Skip wordpress.org API lookups for plugins listed in the PLUGIN_REPORT_IGNORE constant. Defined in wp-config.php as array or comma-separated string. Ignored plugins show "Ignored (via config)" in the Repository column.
1 parent e0d7977 commit 55fd049

1 file changed

Lines changed: 54 additions & 22 deletions

File tree

rt-plugin-report.php

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,30 @@ public function get_plugin_info() {
272272
}
273273

274274

275+
/**
276+
* Check if a plugin slug is on the ignore list.
277+
*
278+
* The ignore list is read from the PLUGIN_REPORT_IGNORE constant, which
279+
* can be defined in wp-config.php as a comma-separated string or an array.
280+
*
281+
* @param string $slug Plugin slug.
282+
*
283+
* @return bool True if the plugin should be ignored.
284+
*/
285+
private function is_ignored( $slug ) {
286+
if ( ! defined( 'PLUGIN_REPORT_IGNORE' ) ) {
287+
return false;
288+
}
289+
290+
$ignore_list = PLUGIN_REPORT_IGNORE;
291+
if ( is_string( $ignore_list ) ) {
292+
$ignore_list = array_map( 'trim', explode( ',', $ignore_list ) );
293+
}
294+
295+
return is_array( $ignore_list ) && in_array( $slug, $ignore_list, true );
296+
}
297+
298+
275299
/**
276300
* Gather all the info we can get about a plugin.
277301
* Uses transient caching to avoid doing repo API calls on every page visit.
@@ -326,27 +350,33 @@ private function assemble_plugin_report( $slug ) {
326350
}
327351
}
328352

329-
// Use the wordpress.org repository API to get detailed information.
330-
$args = array(
331-
'slug' => $slug,
332-
'fields' => array(
333-
'description' => false,
334-
'sections' => false,
335-
'tags' => false,
336-
'version' => true,
337-
'tested' => true,
338-
'requires' => true,
339-
'requires_php' => true,
340-
'compatibility' => true,
341-
'author' => true,
342-
),
343-
);
344-
345-
// Check wordpress.org only if "Update URI" plugin header is not set or set to wordpress.org.
346-
$parsed_repo_url = wp_parse_url( $report['local_info']['UpdateURI'] );
347-
$repo_host = isset( $parsed_repo_url['host'] ) ? $parsed_repo_url['host'] : null;
348-
if ( empty( $repo_host ) || strtolower( $repo_host ) === 'w.org' || strtolower( $repo_host ) === 'wordpress.org' ) {
349-
$returned_object = plugins_api( 'plugin_information', $args );
353+
// Skip API lookups for ignored plugins.
354+
if ( $this->is_ignored( $slug ) ) {
355+
$report['ignored'] = true;
356+
set_site_transient( $cache_key, $report, self::CACHE_LIFETIME_NOREPO );
357+
} else {
358+
// Use the wordpress.org repository API to get detailed information.
359+
$args = array(
360+
'slug' => $slug,
361+
'fields' => array(
362+
'description' => false,
363+
'sections' => false,
364+
'tags' => false,
365+
'version' => true,
366+
'tested' => true,
367+
'requires' => true,
368+
'requires_php' => true,
369+
'compatibility' => true,
370+
'author' => true,
371+
),
372+
);
373+
374+
// Check wordpress.org only if "Update URI" plugin header is not set or set to wordpress.org.
375+
$parsed_repo_url = wp_parse_url( $report['local_info']['UpdateURI'] );
376+
$repo_host = isset( $parsed_repo_url['host'] ) ? $parsed_repo_url['host'] : null;
377+
if ( empty( $repo_host ) || strtolower( $repo_host ) === 'w.org' || strtolower( $repo_host ) === 'wordpress.org' ) {
378+
$returned_object = plugins_api( 'plugin_information', $args );
379+
}
350380
}
351381

352382
// Add the repo info to the report.
@@ -438,7 +468,9 @@ private function render_table_row( $report ) {
438468
}
439469

440470
// Repository.
441-
if ( isset( $report['local_info']['UpdateURI'] ) ) {
471+
if ( isset( $report['ignored'] ) && true === $report['ignored'] ) {
472+
$html .= '<td>' . esc_html__( 'Ignored (via config)', 'plugin-report' ) . '</td>';
473+
} elseif ( isset( $report['local_info']['UpdateURI'] ) ) {
442474
// Parse the UpdateURI's value to get the host.
443475
$parsed_repo_url = wp_parse_url( $report['local_info']['UpdateURI'] );
444476
// If the URI is valid, extract the host, otherwise we'll use the header value.

0 commit comments

Comments
 (0)