mirror of
https://ghproxy.net/https://github.com/fairpm/fair-plugin.git
synced 2025-09-04 10:32:01 +08:00
Signed-off-by: costdev <79332690+costdev@users.noreply.github.com> Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Co-authored-by: Andy Fragen <andy@thefragens.com>
45 lines
838 B
PHP
45 lines
838 B
PHP
<?php
|
|
/**
|
|
* Adds a local source for default icon SVG.
|
|
*
|
|
* @package FAIR
|
|
*/
|
|
|
|
namespace FAIR\Icons;
|
|
|
|
use FAIR;
|
|
|
|
/**
|
|
* Bootstrap
|
|
*/
|
|
function bootstrap() {
|
|
add_filter( 'site_transient_update_plugins', __NAMESPACE__ . '\\set_default_icon', 99, 1 );
|
|
}
|
|
|
|
/**
|
|
* Set default icon in update transient.
|
|
*
|
|
* @param stdClass $transient Update transient.
|
|
*
|
|
* @return stdClass
|
|
*/
|
|
function set_default_icon( $transient ) {
|
|
foreach ( $transient->response as $updates ) {
|
|
$url = plugin_dir_url( FAIR\PLUGIN_FILE ) . 'inc/icons/svg.php';
|
|
$url = add_query_arg( 'color', set_random_color(), $url );
|
|
$updates->icons['default'] = $url;
|
|
}
|
|
|
|
return $transient;
|
|
}
|
|
|
|
/**
|
|
* Set random color.
|
|
*
|
|
* @return string
|
|
*/
|
|
function set_random_color() {
|
|
$rand = str_pad( dechex( wp_rand( 0x000000, 0xFFFFFF ) ), 6, 0, STR_PAD_LEFT );
|
|
|
|
return $rand;
|
|
}
|