$message Message. * @param array $config Channel config. * @return true|\WP_Error */ public function send( array $message, array $config ) { $title = $this->escape( (string) $message['title'] ); $body = '' !== (string) ( $message['intro'] ?? '' ) ? $this->escape( (string) $message['intro'] ) . "\n" : ''; foreach ( $this->item_lines( $message ) as $line ) { $body .= '• ' . $this->escape( $line ) . "\n"; } $blocks = array( array( 'type' => 'header', 'text' => array( 'type' => 'plain_text', 'text' => mb_substr( (string) $message['title'], 0, 150 ), ), ), ); if ( '' !== trim( $body ) ) { $blocks[] = array( 'type' => 'section', 'text' => array( 'type' => 'mrkdwn', 'text' => mb_substr( $body, 0, 2900 ), ), ); } $blocks[] = array( 'type' => 'context', 'elements' => array( array( 'type' => 'mrkdwn', 'text' => sprintf( '<%s|%s> · %s', esc_url_raw( (string) $message['url'] ), $this->escape( (string) $message['link_label'] ), $this->escape( (string) $message['site'] ) ), ), ), ); return $this->post_json( (string) $config['webhook_url'], array( 'text' => $title, // Notification preview text. 'blocks' => $blocks, ) ); } /** * Escape the three characters Slack treats as control characters. * * @param string $text Text. */ private function escape( string $text ): string { return str_replace( array( '&', '<', '>' ), array( '&', '<', '>' ), $text ); } }