Filter
uncanny-automator
automator_{$integration_id}_{$type}
Filter the available items Filters available items for a specific integration type, allowing modification of the list before it's used.
add_filter( 'automator_{$integration_id}_{$type}', $callback, 10, 1 );
Description
Filter the available items for a specific integration type before they are processed. Developers can modify the `$items` array to add, remove, or alter the options presented for triggers or actions within a premium integration. This hook fires after initial item retrieval and before deduplication.
Usage
add_filter( 'automator_{$integration_id}_{$type}', 'your_function_name', 10, 1 );
Parameters
-
$items(array) - The current items
Return Value
array
Examples
<?php
/**
* Example of using the automator_{$integration_id}_{$type} filter hook.
*
* This example assumes you have an integration with ID 'my_plugin' and you are
* filtering 'actions'. It adds a custom action to the list of available actions
* if it's not already present.
*
* @param array $items The current list of actions.
* @return array The modified list of actions.
*/
add_filter( 'automator_my_plugin_actions', function( $items ) {
// Define a new custom action to add.
$new_action_key = 'my_plugin_custom_action';
$new_action_label = 'Perform Custom Action';
// Check if the custom action is already in the list.
if ( ! in_array( $new_action_key, $items, true ) ) {
// If not, add it to the array.
$items[] = $new_action_key;
}
// You might also want to add the label for display purposes if the plugin
// expects both keys and labels, or if it uses keys internally and labels
// for display. The exact structure depends on how the plugin uses these items.
// For simplicity, this example only adds the key. If the plugin expects
// an associative array like ['key' => 'label'], you'd adjust accordingly.
// e.g., if the plugin uses format like:
// $items = ['action_key' => 'Action Label', ...];
// Then you'd modify like this:
// if ( ! array_key_exists( $new_action_key, $items ) ) {
// $items[$new_action_key] = $new_action_label;
// }
return $items;
}, 10, 1 ); // 10 is the default priority, 1 means the function accepts 1 argument.
?>
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/settings/trait-premium-integration-items.php:55
protected function get_available_items( $type ) {
// Validate type.
$this->validate_item_type( $type );
// Get trigger or action items from the integration.
$items = $this->get_items_from_classes( $type );
// Adjust the ID for the filter name.
$integration_id = strtolower( $this->get_id() );
/**
* Filter the available items
*
* @param array $items The current items
* @return array
*/
$items = apply_filters( "automator_{$integration_id}_{$type}", $items );
// Remove duplicates and reindex array
return array_values( array_unique( $items ) );
}