$url ); } /** * Send alert via Slack incoming webhook. * * @param string $subject Alert subject / title. * @param string $body Alert body text. * @param array $context Channel context (webhook_url). * @return bool True on HTTP 2xx response. */ public static function actually_send( string $subject, string $body, array $context ): bool { $url = (string) ( $context['webhook_url'] ?? '' ); if ( '' === $url ) { return false; } // Slack mrkdwn — bold subject + plaintext body in code block for readability. $payload = wp_json_encode( array( 'text' => "*{$subject}*\n```\n{$body}\n```", ) ); $resp = wp_remote_post( $url, array( 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => $payload, 'timeout' => 5, 'blocking' => true, ) ); if ( is_wp_error( $resp ) ) { return false; } $code = (int) wp_remote_retrieve_response_code( $resp ); return $code >= 200 && $code < 300; } }