WordPress at Your Fingertips
function is not described

WC_API_Webhooks::query_webhooks() private WC 2.2

Helper method to get webhook post objects

{} It's a method of the class: WC_API_Webhooks{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->query_webhooks( $args );
$args(array) (required)
Request arguments for filtering query.

Changelog

Since 2.2 Introduced.

Code of WC_API_Webhooks::query_webhooks() WC 5.7.1

private function query_webhooks( $args ) {
	$args = $this->merge_query_args( array(), $args );

	$args['limit'] = isset( $args['posts_per_page'] ) ? intval( $args['posts_per_page'] ) : intval( get_option( 'posts_per_page' ) );

	if ( empty( $args['offset'] ) ) {
		$args['offset'] = 1 < $args['paged'] ? ( $args['paged'] - 1 ) * $args['limit'] : 0;
	}

	$page = $args['paged'];
	unset( $args['paged'], $args['posts_per_page'] );

	if ( isset( $args['s'] ) ) {
		$args['search'] = $args['s'];
		unset( $args['s'] );
	}

	// Post type to webhook status.
	if ( ! empty( $args['post_status'] ) ) {
		$args['status'] = $args['post_status'];
		unset( $args['post_status'] );
	}

	if ( ! empty( $args['post__in'] ) ) {
		$args['include'] = $args['post__in'];
		unset( $args['post__in'] );
	}

	if ( ! empty( $args['date_query'] ) ) {
		foreach ( $args['date_query'] as $date_query ) {
			if ( 'post_date_gmt' === $date_query['column'] ) {
				$args['after']  = isset( $date_query['after'] ) ? $date_query['after'] : null;
				$args['before'] = isset( $date_query['before'] ) ? $date_query['before'] : null;
			} elseif ( 'post_modified_gmt' === $date_query['column'] ) {
				$args['modified_after']  = isset( $date_query['after'] ) ? $date_query['after'] : null;
				$args['modified_before'] = isset( $date_query['before'] ) ? $date_query['before'] : null;
			}
		}

		unset( $args['date_query'] );
	}

	$args['paginate'] = true;

	// Get the webhooks.
	$data_store = WC_Data_Store::load( 'webhook' );
	$results    = $data_store->search_webhooks( $args );

	// Get total items.
	$headers              = new stdClass;
	$headers->page        = $page;
	$headers->total       = $results->total;
	$headers->is_single   = $args['limit'] > $headers->total;
	$headers->total_pages = $results->max_num_pages;

	return array(
		'results' => $results->webhooks,
		'headers' => $headers,
	);
}