Hooks

Class Hooks.


Source

File: src/Tickets_Plus/Emails/Hooks.php

class Hooks extends tad_DI52_ServiceProvider {

	/**
	 * Binds and sets up implementations.
	 *
	 * @since 5.6.6
	 */
	public function register() {
		$this->add_actions();
		$this->add_filters();
	}

	/**
	 * Adds the actions required by each Tickets Emails component.
	 *
	 * @since 5.6.6
	 */
	protected function add_actions() {
		add_action( 'tribe_template_before_include:tickets/v2/emails/template-parts/body/ticket/holder-name', [ $this, 'maybe_add_ticket_qr_code' ], 10, 3 );

		// Include Attendee Registration Fields in Ticket & RSVP emails.
		add_action( 'tribe_template_after_include:tickets/v2/emails/template-parts/body/ticket/security-code', [ $this, 'maybe_include_attendee_registration_fields_ticket_rsvp_emails' ], 10, 3 );

		add_action( 'tribe_template_after_include:tickets/v2/emails/template-parts/header/head/styles', [ $this, 'maybe_include_attendee_registration_fields_styles' ], 10, 3 );
	}

	/**
	 * Adds the filters required by each Tickets Emails component.
	 *
	 * @since 5.6.6
	 */
	protected function add_filters() {
		add_filter( 'tec_tickets_emails_settings_email_styling_fields', [ $this, 'filter_tickets_emails_settings' ] );

		// Ticket Email.
		add_filter( 'tec_tickets_emails_ticket_settings', tribe_callback( Email\Ticket::class, 'filter_tec_tickets_emails_ticket_settings' ), 10 );

		// RSVP.
		add_filter( 'tec_tickets_emails_rsvp_settings', tribe_callback( Email\RSVP::class, 'filter_tec_tickets_emails_rsvp_settings' ), 10 );

		add_filter( 'tec_tickets_emails_email_template_context', [ $this, 'filter_email_template_context' ] );

		add_filter( 'tribe_tickets_get_template_part_content', [ $this, 'filter_email_qr_template' ], 10, 6 );
	}

	/**
	 * Filters the list of fields for Tickets Emails settings, and add the footer credit setting.
	 *
	 * @since 5.6.6
	 *
	 * @param array $fields The current list of fields for Tickets Emails settings.
	 *
	 * @return array The filtered list of fields.
	 */
	public function filter_tickets_emails_settings( array $fields ): array {
		return tribe( Settings::class )->add_footer_credit_setting( $fields );
	}

	/**
	 * Adds QR code template, if settings allow.
	 *
	 * @param string           $file        Template file.
	 * @param string           $name        Template name.
	 * @param \Tribe__Template $et_template Event Tickets template object.
	 * @return void
	 */
	public function maybe_add_ticket_qr_code( $file, $name, $et_template ) {
		/** @var \Tribe__Tickets_Plus__Template $template */
		$template = tribe( 'tickets-plus.template' );

		$include_qr = tribe_get_option( Email\Ticket::$option_ticket_include_qr_codes, true );

		if ( empty( $include_qr ) ) {
			return;
		}

		$args               = $et_template->get_local_values();
		$args['include_qr'] = $include_qr;

		$args['qr'] = $args['preview'] ?
			esc_url( plugins_url( '/event-tickets-plus/src/resources/images/example-qr.png' ) ):
			tribe( Tribe__Tickets_Plus__QR::class )->get_qr_url( $args['ticket'] );

		$template->template( 'v2/emails/template-parts/body/ticket/qr-image', $args, true );
	}

	/**
	 * Filters the context array from the email tickets template.
	 *
	 * @since 5.6.6
	 *
	 * @param array $context Context array from event tickets emails template.
	 *
	 * @return array Filtered context.
	 */
	public function filter_email_template_context( $context ): array {

		// Add footer credit option from settings.
		$context['footer_credit'] = tribe_get_option( Settings::$option_footer_credit, true );

		return $context;
	}

	/**
	 * Maybe include Attendee Registration Fields for RSVP and Tickets emails.
	 *
	 * @since 5.6.10
	 *
	 * @param string           $file        Template file.
	 * @param string           $name        Template name.
	 * @param \Tribe__Template $et_template Event Tickets template object.
	 * @return void
	 */
	public function maybe_include_attendee_registration_fields_ticket_rsvp_emails( $file, $name, $et_template ) {
		if ( ! $et_template instanceof \Tribe__Template ) {
			return;
		}

		$this->container->make( Email\RSVP::class )->maybe_include_ar_fields( $et_template );
		$this->container->make( Email\Ticket::class )->maybe_include_ar_fields( $et_template );
	}

	/**
	 * Maybe include Attendee Registration Fields Styles.
	 *
	 * @since 5.6.10
	 *
	 * @param string           $file        Template file.
	 * @param string           $name        Template name.
	 * @param \Tribe__Template $et_template Event Tickets template object.
	 * @return void
	 */
	public function maybe_include_attendee_registration_fields_styles( $file, $name, $et_template ) {
		if ( ! $et_template instanceof \Tribe__Template ) {
			return;
		}

		$this->container->make( Email\RSVP::class )->maybe_include_ar_fields_styles( $et_template );
		$this->container->make( Email\Ticket::class )->maybe_include_ar_fields_styles( $et_template );
	}

	/**
	 * Filter email QR template.
	 *
	 * @since 5.6.10
	 *
	 * @param string $html     The final HTML
	 * @param string $template The Template file, which is a relative path from the Folder we are dealing with
	 * @param string $file     Complete path to include the PHP File
	 * @param string $slug     Slug for this template
	 * @param string $name     Template name
	 * @param array  $data     The Data that will be used on this template
	 *
	 * @return string
	 */
	public function filter_email_qr_template( $html, $template, $file, $slug, $name, $data ): string {

		if ( ! tec_tickets_emails_is_enabled() ) {
			return $html;
		}

		if ( 'tickets-plus/email-qr' !== $slug ) {
			return $html;
		}

		$data['include_qr'] = true;

		return tribe( 'tickets-plus.template' )->template( 'v2/emails/template-parts/body/ticket/qr-image', $data, false );
	}
}

Top ↑

Changelog

Changelog
Version Description
5.6.6 Introduced.

Top ↑

Methods