1
|
|
|
<?php |
2
|
|
|
class Jetpack_PWA_Helpers { |
3
|
|
|
public static function get_default_manifest_icon_sizes() { |
4
|
|
|
// These icon sizes based on conversation here: |
5
|
|
|
// https://github.com/GoogleChrome/lighthouse/issues/291 |
6
|
|
|
return array( |
7
|
|
|
192, |
8
|
|
|
512, |
9
|
|
|
); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public static function site_icon_url( $size = 512 ) { |
13
|
|
|
$url = get_site_icon_url( $size ); |
14
|
|
|
|
15
|
|
|
// Fall back to built-in WordPress icon |
16
|
|
|
if ( ! $url && in_array( $size, self::get_default_manifest_icon_sizes() ) ) { |
17
|
|
|
$url = esc_url_raw( |
18
|
|
|
plugins_url( "modules/pwa/images/wp-$size.png", JETPACK__PLUGIN_FILE ) |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return $url; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public static function get_theme_color() { |
26
|
|
|
$theme_color = false; |
27
|
|
|
|
28
|
|
|
// if we have AMP enabled, use those colors? |
29
|
|
|
if ( class_exists( 'AMP_Customizer_Settings' ) ) { |
30
|
|
|
/* This filter is documented in wp-content/plugins/amp/includes/class-amp-post-template.php */ |
31
|
|
|
$amp_settings = apply_filters( |
32
|
|
|
'amp_post_template_customizer_settings', |
33
|
|
|
AMP_Customizer_Settings::get_settings(), |
34
|
|
|
null |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
if ( isset( $amp_settings['header_background_color'] ) ) { |
38
|
|
|
$theme_color = $amp_settings['header_background_color']; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ( ! $theme_color && current_theme_supports( 'custom-background' ) ) { |
43
|
|
|
$background_color = get_background_color(); // Returns hex key without hash or empty string |
44
|
|
|
if ( $background_color ) { |
45
|
|
|
$theme_color = "#$background_color"; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ( ! $theme_color ) { |
50
|
|
|
$theme_color = '#fff'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Allows overriding the PWA theme color which is used when loading the app. |
55
|
|
|
* |
56
|
|
|
* @since 5.6.0 |
57
|
|
|
* |
58
|
|
|
* @param string $theme_color |
59
|
|
|
*/ |
60
|
|
|
return apply_filters( 'jetpack_pwa_background_color', $theme_color ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|