-
Notifications
You must be signed in to change notification settings - Fork 38
rework dotorg_connectivity site health check #9 #30
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
Open
ideag
wants to merge
2
commits into
fairpm:main
Choose a base branch
from
ideag:9-site-health-checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.