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

Differentiate between client and server being offline in the messaging on the offline page #190

Merged
merged 1 commit into from
Jul 10, 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
6 changes: 4 additions & 2 deletions wp-admin/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
switch ( isset( $_REQUEST['code'] ) ? sanitize_key( $_REQUEST['code'] ) : null ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.NoNonceVerification
case 'offline':
$title_prefix = __( 'Offline', 'pwa' );
$content = sprintf( '<h1>%s</h1>', esc_html__( 'You seem to be offline.', 'pwa' ) );
$content .= sprintf( '<p>%s</p>', esc_html__( 'Please check your internet connection. In the future, this error screen could provide you with actions you can perform while offline, like edit recent drafts in Gutenberg.', 'pwa' ) );
$content = sprintf( '<h1>%s</h1>', esc_html__( 'Offline', 'pwa' ) );
$content .= '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
$content .= sprintf( '<p>%s</p>', esc_html__( 'In the future, this error screen could provide you with actions you can perform while offline, like edit recent drafts in Gutenberg.', 'pwa' ) );
break;
case '500':
$title_prefix = __( 'Internal Server Error', 'pwa' );
$content = sprintf( '<h1>%s</h1>', esc_html__( 'A server error occurred.', 'pwa' ) );
$content .= '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
$content .= sprintf(
'<p>%s</p>',
esc_html__( 'Something went wrong which prevented WordPress from serving a response. Please check your error logs.', 'pwa' )
Expand Down
3 changes: 1 addition & 2 deletions wp-includes/js/service-worker-navigation-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ ERROR_OFFLINE_BODY_FRAGMENT_URL, STREAM_HEADER_FRAGMENT_QUERY_VAR, NAVIGATION_BL
return details;
}
);

return new Response( body, init );
} );
} );
Expand All @@ -111,7 +110,7 @@ ERROR_OFFLINE_BODY_FRAGMENT_URL, STREAM_HEADER_FRAGMENT_QUERY_VAR, NAVIGATION_BL
headers: response.headers
};

const body = text.replace( /[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, errorMessages.default );
const body = text.replace( /[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, navigator.onLine ? errorMessages.serverOffline : errorMessages.clientOffline );

return new Response( body, init );
} );
Expand Down
7 changes: 4 additions & 3 deletions wp-includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ function wp_service_worker_get_error_messages() {
return apply_filters(
'wp_service_worker_error_messages',
array(
'default' => __( 'Please check your internet connection, and try again.', 'pwa' ),
'error' => __( 'Something prevented the page from being rendered. Please try again.', 'pwa' ),
'comment' => __( 'Your comment will be submitted once you are back online!', 'pwa' ),
'clientOffline' => __( 'It seems you are offline. Please check your internet connection and try again.', 'pwa' ),
'serverOffline' => __( 'The server appears to be down. Please try again later.', 'pwa' ),
'error' => __( 'Something prevented the page from being rendered. Please try again.', 'pwa' ),
'comment' => __( 'Your comment will be submitted once you are back online!', 'pwa' ),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/theme-compat/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

?>
<main>
<h1><?php esc_html_e( 'Oops! It looks like you&#8217;re offline.', 'pwa' ); ?></h1>
<h1><?php esc_html_e( 'Offline', 'pwa' ); ?></h1>
<?php wp_service_worker_error_message_placeholder(); ?>
</main>
<?php
Expand Down