class-otgs-installer-icons.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class OTGS_Installer_Icons {
/**
* @var WP_Installer
*/
private $installer;
public function __construct( WP_Installer $installer ) {
$this->installer = $installer;
}
public function add_hooks() {
add_filter( 'otgs_installer_upgrade_check_response', array( $this, 'add_icons_on_response' ), 10, 2 );
}
/**
* @param stdClass $response
* @param string $name
*
* @return stdClass
*/
public function add_icons_on_response( $response, $name ) {
$repositories = array_keys( $this->installer->get_repositories() );
$product = '';
$repository = '';
foreach( $repositories as $repository_id ) {
if ( isset( $this->installer->settings['repositories'][ $repository_id ]['data']['products-map'][ $response->plugin ] ) ) {
$product = $this->installer->settings['repositories'][ $repository_id ]['data']['products-map'][ $response->plugin ];
$repository = $repository_id;
break;
} elseif ( isset( $this->installer->settings['repositories'][ $repository_id ]['data']['products-map'][ $name ] ) ) {
$product = $this->installer->settings['repositories'][ $repository_id ]['data']['products-map'][ $name ];
$repository = $repository_id;
break;
}
}
if ( $product && $repository ) {
$base = $this->installer->plugin_url() . '/../icons/plugin-icons/' . $repository . '/' . $product . '/icon';
$response->icons = array(
'svg' => $base . '.svg',
'1x' => $base . '-128x128.png',
'2x' => $base . '-256x256.png',
);
}
return $response;
}
}