Status::diagnostic_data( array $data )

Summary

Return a list of webhooks for current BC store


Parameters

$data

(array) (Required)


Return

(array)


Source

File: src/BigCommerce/Webhooks/Status.php

	public function diagnostic_data( $data ) {
		$webhooks = $this->api->listWebhooks();

		usort( $webhooks,
            /**
            * order webhooks by scope ASC, is_active DESC, destination ASC
            */
            function ( $a, $b ) {
                if ( $a->scope === $b->scope ) {
                    if ( $a->is_active === $b->active ) {
                        return strcmp( $a->destination, $b->destination );
                    }

                    return $a->is_active ? - 1 : 1;
                }

                return strcmp( $a->scope, $b->scope );
		    }
        );

		$webhook_data = [];

		$scopes = array_unique( wp_list_pluck( $webhooks, 'scope' ) );
		foreach ( $scopes as $scope ) {
			$webhook_data[] = [
				'label' => $scope,
				'key'   => sprintf( 'webhook-%s', $scope ),
				'value' => '<ul>' . implode( array_map( function ( $hook ) {
						$disabled = $hook->is_active ? '' : ( ' ' . __( '(disabled)', 'bigcommerce' ) );

						return sprintf( '<li>%s%s</li>', esc_url( $hook->destination ), $disabled );
					}, array_filter( $webhooks, function ( $hook ) use ( $scope ) {
						return $hook->scope === $scope;
					} ) ) ) . '</ul>',
			];
		}

		$data [] = [
			'label' => __( 'Webhooks', 'bigcommerce' ),
			'key'   => 'webhooks',
			'value' => $webhook_data,
		];

		return $data;
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.