PluginProbe
Depicter — Popup & Slider Builder / 1.5.2
Depicter — Popup & Slider Builder v1.5.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / WordPress / SystemCheckService.php

SystemCheckService.php in Depicter — Popup & Slider Builder 1.5.2, at app/src/WordPress/SystemCheckService.php

84 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\WordPress;
3
4 class SystemCheckService {
5
6 /**
7 * SystemCheckService constructor.
8 */
9 public function __construct(){
10 add_filter( 'site_status_tests', array( $this, 'system_status_check' ) );
11 }
12
13 /**
14 * Add extra checking for system health
15 *
16 * @param $tests
17 *
18 * @return mixed
19 */
20 public function system_status_check( $tests ) {
21
22 $tests['direct']['depicter_curl_check'] = array(
23 'label' => __( 'Check to access depicter resources servers.', 'depicter' ),
24 'test' => array( $this, 'check_server_connection' )
25 );
26
27 return $tests;
28 }
29
30 /**
31 * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
32 */
33 public function check_server_connection() {
34 $result = array(
35 'label' => __( 'Connecting to depicter resources servers passed successfully', 'depicter' ),
36 'status' => 'good',
37 'badge' => array(
38 'label' => __( 'Performance' ),
39 'color' => 'blue',
40 ),
41 'actions' => '',
42 'test' => 'check_server_connection',
43 'description' => __( 'Connecting to depicter resources servers passed successfully', 'depicter' )
44 );
45
46 try {
47 $response = \Depicter::remote()->get( \Depicter::remote()->endpoint() . 'v1/core/version-check/latest' );
48
49 if ( $response->getStatusCode() != 200 ) {
50 $result['status'] = 'critical';
51
52 $result['description'] = $this->getErrorOuput();
53 $result['label'] = __( 'Error while trying to connect to depicter resources servers', 'depicter' );
54 }
55 } catch( \Exception $exception ) {
56 $result['status'] = 'critical';
57
58 $result['description'] = $this->getErrorOuput();
59 $result['label'] = __( 'Error while trying to connect to depicter resources servers', 'depicter' );
60 }
61 return $result;
62 }
63
64 /**
65 * Get error output
66 *
67 * @return string
68 */
69 public function getErrorOuput() {
70 $screen_reader = __( 'Error', 'depicter' );
71 $message = __( 'Your site cannot communicate securely with depicter services. Contact your host provider and ask them to whitelist <code>depicter.com</code> to gain access to assets library', 'depicter' );
72 $message = "<span class='dashicons error'><span class='screen-reader-text'>$screen_reader</span></span> $message";
73
74 $output = '<ul>';
75 $output .= sprintf(
76 '<li>%s</li>',
77 $message
78 );
79 $output .= '</ul>';
80
81 return $output;
82 }
83 }
84