plugin = $plugin; } /** * Registers the tests. */ public function register(): void { add_filter( 'site_status_tests', array( $this, 'add_tests' ) ); } /** * Adds the tests. * * @param array $tests Tests. */ public function add_tests( array $tests ): array { $ours = array( 'tidelist_scheduler' => array( __( 'Tidelist background jobs', 'tidelist' ), 'test_scheduler' ), 'tidelist_cron' => array( __( 'Tidelist WP-Cron', 'tidelist' ), 'test_cron' ), 'tidelist_images' => array( __( 'Tidelist photo conversion', 'tidelist' ), 'test_images' ), 'tidelist_https' => array( __( 'Tidelist HTTPS', 'tidelist' ), 'test_https' ), 'tidelist_connection' => array( __( 'Tidelist marketplace connection', 'tidelist' ), 'test_connection' ), ); foreach ( $ours as $key => $test ) { $tests['direct'][ $key ] = array( 'label' => $test[0], 'test' => array( $this, $test[1] ), ); } return $tests; } /** * Background jobs. */ public function test_scheduler(): array { $now = time(); return $this->wrap( Reliability::evaluate( $this->plugin->job_monitor()->facts( $now ), $now ), 'tidelist_scheduler' ); } /** * WP-Cron. */ public function test_cron(): array { return $this->wrap( Checks::cron( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), 'tidelist_cron' ); } /** * Image libraries. */ public function test_images(): array { $gd = function_exists( 'imagecreatefromwebp' ) && function_exists( 'imagejpeg' ); return $this->wrap( Checks::images( $gd, extension_loaded( 'imagick' ) ), 'tidelist_images' ); } /** * HTTPS. */ public function test_https(): array { return $this->wrap( Checks::https( is_ssl() || 0 === strpos( home_url(), 'https://' ) ), 'tidelist_https' ); } /** * Marketplace connection. */ public function test_connection(): array { $worst = null; foreach ( $this->plugin->channels()->all() as $channel ) { $connection = $channel->connection(); $check = Checks::connection( $connection->connected, $connection->expires_at, time(), $channel->label() ); if ( null === $worst || Checks::GOOD === $worst['status'] || ( Checks::CRITICAL === $check['status'] && Checks::CRITICAL !== $worst['status'] ) ) { $worst = $check; } } return $this->wrap( $worst ?? Checks::connection( false, 0, time() ), 'tidelist_connection' ); } /** * Site Health result structure. * * @param array $check Check result. * @param string $test Test key. */ private function wrap( array $check, string $test ): array { return array( 'label' => $check['label'], 'status' => $check['status'], 'badge' => array( 'label' => 'Tidelist', 'color' => Checks::CRITICAL === $check['status'] ? 'red' : ( Checks::RECOMMENDED === $check['status'] ? 'orange' : 'blue' ), ), 'description' => '

' . esc_html( $check['description'] ) . '

', 'actions' => '', 'test' => $test, ); } }