Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Updates | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
add_zip_download_link | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | /** |
3 | * Add .zip download link in the yellow "update available" banner. |
4 | * |
5 | * @package brianhenryie/bh-wp-plugins-page |
6 | */ |
7 | |
8 | namespace BrianHenryIE\WP_Plugins_Page\Admin; |
9 | |
10 | use stdClass; |
11 | |
12 | /** |
13 | * Append "v1.2.3 zip" as a download link to each plugin update notification. |
14 | */ |
15 | class Updates { |
16 | |
17 | /** |
18 | * Append "Download v1.2.3 zip" to each plugins.php yellow update notification. |
19 | * |
20 | * @hooked in_plugin_update_message-{plugin_basename} |
21 | * |
22 | * @param array<string,mixed> $plugin_data An array of plugin metadata. See get_plugin_data() |
23 | * and the {@see 'plugin_row_meta'} filter for the list |
24 | * of possible values. |
25 | * @param stdClass $response { |
26 | * An object of metadata about the available plugin update. |
27 | * |
28 | * @type string $id Plugin ID, e.g. `w.org/plugins/[plugin-name]`. |
29 | * @type string $slug Plugin slug. |
30 | * @type string $plugin Plugin basename. |
31 | * @type string $new_version New plugin version. |
32 | * @type string $url Plugin URL. |
33 | * @type string $package Plugin update package URL. |
34 | * @type string[] $icons An array of plugin icon URLs. |
35 | * @type string[] $banners An array of plugin banner URLs. |
36 | * @type string[] $banners_rtl An array of plugin RTL banner URLs. |
37 | * @type string $requires The version of WordPress which the plugin requires. |
38 | * @type string $tested The version of WordPress the plugin is tested against. |
39 | * @type string $requires_php The version of PHP which the plugin requires. |
40 | * } |
41 | */ |
42 | public function add_zip_download_link( array $plugin_data, stdClass $response ): void { |
43 | |
44 | if ( ! filter_var( $response->package, FILTER_VALIDATE_URL ) ) { |
45 | return; |
46 | } |
47 | |
48 | $parsed_url = wp_parse_url( $response->package ); |
49 | |
50 | if ( ! $parsed_url || ! isset( $parsed_url['path'] ) ) { |
51 | return; |
52 | } |
53 | |
54 | $filetype = wp_check_filetype( basename( $parsed_url['path'] ) )['ext']; |
55 | |
56 | if ( ! $filetype ) { |
57 | return; |
58 | } |
59 | |
60 | echo ' Download <a title="' . esc_attr( esc_url( $response->package ) ) . '" href="' . esc_url( $response->package ) . '" target="_top">v' . esc_html( $response->new_version ) . ' ' . esc_html( $filetype ) . '</a>.'; |
61 | } |
62 | } |