true ]; * }, 10, 2 ); * * And for automation, subscribe to the event bus: `trueplayer/event/{name}`. */ class Integrations { public static function init() { foreach ( self::available() as $integration ) { $integration->register(); } } /** * @return \TruePlayer\Interfaces\IntegrationInterface[] */ public static function all(): array { $built_in = [ // First, so it is the obvious default in the provider picker: it is // the only one that needs nothing installed. new Integrations\WpMail(), ]; return apply_filters( 'trueplayer/integrations/register', $built_in ); } /** * @return \TruePlayer\Interfaces\IntegrationInterface[] */ public static function available(): array { return array_values( array_filter( self::all(), function ( $i ) { return $i->is_available(); } ) ); } public static function get( string $id ) { foreach ( self::all() as $integration ) { if ( $integration->id() === $id ) { return $integration; } } return null; } /** * Generic subscribe pipeline used by the opt-in layer. Routes to the named * provider when available, otherwise lets any listener handle it via the * `trueplayer/subscribe` filter. Always returns a { ok, message } array. */ public static function subscribe( array $data ): array { $provider = $data['provider'] ?? ''; $integration = $provider ? self::get( $provider ) : null; $result = [ 'ok' => false, 'message' => __( 'No subscription provider is configured.', 'trueplayer' ) ]; if ( $integration && $integration->is_available() ) { $result = $integration->subscribe( $data ); } /** * Let any plugin observe or override the outcome (e.g. also push to a * second list, or handle the opt-in when no provider matched). */ $result = apply_filters( 'trueplayer/subscribe', $result, $data ); // Fire an event so webhooks + automation see opt-ins too. if ( ! empty( $result['ok'] ) ) { Events::emit( 'subscriber.added', [ 'video_id' => (int) ( $data['video_id'] ?? 0 ), 'provider' => $provider, 'subject' => [ 'email' => $data['email'] ?? '', 'name' => $data['name'] ?? '' ], ] ); } return $result; } }