class.jetpack-pwa-helpers.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. public static function site_icon_url( $size = 512 ) {
  12. $url = function_exists( 'get_site_icon_url' )
  13. ? get_site_icon_url( $size )
  14. : false;
  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. return $url;
  22. }
  23. public static function get_theme_color() {
  24. $theme_color = false;
  25. // if we have AMP enabled, use those colors?
  26. if ( class_exists( 'AMP_Customizer_Settings' ) ) {
  27. /* This filter is documented in wp-content/plugins/amp/includes/class-amp-post-template.php */
  28. $amp_settings = apply_filters(
  29. 'amp_post_template_customizer_settings',
  30. AMP_Customizer_Settings::get_settings(),
  31. null
  32. );
  33. if ( isset( $amp_settings['header_background_color'] ) ) {
  34. $theme_color = $amp_settings['header_background_color'];
  35. }
  36. }
  37. if ( ! $theme_color && current_theme_supports( 'custom-background' ) ) {
  38. $background_color = get_background_color(); // Returns hex key without hash or empty string
  39. if ( $background_color ) {
  40. $theme_color = "#$background_color";
  41. }
  42. }
  43. if ( ! $theme_color ) {
  44. $theme_color = '#fff';
  45. }
  46. /**
  47. * Allows overriding the PWA theme color which is used when loading the app.
  48. *
  49. * @since 5.6.0
  50. *
  51. * @param string $theme_color
  52. */
  53. return apply_filters( 'jetpack_pwa_background_color', $theme_color );
  54. }
  55. }