WC_Webhook_Data_Store::read()publicWC 3.3.0

Read a webhook from the database.

Method of the class: WC_Webhook_Data_Store{}

Hooks from the method

Return

null. Nothing (null).

Usage

$WC_Webhook_Data_Store = new WC_Webhook_Data_Store();
$WC_Webhook_Data_Store->read( $webhook );
$webhook(WC_Webhook) (required) (passed by reference — &)
Webhook instance.

Changelog

Since 3.3.0 Introduced.

WC_Webhook_Data_Store::read() code WC 8.7.0

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' ) );
	}
}