Filter
uncanny-automator
automator_get_trigger_sentence
Filters the sentence used to describe a trigger, allowing modification of its output.
add_filter( 'automator_get_trigger_sentence', $callback, 10, 3 );
Description
Fires after a trigger's sentence is retrieved. Developers can modify the sentence for a specific trigger ID and type, or return a custom sentence structure. This hook is an alias for `get_trigger_sentence` and is deprecated in favor of it.
Usage
add_filter( 'automator_get_trigger_sentence', 'your_function_name', 10, 3 );
Parameters
-
$sentence(mixed) - This parameter holds the dynamically generated sentence describing the trigger, which can be modified by filters.
-
$id(mixed) - The sentence generated to describe the trigger.
-
$type(mixed) - This parameter represents the unique identifier of the trigger.
Return Value
The filtered value.
Examples
/**
* Customize the trigger sentence for a specific trigger type.
*
* This function checks if the trigger type is 'new_post' and, if so,
* modifies the default sentence to be more descriptive.
*
* @param mixed $sentence The original trigger sentence.
* @param mixed $id The trigger ID.
* @param mixed $type The trigger type.
* @return mixed The modified or original trigger sentence.
*/
add_filter(
'automator_get_trigger_sentence',
function( $sentence, $id, $type ) {
// Check if the trigger type is 'new_post' and if the sentence is an array (as expected)
if ( 'new_post' === $type && is_array( $sentence ) ) {
// Add a custom sentence for the 'new_post' trigger type.
// This assumes the $sentence array is intended to hold sentences keyed by type.
$sentence['new_post'] = __( 'A new post is published in WordPress', 'your-text-domain' );
}
return $sentence;
},
10, // Priority
3 // Accepted arguments
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/utilities/class-automator-get-data.php:894
public function trigger_sentence( $id, $type = '' ) {
global $wpdb;
$trigger_meta = $wpdb->get_results(
$wpdb->prepare(
"SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d",
$id
)
);
$sentence = $this->get_trigger_action_sentence( $id );
$sentence = apply_filters_deprecated(
'get_trigger_sentence',
array( $sentence, $type, $trigger_meta ),
'3.0',
'automator_get_trigger_sentence'
);
$sentence = apply_filters( 'automator_get_trigger_sentence', $sentence, $id, $type );
if ( in_array( $type, array_keys( $sentence ), true ) ) {
return $sentence[ $type ];
}
return $sentence;
}