English (United Kingdom)

do_action( 'vikrestaurants_before_query_conditional_texts', Factory $factory )

Fires while constructing the factory object used to create the supported actions and filters of the conditional texts feature.


Description 

Trigger hook to let the plugins register new conditional text actions and filters.

The filters are used to extend the conditions needed to apply a conditional text to a notification e-mail. The actions are the rules used to enhance the information of the notification e-mail. The actions are applied only in case all the configured filters are verified.

In order to extend the list of supported filters, you need to attach your classes to the $factory object as described below.

$factory->registerFilterProvider('custom', function(array $options) {
    require_once dirname(__FILE__) . '/filters/CustomFilter.php';
    return new CustomFilter($options);
});

The registered filters must inherit the E4J\VikRestaurants\Mail\ConditionalText\ConditionalTextFilter class, otherwise they will be ignored.

In order to extend the list of supported actions, you need to attach your classes to the $factory object as described below.

$factory->registerActionProvider('custom', function(array $options) {
    require_once dirname(__FILE__) . '/actions/CustomAction.php';
    return new CustomAction($options);
});

The registered actions must inherit the E4J\VikRestaurants\Mail\ConditionalText\ConditionalTextAction class, otherwise they will be ignored.


Parameters

$factory

(Factory)  The factory class used to instantiate conditional text filters and actions. This class is part of the E4J\VikRestaurants\Mail\ConditionalText namespace.


Example

The example below explains how to support custom filters and actions for the conditional texts.

/**
 * Trigger event to let the plugins register new conditional text actions and filters. 
 *
 * @param  Factory  $factory
 *
 * @since  1.3
 */
add_action('vikrestaurants_setup_conditional_texts', function($factory) {
    // register "custom" filter
    $factory->registerFilterProvider('custom', function(array $options) {
        // anonymous classes are supported too, but still need to implement the ConditionalTextFilter interface
        return new class ($options) implements E4J\VikRestaurants\Mail\ConditionalText\ConditionalTextFilter {
            /**
             * @inheritDoc
             */
            public function isEligible(string $templateId, array $data) {
                /**
                 * @todo check whether the conditional text is eligible or not
                 */

                return false;
            }
        };
    });

    // register "custom" action
    $factory->registerActionProvider('custom', function(array $options) {
        // anonymous classes are supported too, but still need to implement the ConditionalTextAction interface
        return new class ($options) implements E4J\VikRestaurants\Mail\ConditionalText\ConditionalTextAction {
            /**
             * @inheritDoc
             */
            public function preflight(Mail $mail) {
                // do stuff before executing the apply method, if needed
            }

            /**
             * @inheritDoc
             */
            public function apply(Mail $mail) {
                // extend the $mail object with the provided information
            }
        };
    });
});

Changelog

Version Description
1.3 Introduced.
Last Update: 2023-12-20
Helpful?

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.