Filter uncanny-automator

automator_recipe_main_objectstructuretriggers

Filters the structure of triggers available for recipes, allowing modification before they are displayed.

add_filter( 'automator_recipe_main_objectstructuretriggers', $callback, 10, 2 );

Description

Filters the triggers object used within the main recipe structure. Developers can modify or replace the default triggers object to customize how triggers are handled or displayed in recipes. This filter runs when the recipe structure is being built.


Usage

add_filter( 'automator_recipe_main_objectstructuretriggers', 'your_function_name', 10, 2 );

Parameters

$triggers (mixed)
This parameter holds an array of trigger objects that represent the triggers configured for the recipe.
$this (mixed)
This parameter contains the array of trigger objects for the recipe.

Return Value

The filtered value.


Examples

<?php
/**
 * Adds a custom trigger to the Automator recipe structure.
 *
 * This function hooks into the 'automator_recipe_main_objectstructuretriggers' filter
 * to register a new trigger type that is not part of the default set.
 *
 * @param Uncanny_AutomatorCoreServicesRecipeStructureTriggersTriggers $triggers The existing triggers object.
 * @param Uncanny_AutomatorCoreServicesRecipeRecipe The current recipe object.
 *
 * @return Uncanny_AutomatorCoreServicesRecipeStructureTriggersTriggers The modified triggers object.
 */
function my_custom_automator_trigger( $triggers, $recipe ) {
	// Ensure we are working with the correct object type.
	if ( ! is_a( $triggers, 'Uncanny_AutomatorCoreServicesRecipeStructureTriggersTriggers' ) ) {
		return $triggers;
	}

	// If you have a custom trigger class, you would instantiate and add it here.
	// For this example, let's imagine we have a custom trigger class located at:
	// 'My_PluginAutomatorCustom_TriggersMy_New_Trigger'

	// If your custom trigger needs to be passed the recipe object, you would do so.
	// $my_new_trigger_instance = new My_PluginAutomatorCustom_TriggersMy_New_Trigger( $recipe );

	// For demonstration purposes, let's assume we have a simple way to add a trigger
	// by extending the existing Triggers object or using a method it provides.
	// In a real-world scenario, you'd likely extend or modify the Triggers object
	// more deeply or register triggers through a dedicated method if provided by the plugin.

	// Example of how you *might* add a new trigger if the $triggers object had a method like 'add_trigger'.
	// This is hypothetical and depends on the actual structure of the Uncanny Automator plugin.
	// if ( method_exists( $triggers, 'add_trigger' ) ) {
	//     $triggers->add_trigger( $my_new_trigger_instance );
	// }

	// For now, we'll just return the original triggers object, but this is where
	// you would add your custom logic to register your new trigger.
	// The actual implementation would involve registering your trigger class
	// with Uncanny Automator's internal systems, potentially by adding it to
	// an internal array or calling a registration method.

	// If you were to add a completely new trigger type, you would likely need to:
	// 1. Create your custom trigger class that extends a base Uncanny Automator trigger class.
	// 2. Register your custom trigger class with Uncanny Automator's systems, perhaps
	//    by adding it to a list within the Triggers object or using another registration hook.

	// Since the provided context shows the initialization of $triggers as:
	// $triggers = new StructureTriggersTriggers( $this );
	// the modification would likely involve interacting with methods or properties
	// of this $triggers object to add your custom trigger.

	// As a placeholder, we'll just return the object. In a real scenario, you'd
	// modify $triggers here to include your custom trigger.
	return $triggers;
}
add_filter( 'automator_recipe_main_objectstructuretriggers', 'my_custom_automator_trigger', 10, 2 );

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/services/recipe/structure.php:192

private function hydrate_properties() {

		$this->is_recipe_on = 'publish' === self::$post['post_status'];
		$this->title        = self::$post['post_title'];
		$this->recipe_type  = isset( self::$meta['uap_recipe_type'] ) ? self::$meta['uap_recipe_type'] : '';

		$stats         = new StructureStats( $this );
		$miscellaneous = new StructureMiscellaneous( $this );
		$triggers      = new StructureTriggersTriggers( $this );
		$actions       = new StructureActionsActions( $this, self::$meta );

		$this->stats         = apply_filters( 'automator_recipe_main_objectstructurestats', $stats, $this );
		$this->miscellaneous = apply_filters( 'automator_recipe_main_objectstructuremiscellaneous', $miscellaneous, $this );
		$this->triggers      = apply_filters( 'automator_recipe_main_objectstructuretriggers', $triggers, $this );
		// @see Conditions_Pluggable::register_hooks().
		$this->actions = apply_filters( 'automator_recipe_main_objectstructureactions', $actions, $this ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

		return $this;
	}

Scroll to Top