Completed
Push — add/lazy-images ( 1aef1c...4b007f )
by
unknown
08:11
created

Jetpack_PWA_Helpers   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 0

3 Methods

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