Webhooks keyed by their identifier. */ public function all( Form $form ): array { $stored = $form->setting( self::SETTING, array() ); $stored = is_array( $stored ) ? $stored : array(); $webhooks = array(); foreach ( $stored as $key => $data ) { $key = sanitize_key( (string) $key ); if ( '' === $key || ! is_array( $data ) ) { continue; } $webhooks[ $key ] = Webhook::from_array( $key, $data ); } /** * Filters the webhooks of a form. * * Lets a site send submissions somewhere without storing an endpoint, and * a secret, in the database. * * @since 1.0.0 * * @param array $webhooks Webhooks keyed by identifier. * @param Form $form Form they belong to. */ $webhooks = (array) apply_filters( 'formpilot_webhooks', $webhooks, $form ); return array_filter( $webhooks, static fn( $webhook ): bool => $webhook instanceof Webhook ); } /** * Returns the webhooks that should receive a submission. * * @param Form $form Form to read. * * @return array Webhooks keyed by their identifier. */ public function active( Form $form ): array { return array_filter( $this->all( $form ), static fn( Webhook $webhook ): bool => $webhook->is_active() ); } /** * Returns one webhook of a form. * * @param Form $form Form to read. * @param string $key Webhook identifier. * * @return Webhook|null The webhook, or null when the form has no such entry. */ public function find( Form $form, string $key ): ?Webhook { return $this->all( $form )[ sanitize_key( $key ) ] ?? null; } }