Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressive Web Apps: sunset feature #13409

Merged
merged 6 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -6306,6 +6306,9 @@ public function deprecated_hooks() {
'atd_http_post_error' => null,
'atd_service_domain' => null,
'jetpack_widget_authors_exclude' => 'jetpack_widget_authors_params',
// Removed in Jetpack 7.9.0
'jetpack_pwa_manifest' => null,
'jetpack_pwa_background_color' => null,
);

// This is a silly loop depth. Better way?
Expand Down
6 changes: 0 additions & 6 deletions modules/module-headings.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ function jetpack_get_module_i18n( $key ) {
'description' => _x( 'Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.', 'Module Description', 'jetpack' ),
),

'pwa' => array(
'name' => _x( 'Progressive Web Apps', 'Module Name', 'jetpack' ),
'description' => _x( 'Speed up and improve the reliability of your site using the latest in web technology.', 'Module Description', 'jetpack' ),
),

'related-posts' => array(
'name' => _x( 'Related posts', 'Module Name', 'jetpack' ),
'description' => _x( 'Keep visitors engaged on your blog by highlighting relevant and new content at the bottom of each published post.', 'Module Description', 'jetpack' ),
Expand Down Expand Up @@ -297,7 +292,6 @@ function jetpack_get_module_i18n_tag( $key ) {

// Modules with `Developers` tag:
// - modules/json-api.php
// - modules/pwa.php
// - modules/sso.php
'Developers' =>_x( 'Developers', 'Module Tag', 'jetpack' ),

Expand Down
19 changes: 0 additions & 19 deletions modules/module-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,25 +858,6 @@ function jetpack_comment_likes_more_info() {
}
add_action( 'jetpack_module_more_info_comment-likes', 'jetpack_comment_likes_more_info' );

/**
* Progressive Web Apps support link.
*/
function jetpack_pwa_more_link() {
echo 'https://jetpack.com/support/progressive-web-apps/';
}
add_action( 'jetpack_learn_more_button_pwa', 'jetpack_pwa_more_link' );

/**
* Progressive Web Apps description.
*/
function jetpack_pwa_more_info() {
esc_html_e(
'Speed up and improve the reliability of your site using the latest in web technology.',
'jetpack'
);
}
add_action( 'jetpack_module_more_info_pwa', 'jetpack_pwa_more_info' );

/**
* Asset CDN support link.
*/
Expand Down
40 changes: 1 addition & 39 deletions modules/pwa.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
<?php
/**
* Module Name: Progressive Web Apps
* Module Description: Speed up and improve the reliability of your site using the latest in web technology.
* Sort Order: 38
* Recommendation Order: 18
* First Introduced: 5.6.0
* Requires Connection: Yes
* Auto Activate: No
* Module Tags: Developers
* Feature: Traffic
* Additional Search Queries: manifest, pwa, progressive
* Deprecated. No longer needed.
*/

require_once ( JETPACK__PLUGIN_DIR . 'modules/pwa/class.jetpack-pwa-helpers.php' );
require_once ( JETPACK__PLUGIN_DIR . 'modules/pwa/class.jetpack-pwa-manifest.php' );

class Jetpack_PWA {
/**
* @var Jetpack_PWA
*/
private static $__instance = null;

/**
* Singleton implementation
*
* @return Jetpack_PWA
*/
public static function instance() {
if ( is_null( self::$__instance ) ) {
self::$__instance = new Jetpack_PWA;
}

return self::$__instance;
}

private function __construct() {
Jetpack_PWA_Manifest::instance();
}
}

Jetpack_PWA::instance();
64 changes: 3 additions & 61 deletions modules/pwa/class.jetpack-pwa-helpers.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
<?php
class Jetpack_PWA_Helpers {
public static function get_default_manifest_icon_sizes() {
// These icon sizes based on conversation here:
// https://github.com/GoogleChrome/lighthouse/issues/291
return array(
192,
512,
);
}

public static function site_icon_url( $size = 512 ) {
$url = get_site_icon_url( $size );

// Fall back to built-in WordPress icon
if ( ! $url && in_array( $size, self::get_default_manifest_icon_sizes() ) ) {
$url = esc_url_raw(
plugins_url( "modules/pwa/images/wp-$size.png", JETPACK__PLUGIN_FILE )
);
}

return $url;
}

public static function get_theme_color() {
$theme_color = false;

// if we have AMP enabled, use those colors?
if ( class_exists( 'AMP_Customizer_Settings' ) ) {
/* This filter is documented in wp-content/plugins/amp/includes/class-amp-post-template.php */
$amp_settings = apply_filters(
'amp_post_template_customizer_settings',
AMP_Customizer_Settings::get_settings(),
null
);

if ( isset( $amp_settings['header_background_color'] ) ) {
$theme_color = $amp_settings['header_background_color'];
}
}

if ( ! $theme_color && current_theme_supports( 'custom-background' ) ) {
$background_color = get_background_color(); // Returns hex key without hash or empty string
if ( $background_color ) {
$theme_color = "#$background_color";
}
}

if ( ! $theme_color ) {
$theme_color = '#fff';
}

/**
* Allows overriding the PWA theme color which is used when loading the app.
*
* @since 5.6.0
*
* @param string $theme_color
*/
return apply_filters( 'jetpack_pwa_background_color', $theme_color );
}
}
/**
* Deprecated. No longer needed.
*/
97 changes: 3 additions & 94 deletions modules/pwa/class.jetpack-pwa-manifest.php
Original file line number Diff line number Diff line change
@@ -1,95 +1,4 @@
<?php

class Jetpack_PWA_Manifest {
/**
* @var Jetpack_PWA_Manifest
*/
private static $__instance = null;

/**
* When this query var is present, display the PWA manifest.
*
* @var string
*/
const PWA_MANIFEST_QUERY_VAR = 'jetpack_app_manifest';

/**
* Singleton implementation
*
* @return Jetpack_PWA_Manifest
*/
public static function instance() {
if ( is_null( self::$__instance ) ) {
self::$__instance = new Jetpack_PWA_Manifest;
}

return self::$__instance;
}

/**
* Registers actions the first time that instance() is called.
*/
private function __construct() {
add_action( 'wp_head', array( $this, 'render_manifest_link' ) );
add_action( 'amp_post_template_head', array( $this, 'render_manifest_link' ) );
add_action( 'template_redirect', array( $this, 'render_manifest_json' ), 2 );
}

function render_manifest_link() {
?>
<link rel="manifest" href="<?php echo esc_url_raw( $this->get_manifest_url() ); ?>">
<meta name="theme-color" content="<?php echo esc_attr( Jetpack_PWA_Helpers::get_theme_color() ); ?>">
<?php
}

public function get_manifest_url() {
return add_query_arg(
self::PWA_MANIFEST_QUERY_VAR, '1', home_url()
);
}

function render_manifest_json() {
// Do not load manifest in multiple locations
if ( is_front_page() && isset( $_GET[ self::PWA_MANIFEST_QUERY_VAR ] ) && $_GET[ self::PWA_MANIFEST_QUERY_VAR ] ) {
@ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed.

$theme_color = Jetpack_PWA_Helpers::get_theme_color();

$manifest = array(
'name' => get_bloginfo( 'name' ),
'start_url' => get_home_url(),
'short_name' => substr( get_bloginfo( 'name' ), 0, 12 ),
'display' => 'standalone',
'background_color' => $theme_color,
'theme_color' => $theme_color,
);

if ( $description = get_bloginfo( 'description' ) ) {
$manifest['description'] = $description;
}

$manifest['icons'] = array_map(
array( $this, 'build_icon_object' ),
Jetpack_PWA_Helpers::get_default_manifest_icon_sizes()
);

/**
* Allow overriding the manifest.
*
* @since 5.6.0
*
* @param array $manifest
*/
$manifest = apply_filters( 'jetpack_pwa_manifest', $manifest );

wp_send_json( $manifest );
}
}

function build_icon_object( $size ) {
return array(
'src' => Jetpack_PWA_Helpers::site_icon_url( $size ),
'sizes' => sprintf( '%1$dx%1$d', $size ),
);
}
}
/**
* Deprecated. No longer needed.
*/
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
<testsuite name="3rd-party">
<directory prefix="test_" suffix=".php">tests/php/3rd-party</directory>
</testsuite>
<testsuite name="pwa">
<directory prefix="test_" suffix=".php">tests/php/pwa</directory>
</testsuite>
<testsuite name="lazy-images">
<directory prefix="test_" suffix=".php">tests/php/modules/lazy-images</directory>
</testsuite>
Expand Down
79 changes: 0 additions & 79 deletions tests/php/pwa/test_class.jetpack-pwa-helpers.php

This file was deleted.