Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Created November 27, 2020 21:55
Show Gist options
  • Select an option

  • Save georgestephanis/e4d2b1f72e919b7560eb1ad6c242ad54 to your computer and use it in GitHub Desktop.

Select an option

Save georgestephanis/e4d2b1f72e919b7560eb1ad6c242ad54 to your computer and use it in GitHub Desktop.
This will build a github markdown table of all the plugins on a site.
<?php
include( 'the/path/to/wp-load.php' );
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
$updates = get_site_transient( 'update_plugins' );
if ( ! $updates ) {
wp_update_plugins();
$updates = get_site_transient( 'update_plugins' );
}
$headers = array(
'Slug',
'Active',
'Version',
'Repo Version',
'Repo Or Custom URL',
);
echo '| ' . implode( ' | ', $headers ) . " |\r\n";
echo '| ' . trim( str_repeat( '--- | ', count( $headers ) ) ) . "\r\n";
$plugins = get_plugins();
foreach ( $plugins as $file => $data ) {
echo '| ';
foreach ( $headers as $header ) {
switch ( $header ) {
case 'Slug':
echo strpos( $file, '/' ) ? dirname( $file ) : $file;
break;
case 'Active':
echo is_plugin_active( $file ) ? 'Yes' : ( is_plugin_active_for_network( $file ) ? 'Network' : 'No' );
break;
case 'Repo Version':
if ( isset( $updates->response[ $file ] ) ) {
echo $updates->response[ $file ]->new_version;
} elseif ( isset( $updates->no_update[ $file ] ) ) {
echo 'Current';
} else {
echo 'Not In Repository';
}
break;
case 'Repo Or Custom URL':
if ( isset( $updates->response[ $file ] ) ) {
echo $updates->response[ $file ]->url;
} elseif ( isset( $updates->no_update[ $file ] ) ) {
echo $updates->no_update[ $file ]->url;
} else {
echo $data['Plugin URI'];
}
break;
default:
echo $data[ $header ];
break;
}
echo ' | ';
}
echo "\r\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment