Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Plugins show their .org status.
  • Loading branch information
janw-me committed Nov 10, 2023
commit 0c695a584108fa281c17e29dfd40a3e23d506a79
42 changes: 41 additions & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
'status',
'update',
'version',
'auto_update',
'wordpress.org',
);

/**
Expand Down Expand Up @@ -721,6 +721,7 @@ protected function get_item_list() {
'file' => $file,
'auto_update' => in_array( $file, $auto_updates, true ),
'author' => $details['Author'],
'wordpress.org' => $this->get_dotorg_status( $name ),
];

if ( null === $update_info ) {
Expand All @@ -747,6 +748,45 @@ protected function get_item_list() {
return $items;
}

/**
* Get the wordpress.org status of a plugin.
*
* @param string $plugin_name The plugin slug.
*
* @return string The status of the plugin, includes the last update date.
*/
protected function get_dotorg_status( $plugin_name ) {
$request = wp_remote_get( "https://plugins.trac.wordpress.org/log/{$plugin_name}/?limit=1&mode=stop_on_copy&format=rss" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only make this request if we're checking for the date?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a better check in d7ec274
The answer is, not always,

When the call to api.wp is not succesfull, we need to check the SVN to distinguish between closed and never on .org.

$response_code = wp_remote_retrieve_response_code( $request );
if ( 404 === $response_code ) {
return 'not on wordpress.org'; // This plugin was never on .org.
}
if ( ! class_exists( 'SimpleXMLElement' ) ) {
WP_CLI::error( "The PHP extension 'SimpleXMLElement' is not available but is required for XML-formatted output." );
}

$update_date = 'Unknown last update date';

// log the date.
$r_body = wp_remote_retrieve_body( $request );
if ( str_contains( $r_body, 'pubDate' ) ) {
// Very basic check, not validating the format or anything else.
$xml = simplexml_load_string( $r_body );
$xml_pub_date = $xml->xpath( '//pubDate' );
if ( $xml_pub_date ) {
$update_date = 'last updated ' . wp_date( get_option( 'date_format' ), (string) strtotime( $xml_pub_date[0] ) );
}
}

$request = wp_remote_head( 'https://api.wordpress.org/plugins/info/1.0/' . $plugin_name );
$response_code = wp_remote_retrieve_response_code( $request );
if ( 200 === $response_code ) {
return 'active, ' . $update_date; // this plugin is on .org.
}

return 'closed, ' . $update_date;
}

protected function filter_item_list( $items, $args ) {
$basenames = wp_list_pluck( $this->fetcher->get_many( $args ), 'file' );
return Utils\pick_fields( $items, $basenames );
Expand Down