Created
October 4, 2017 22:30
-
-
Save bradyvercher/13164872aa312db2e31c2efa8dac7e35 to your computer and use it in GitHub Desktop.
Register icons to display on the Manage Plugins screen for plugins that aren't in the WordPress.org directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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