Automattic\WooCommerce\Internal\PushNotifications\Dispatchers
WpcomNotificationDispatcher::make_request
Makes the WPCOM API request via the Jetpack connection.
Method of the class: WpcomNotificationDispatcher{}
No Hooks.
Returns
Array|WP_Error.
Usage
// private - for code of main (parent) class only $result = $this->make_request( $site_id, $payload, $tokens );
- $site_id(int) (required)
- The Jetpack site ID.
- $payload(array) (required)
- The notification payload.
- $tokens(PushToken[]) (required)
- The push tokens.
Changelog
| Since 10.7.0 | Introduced. |
WpcomNotificationDispatcher::make_request() WpcomNotificationDispatcher::make request code WC 10.7.0
private function make_request( int $site_id, array $payload, array $tokens ) {
$body = wp_json_encode(
array_merge(
$payload,
array(
'tokens' => array_map(
fn ( PushToken $token ) => $token->to_wpcom_format(),
$tokens
),
)
)
);
if ( false === $body ) {
return new WP_Error( 'json_encode_failed', 'Failed to encode push notification payload.' );
}
// @phpstan-ignore return.type
return Jetpack_Connection_Client::wpcom_json_api_request_as_blog(
sprintf( '/sites/%d/%s', $site_id, self::SEND_ENDPOINT ),
self::WPCOM_API_VERSION,
array(
'headers' => array( 'Content-Type' => 'application/json' ),
'method' => 'POST',
'timeout' => self::REQUEST_TIMEOUT,
),
$body,
'wpcom'
);
}