WC_Webhook::build_payload
Build the payload data for the webhook.
Метод класса: WC_Webhook{}
Хуки из метода
Возвращает
Разное. Payload data.
Использование
$WC_Webhook = new WC_Webhook(); $WC_Webhook->build_payload( $resource_id );
- $resource_id(разное) (обязательный)
- First hook argument, typically the resource ID.
Список изменений
| С версии 2.2.0 | Введена. |
Код WC_Webhook::build_payload() WC Webhook::build payload WC 10.4.2
public function build_payload( $resource_id ) {
// Build the payload with the same user context as the user who created
// the webhook -- this avoids permission errors as background processing
// runs with no user context.
$current_user = get_current_user_id();
wp_set_current_user( $this->get_user_id() );
$resource = $this->get_resource();
$event = $this->get_event();
// If a resource has been deleted, just include the ID.
if ( 'deleted' === $event ) {
$payload = array(
'id' => $resource_id,
);
} elseif ( in_array( $this->get_api_version(), wc_get_webhook_rest_api_versions(), true ) ) {
$payload = $this->get_wp_api_payload( $resource, $resource_id, $event );
} else {
if ( ! WC()->legacy_rest_api_is_available() ) {
throw new \Exception( 'The Legacy REST API plugin is not installed on this site. More information: https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/ ' );
}
$payload = wc()->api->get_webhook_api_payload( $resource, $resource_id, $event );
}
// Restore the current user.
wp_set_current_user( $current_user );
return apply_filters( 'woocommerce_webhook_payload', $payload, $resource, $resource_id, $this->get_id() );
}