Skip to content
Open
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
66 changes: 63 additions & 3 deletions rt-plugin-report.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ public function settings_page() {
echo '<tbody>';

foreach ( $plugins as $key => $plugin ) {
$slug = $this->get_plugin_slug( $key );
$cache_key = $this->create_cache_key( $slug );
$cache = get_site_transient( $cache_key );
$slug = $this->get_plugin_slug( $key );
$cache = $this->get_report( $slug );
if ( $cache ) {
// Use the cached report to create a table row.
echo $this->render_table_row( $cache );
Expand Down Expand Up @@ -773,10 +772,71 @@ public function upgrade_delete_cache_items( $upgrader, $data ) {
}
}

/**
* Public API: get the report data for a plugin.
*
* Returns cached data when available, otherwise assembles a fresh report
* (which also populates the cache). This is the recommended way for other
* plugins to read Plugin Report data without accessing transients directly.
*
* @param string $slug Plugin slug (e.g. "akismet").
*
* @return array|null Report data array, or null if the slug is empty or not found.
*/
public function get_report( $slug ) {
if ( empty( $slug ) ) {
return null;
}

// Check if get_plugins() function exists.
if ( ! function_exists( 'plugins_api' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
}

$cache_key = $this->create_cache_key( $slug );
$cache = get_site_transient( $cache_key );

if ( ! empty( $cache ) ) {
return $cache;
}

return $this->assemble_plugin_report( $slug );
}

}

// Instantiate the class.
$plugin_report_instance = new RT_Plugin_Report();
$plugin_report_instance->init();


/**
* Public API: get Plugin Report data for a plugin.
*
* Convenience wrapper around RT_Plugin_Report::get_report(). Uses a static
* instance to avoid repeated object creation. Returns cached data when
* available, otherwise fetches fresh data from the wordpress.org API and
* caches it. Safe to call from any plugin — if Plugin Report is not active
* or the slug is invalid, returns null.
*
* Example usage:
*
* if ( function_exists( 'plugin_report_get_data' ) ) {
* $report = plugin_report_get_data( 'akismet' );
* if ( isset( $report['repo_info'] ) ) {
* echo $report['repo_info']->tested;
* }
* }
*
* @param string $slug Plugin slug (e.g. "akismet").
*
* @return array|null Report data array, or null if not available.
*/
function plugin_report_get_data( $slug ) {
static $plugin_report = null;
if ( null === $plugin_report ) {
$plugin_report = new RT_Plugin_Report();
}
return $plugin_report->get_report( $slug );
}
}
Loading