Filter uncanny-automator

automator_recipe_main_objectstructureactions

Filters the main actions object structure for Automator recipes to allow modification before being displayed.

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

Description

Filters the main action objects used in the recipe structure. Allows developers to modify, add, or remove available actions before they are rendered. This hook is essential for extending or customizing the action selection in the recipe builder.


Usage

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

Parameters

$actions (mixed)
This parameter contains an array of action objects that are part of the recipe's structure.
$this (mixed)
This parameter contains an array or object representing the actions associated with a recipe.

Return Value

The filtered value.


Examples

<?php

/**
 * Example: Modify the default Actions object for a recipe.
 *
 * This filter allows you to replace or augment the default 'Actions' object
 * used within the Automator recipe structure. For instance, you might want
 * to add custom actions or modify how existing actions are handled.
 *
 * @param object $actions The default Actions object.
 * @param object $this    The main recipe object instance.
 * @return object The modified or replaced Actions object.
 */
add_filter(
	'automator_recipe_main_objectstructureactions',
	function ( $actions, $recipe_object ) {

		// Example: You could potentially add a new custom action class to the actions collection.
		// In a real-world scenario, this would involve more complex logic to
		// integrate with existing action types or register new ones.
		// For demonstration, let's imagine we have a custom action class.
		//
		// class MyCustomAction extends Automator_Recipe_Structure_Actions_Base {
		//     public function get_id() { return 'my_custom_action'; }
		//     // ... other methods
		// }
		//
		// $actions->add_action( new MyCustomAction() );

		// For this example, we'll just return the original object,
		// but the hook allows for modification.
		return $actions;
	},
	10, // Priority: Default is 10
	2   // Accepted Args: The number of arguments the callback function accepts ( $actions, $this )
);

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:194

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