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

foreach ( $plugins as $key => $plugin ) {
$slug = $this->get_plugin_slug( $key );
$slug = $this->get_plugin_slug( $key, $plugin );
$cache_key = $this->create_cache_key( $slug );
$cache = get_site_transient( $cache_key );
if ( $cache ) {
Expand Down Expand Up @@ -204,7 +204,7 @@ private function get_plugin_slugs() {
$plugins = get_plugins();
$slugs = array();
foreach ( $plugins as $key => $plugin ) {
$slugs[] = $this->get_plugin_slug( $key );
$slugs[] = $this->get_plugin_slug( $key, $plugin );
}
return $slugs;
}
Expand All @@ -213,14 +213,20 @@ private function get_plugin_slugs() {
/**
* Convert a plugin's file path into its slug.
*
* @param string $file Plugin file path.
* @param string $file Plugin file path.
* @param array $plugin_data Optional plugin header data from get_plugins().
*/
private function get_plugin_slug( $file ) {
private function get_plugin_slug( $file, $plugin_data = array() ) {
if ( strpos( $file, '/' ) !== false ) {
$parts = explode( '/', $file );
} else {
$parts = explode( '.', $file );
return sanitize_title( $parts[0] );
}
// Single-file plugin (e.g. hello.php): prefer TextDomain as slug,
// since the filename alone often doesn't match the wp.org slug.
if ( ! empty( $plugin_data['TextDomain'] ) ) {
return sanitize_title( $plugin_data['TextDomain'] );
}
$parts = explode( '.', $file );
return sanitize_title( $parts[0] );
}

Expand Down Expand Up @@ -293,7 +299,7 @@ private function assemble_plugin_report( $slug ) {

// Get the locally available info, and add it to the report.
foreach ( $plugins as $key => $plugin ) {
if ( $this->get_plugin_slug( $key ) === $slug ) {
if ( $this->get_plugin_slug( $key, $plugin ) === $slug ) {

// Translate plugin data.
$textdomain = $plugin['TextDomain'];
Expand Down Expand Up @@ -742,7 +748,7 @@ private function clear_cache() {
$plugins = get_plugins();
// Loop through the plugins array, and delete cache items.
foreach ( $plugins as $key => $plugin ) {
$slug = $this->get_plugin_slug( $key );
$slug = $this->get_plugin_slug( $key, $plugin );
$this->clear_cache_item( $slug );
}
}
Expand All @@ -765,9 +771,11 @@ private function clear_cache_item( $slug ) {
public function upgrade_delete_cache_items( $upgrader, $data ) {
// Check if plugins have been upgraded by WP.
if ( isset( $data ) && isset( $data['plugins'] ) && is_array( $data['plugins'] ) ) {
$plugins = get_plugins();
// Loop through the plugins, and delete the associated cache items.
foreach ( $data['plugins'] as $key => $value ) {
$slug = $this->get_plugin_slug( $value );
$plugin_data = isset( $plugins[ $value ] ) ? $plugins[ $value ] : array();
$slug = $this->get_plugin_slug( $value, $plugin_data );
$this->clear_cache_item( $slug );
}
}
Expand Down
Loading