WC_Webhook_Data_Store::read( WC_Webhook $webhook )
Read a webhook from the database.
Description Description
Parameters Parameters
- $webhook
-
(Required) Webhook instance.
Source Source
File: includes/data-stores/class-wc-webhook-data-store.php
public function read( &$webhook ) {
global $wpdb;
$data = wp_cache_get( $webhook->get_id(), 'webhooks' );
if ( false === $data ) {
$data = $wpdb->get_row( $wpdb->prepare( "SELECT webhook_id, status, name, user_id, delivery_url, secret, topic, date_created, date_modified, api_version, failure_count, pending_delivery FROM {$wpdb->prefix}wc_webhooks WHERE webhook_id = %d LIMIT 1;", $webhook->get_id() ), ARRAY_A ); // WPCS: cache ok, DB call ok.
wp_cache_add( $webhook->get_id(), $data, 'webhooks' );
}
if ( is_array( $data ) ) {
$webhook->set_props(
array(
'id' => $data['webhook_id'],
'status' => $data['status'],
'name' => $data['name'],
'user_id' => $data['user_id'],
'delivery_url' => $data['delivery_url'],
'secret' => $data['secret'],
'topic' => $data['topic'],
'date_created' => '0000-00-00 00:00:00' === $data['date_created'] ? null : $data['date_created'],
'date_modified' => '0000-00-00 00:00:00' === $data['date_modified'] ? null : $data['date_modified'],
'api_version' => $data['api_version'],
'failure_count' => $data['failure_count'],
'pending_delivery' => $data['pending_delivery'],
)
);
$webhook->set_object_read( true );
do_action( 'woocommerce_webhook_loaded', $webhook );
} else {
throw new Exception( __( 'Invalid webhook.', 'woocommerce' ) );
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |