10, 'blocking' => true, // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- core's own filter, applied the way spawn_cron() does. 'sslverify' => (bool) apply_filters( 'https_local_ssl_verify', false, $url ), 'body' => array( 'apwc_probe' => '1' ), ) ); $time = (int) round( ( microtime( true ) - $start ) * 1000 ); $code = is_wp_error( $res ) ? 0 : (int) wp_remote_retrieve_response_code( $res ); $ok = $code >= 200 && $code < 300; if ( is_wp_error( $res ) ) { $message = sprintf( /* translators: %s: error message from the HTTP request. */ __( 'Couldn’t reach wp-cron.php from this server: %s', 'admin-powerups-for-woocommerce' ), wp_strip_all_tags( $res->get_error_message() ) ); } elseif ( $ok ) { $message = sprintf( /* translators: 1: HTTP status code, 2: milliseconds. */ __( 'wp-cron.php is reachable (HTTP %1$d in %2$s ms). This shows the server can reach itself, not that events run.', 'admin-powerups-for-woocommerce' ), $code, number_format_i18n( $time ) ); } else { $message = sprintf( /* translators: %d: HTTP status code. */ __( 'wp-cron.php answered HTTP %d. Requests from the server to itself may be blocked (firewall, password protection or a security plugin).', 'admin-powerups-for-woocommerce' ), $code ); } $result = array( 'ok' => $ok, 'code' => $code, 'time_ms' => $time, 'message' => $message, 'checked' => time(), ); set_transient( self::TRANSIENT, $result, self::TTL ); return $result; } /** * The last result, or null when there's none (or it's expired). * * @since 1.0.0 * @return array{ok: bool, code: int, time_ms: int, message: string, checked: int}|null */ public static function last() { $last = get_transient( self::TRANSIENT ); if ( ! is_array( $last ) || ! isset( $last['ok'], $last['message'], $last['checked'] ) ) { return null; } return array( 'ok' => (bool) $last['ok'], 'code' => (int) ( $last['code'] ?? 0 ), 'time_ms' => (int) ( $last['time_ms'] ?? 0 ), 'message' => is_string( $last['message'] ) ? $last['message'] : '', 'checked' => (int) $last['checked'], ); } }