Added WP-CLI command
This commit is contained in:
parent
c904665af8
commit
4af73b93dc
27
README.md
27
README.md
@ -10,6 +10,30 @@ On plugins that have not been updated in over two years, a warning emoji is disp
|
|||||||
2. Activate the plugin through the 'Plugins' screen in WordPress.
|
2. Activate the plugin through the 'Plugins' screen in WordPress.
|
||||||
3. That's it! The plugin will automatically display the last updated date for installed plugins available in the WordPress Plugin Directory.
|
3. That's it! The plugin will automatically display the last updated date for installed plugins available in the WordPress Plugin Directory.
|
||||||
|
|
||||||
|
Sure, here's an example section that you can add to the `README.md` file to document the new WP-CLI command:
|
||||||
|
|
||||||
|
## WP-CLI Command
|
||||||
|
|
||||||
|
PLU Redux includes a WP-CLI command that displays the "Last Updated" date of installed plugins. Here's how you use it:
|
||||||
|
|
||||||
|
```
|
||||||
|
wp plu list
|
||||||
|
```
|
||||||
|
|
||||||
|
This command will output a list of installed (WordPress Plugin Directory listed) plugins alongside their "Last Updated" date:
|
||||||
|
|
||||||
|
```
|
||||||
|
+-----------------------------------+---------------------------+
|
||||||
|
| Plugin Name | Last Updated |
|
||||||
|
+-----------------------------------+---------------------------+
|
||||||
|
| Akismet Anti-Spam Spam Protection | 2023-04-05 10:17am GMT |
|
||||||
|
| Lazy Load | 2018-11-22 04:43am GMT ← |
|
||||||
|
| Proxy Cache Purge | 2022-06-09 10:57pm GMT |
|
||||||
|
+-----------------------------------+---------------------------+
|
||||||
|
```
|
||||||
|
|
||||||
|
Plugins that have not been updated in over two years will be highlighted with an arrow (←) to the right of the "Last Updated" date.
|
||||||
|
|
||||||
## Frequently Asked Questions
|
## Frequently Asked Questions
|
||||||
|
|
||||||
### How does the plugin determine if a plugin hasn't been updated in over two years?
|
### How does the plugin determine if a plugin hasn't been updated in over two years?
|
||||||
@ -28,6 +52,9 @@ Sadly, no. PLU Redux only works with plugins that are available in the WordPress
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### 2.1.0
|
||||||
|
* Added a WP-CLI command.
|
||||||
|
|
||||||
### 2.0.0
|
### 2.0.0
|
||||||
* Brought code up to date.
|
* Brought code up to date.
|
||||||
* Added feature where a warning emoji is displayed next to plugins that have not been updated in over two years.
|
* Added feature where a warning emoji is displayed next to plugins that have not been updated in over two years.
|
||||||
|
@ -93,3 +93,42 @@ function plu_redux_get_last_updated( $slug ) {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WP-CLI command to display last updated dates of installed plugins.
|
||||||
|
*/
|
||||||
|
function plu_redux_last_updated_command() {
|
||||||
|
$plugins = get_plugins();
|
||||||
|
|
||||||
|
$table = new \cli\Table();
|
||||||
|
$table->setHeaders(array('Plugin Name', 'Last Updated'));
|
||||||
|
|
||||||
|
foreach ($plugins as $plugin_file => $plugin_info) {
|
||||||
|
// Extract the plugin's slug from the plugin filename
|
||||||
|
list($slug) = explode('/', $plugin_file);
|
||||||
|
|
||||||
|
// Generate a unique hash of the plugin's slug
|
||||||
|
$slug_hash = md5($slug);
|
||||||
|
|
||||||
|
// Get the last updated date from the cache
|
||||||
|
$last_updated = get_transient("plu_redux_{$slug_hash}");
|
||||||
|
|
||||||
|
// If the cache does not have the date, retrieve it from the WordPress API and cache it
|
||||||
|
if (false === $last_updated) {
|
||||||
|
$last_updated = plu_redux_get_last_updated($slug);
|
||||||
|
set_transient("plu_redux_{$slug_hash}", $last_updated, 86400); // cache for one day
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($last_updated) {
|
||||||
|
// Check if last update was more than 2 years ago
|
||||||
|
$two_years_ago = strtotime('-2 years'); // get a Unix timestamp for 2 years ago
|
||||||
|
$last_updated_timestamp = strtotime($last_updated); // get a Unix timestamp for the last updated date
|
||||||
|
$is_old = $last_updated_timestamp < $two_years_ago; // check if the last updated date is older than 2 years
|
||||||
|
$warning = $is_old ? ' ←' : ''; // if the last updated date is older than 2 years, add a warning symbol
|
||||||
|
$table->addRow(array($plugin_info['Name'], $last_updated . $warning));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->display();
|
||||||
|
}
|
||||||
|
\WP_CLI::add_command('plu list', 'plu_redux_last_updated_command');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user