Factory Setup
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. |