'good'|'recommended'|'critical', 'label' => string, 'description' => string]. * * @package Tidelist */ namespace Tidelist\Health; use Tidelist\Support\Text; /** * Health checks. */ final class Checks { const GOOD = 'good'; const RECOMMENDED = 'recommended'; const CRITICAL = 'critical'; /** * WP-Cron: warns when it is switched off, because a real cron job must then call it. * * @param bool $cron_disabled DISABLE_WP_CRON is true. */ public static function cron( bool $cron_disabled ): array { if ( $cron_disabled ) { return self::result( self::RECOMMENDED, 'WP-Cron is switched off', 'DISABLE_WP_CRON is on. Tidelist only works in the background if a real cron job calls wp-cron.php every few minutes. Ask your hosting provider how to set one up.' ); } return self::result( self::GOOD, 'WP-Cron is on', 'Background jobs are triggered by visits to the site.' ); } /** * Image library: .webp photos are converted to JPG for the marketplace. * * @param bool $gd_webp GD can read .webp. * @param bool $imagick Imagick is available. */ public static function images( bool $gd_webp, bool $imagick ): array { if ( $gd_webp || $imagick ) { return self::result( self::GOOD, 'Photos can be converted', 'The server can convert .webp photos to JPG for the marketplace.' ); } return self::result( self::RECOMMENDED, 'Photos in .webp cannot be converted', 'The server has neither GD with .webp support nor Imagick. Products with only .webp photos cannot be published. Ask your hosting provider to enable one of them.' ); } /** * HTTPS: the marketplace OAuth return address and photo addresses should be secure. * * @param bool $is_ssl The site address starts with https. */ public static function https( bool $is_ssl ): array { if ( $is_ssl ) { return self::result( self::GOOD, 'The site uses HTTPS', 'The return address registered at the marketplace and the photo addresses are secure.' ); } return self::result( self::RECOMMENDED, 'The site does not use HTTPS', 'Marketplaces expect secure addresses for the connection and for photos. Switch the site to HTTPS.' ); } /** * Marketplace connection. * * @param bool $connected An account is connected. * @param int $refresh_expires_at Unix time when the connection runs out (0 = unknown). * @param int $now Now (Unix). * @param string $channel_label Marketplace name. */ public static function connection( bool $connected, int $refresh_expires_at, int $now, string $channel_label = 'marketplace' ): array { if ( ! $connected ) { return self::result( self::RECOMMENDED, Text::channel( 'No {channel} account is connected', $channel_label ), Text::channel( 'Connect your {channel} account on the Tidelist Connect screen.', $channel_label ) ); } if ( $refresh_expires_at > 0 && $refresh_expires_at < $now ) { return self::result( self::CRITICAL, Text::channel( 'The {channel} connection has expired', $channel_label ), Text::channel( 'Reconnect your {channel} account on the Tidelist Connect screen. Adverts are not taken down while the connection is expired.', $channel_label ) ); } if ( $refresh_expires_at > 0 && $refresh_expires_at - $now < 3 * DAY_IN_SECONDS ) { return self::result( self::RECOMMENDED, Text::channel( 'The {channel} connection runs out soon', $channel_label ), 'It is renewed automatically every day. If this stays, check that background jobs run.' ); } return self::result( self::GOOD, Text::channel( 'The {channel} connection is valid', $channel_label ), 'It is renewed automatically every day.' ); } /** * Result array. * * @param string $status Status. * @param string $label Label. * @param string $description Description. */ private static function result( string $status, string $label, string $description ): array { return array( 'status' => $status, 'label' => $label, 'description' => $description, ); } }