Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register icons to display on the Manage Plugins screen for plugins that aren't in the WordPress.org directory.
<?php
/**
* Register plugin icons.
*
* WordPress 4.9 introduced icons in the list table on the Manage Plugins
* screen. The icons are pulled from the W.org update API. If an icon isn't
* available, a generic plugin Dashicon is shown instead.
*
* @param array $value Plugin update data.
* @return array
*/
add_filter( 'site_transient_update_plugins', function( $value ) {
$vendor_slug = 'example'; // Unique vendor slug.
$plugin_file = 'example/example.php'; // Relative path to the main plugin file from the plugins directory.
$plugin_icon = 'https://example.com/plugin-icon.png'; // URL to the plugin icon.
$icons = array(
'1x' => '',
'2x' => '',
'default' => $plugin_icon,
);
$plugin_slug = dirname( $plugin_file );
if ( isset( $value->no_update[ $plugin_file ] ) ) {
$value->no_update[ $plugin_file ]->icons = $icons;
} elseif ( isset( $value->response[ $plugin_file ] ) ) {
$value->response[ $plugin_file ]->icons = $icons;
} else {
$data = new stdClass;
$data->id = $vendor_slug . '/' . $plugin_slug;
$data->slug = $plugin_slug;
$data->plugin = $plugin_file;
$data->icons = $icons;
$value->no_update[ $plugin_file ] = $data;
}
return $value;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment