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

Update error messages html comment placeholders with mustache tags #720

Merged
merged 1 commit into from
Mar 2, 2022
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
4 changes: 2 additions & 2 deletions wp-admin/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
case 'offline':
$title_prefix = __( 'Offline', 'pwa' );
$content = sprintf( '<h1>%s</h1>', esc_html__( 'Offline', 'pwa' ) );
$content .= '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
$content .= '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder.
$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 .= '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder.
$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
12 changes: 5 additions & 7 deletions wp-includes/js/service-worker-navigation-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ ERROR_OFFLINE_URL, ERROR_500_URL, NAVIGATION_DENYLIST_PATTERNS, ERROR_MESSAGES *
};

let body = text.replace(
/[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/,
'{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}',
errorMessages.error
);
body = body.replace(
/([<]!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->)((?:.|\n)+?)([<]!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->)/,
/({{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}})((?:.|\n)+?)({{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}})/,
(details) => {
if (!responseBody) {
return ''; // Remove the details from the document entirely.
Expand Down Expand Up @@ -103,13 +103,11 @@ ERROR_OFFLINE_URL, ERROR_500_URL, NAVIGATION_DENYLIST_PATTERNS, ERROR_MESSAGES *

// Replace the comments.
details = details.replace(
'<' +
'!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->',
'{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}}',
''
);
details = details.replace(
'<' +
'!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->',
'{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}}',
''
);
return details;
Expand Down Expand Up @@ -137,7 +135,7 @@ ERROR_OFFLINE_URL, ERROR_500_URL, NAVIGATION_DENYLIST_PATTERNS, ERROR_MESSAGES *
};

const body = text.replace(
/[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/,
'{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}',
navigator.onLine
? errorMessages.serverOffline
: errorMessages.clientOffline
Expand Down
4 changes: 2 additions & 2 deletions wp-includes/js/service-worker-offline-commenting.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
};

let body = text.replace(
/[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/,
'{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}',
errorMessages.error
);
body = body.replace(
Expand Down Expand Up @@ -125,7 +125,7 @@
};

const body = text.replace(
/[<]!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/,
'{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}',
errorMessages.comment
);

Expand Down
6 changes: 3 additions & 3 deletions wp-includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ function wp_service_worker_error_details_template( $output = '' ) {
if ( empty( $output ) ) {
$output = '<details id="error-details"><summary>' . esc_html__( 'More Details', 'pwa' ) . '</summary>{{{error_details_iframe}}}</details>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Variable includes iframe tag.
}
echo '<!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->';
echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}}'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints template begin tag.
echo wp_kses_post( $output );
echo '<!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->';
echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}}'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints template end tag.
}

/**
* Display service worker error message template tag.
*/
function wp_service_worker_error_message_placeholder() {
echo '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
echo '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Prints error message placeholder.
}

/**
Expand Down