Skip to content
Open
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
54 changes: 54 additions & 0 deletions assets/js/fair-site-health.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { __, sprintf } = wp.i18n;

wp.hooks.addFilter( 'site_status_test_result', 'fair/fair-plugin/site-health', function( response_data ) {
if ( 'dotorg_communication' !== response_data['test'] ) {
return response_data;
}

// parsing the API error message out of a core translation as there is no current way to get that directly
const regex = new RegExp( fairSiteHealth.errorMessageRegex, 'gim' );
let matches = regex.exec( response_data.description );
const errorMessage = (matches && matches[1] != null) ? matches[1] : '';

response_data.description = sprintf(
'<p>%s</p>',
__( 'Communicating with the update servers is used to check for new versions, and to both install and update WordPress core, themes or plugins.', 'fair' )
);
switch ( response_data['status'] ) {
case 'critical' :
response_data.label = sprintf(
__( 'Could not reach %s' , 'fair' ),
fairSiteHealth.defaultRepoDomain
);
response_data.description += sprintf(
'<p>%s</p>',
sprintf(
'<span class="error"><span class="screen-reader-text">%s</span></span> %s',
/* translators: Hidden accessibility text. */
__( 'Error', 'fair' ),
sprintf(
/* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
__( 'Your site is unable to reach update server at %1$s, and returned the error: %2$s', 'fair' ),
fairSiteHealth.repoIPAddress,
errorMessage
)
)
);
response_data.actions = sprintf(
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Localized Support reference. */
__( 'https://wordpress.org/support/forums/', 'fair' ),
__( 'Get help resolving this issue.', 'fair' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)', 'fair' )
);
break;
case 'good' :
response_data.label = sprintf(
__( 'Can communicate with %s' , 'fair' ),
fairSiteHealth.defaultRepoDomain
);
break;
}
return response_data;
});
1 change: 1 addition & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function bootstrap() {
Pings\bootstrap();
Salts\bootstrap();
Settings\bootstrap();
Site_Health\bootstrap();
User_Notification\bootstrap();
Version_Check\bootstrap();

Expand Down
42 changes: 42 additions & 0 deletions inc/site-health/namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Implements the plugin settings page.
*
* @package FAIR
*/

namespace FAIR\Site_Health;

/**
* Bootstrap.
*/
function bootstrap() {
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\enqueue_media_scripts' );
}

function enqueue_media_scripts( $hook_suffix ) {

if ( 'site-health.php' !== $hook_suffix ) {
return;
}

wp_enqueue_script( 'fair-site-health', esc_url( plugin_dir_url( \FAIR\PLUGIN_FILE ) . 'assets/js/fair-site-health.js' ), [ 'wp-i18n' ], \FAIR\VERSION, true );
wp_localize_script( 'fair-site-health', 'fairSiteHealth',
[
'defaultRepoDomain' => \FAIR\Default_Repo\get_default_repo_domain(),
'repoIPAddress' => gethostbyname( \FAIR\Default_Repo\get_default_repo_domain() ),
'errorMessageRegex' => build_error_message_regex(),
]
);

}

function build_error_message_regex() {
$regex = str_replace(
[ '%1\$s', '%2\$s' ],
[ '(?:.*?)', '(.*)'],
preg_quote( __( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s' ) )
);
$regex = $regex . '<\/p>';
return $regex;
}
1 change: 1 addition & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require_once __DIR__ . '/inc/pings/namespace.php';
require_once __DIR__ . '/inc/salts/namespace.php';
require_once __DIR__ . '/inc/settings/namespace.php';
require_once __DIR__ . '/inc/site-health/namespace.php';
require_once __DIR__ . '/inc/user-notification/namespace.php';
require_once __DIR__ . '/inc/version-check/namespace.php';

Expand Down