Filter
uncanny-automator
automator_recipe_main_objectstructurestats
Filters the main object's stats before they are displayed, allowing for dynamic modification of recipe performance data.
add_filter( 'automator_recipe_main_objectstructurestats', $callback, 10, 2 );
Description
Allows modification of the recipe's statistics object before it's used internally. Developers can alter stat calculations or add custom statistical data. This filter is applied within the core recipe structure service when initializing the stats object.
Usage
add_filter( 'automator_recipe_main_objectstructurestats', 'your_function_name', 10, 2 );
Parameters
-
$stats(mixed) - This parameter contains an array or object holding statistical data related to the recipe, which is being filtered.
-
$this(mixed) - This parameter contains the statistics object for the recipe, which can be modified by the filter.
Return Value
The filtered value.
Examples
/**
* Example filter for automator_recipe_main_objectstructurestats hook.
* This function modifies the stats object by adding a custom property related to recipe completion rate.
*
* @param AutomatorCoreServicesRecipeStructureStats $stats The original stats object.
* @param AutomatorCoreServicesRecipeStructureRecipe $recipe The recipe object instance.
* @return AutomatorCoreServicesRecipeStructureStats The modified stats object.
*/
add_filter(
'automator_recipe_main_objectstructurestats',
function( $stats, $recipe ) {
// Assume there's a method on the recipe object to get completed runs.
// This is a placeholder for realistic data retrieval.
$completed_runs = $recipe->get_completed_runs_count();
$total_runs = $recipe->get_total_runs_count();
$completion_rate = 0;
if ( $total_runs > 0 ) {
$completion_rate = ( $completed_runs / $total_runs ) * 100;
}
// Add a custom property to the stats object.
// The Stats class might not have a direct public property for this,
// so we're assuming it allows for dynamic addition or has a specific method.
// If not, a wrapper object or a dedicated method in the Stats class would be needed.
if ( method_exists( $stats, 'set_custom_property' ) ) {
$stats->set_custom_property( 'completion_rate', round( $completion_rate, 2 ) );
} else {
// As a fallback, if the Stats object doesn't have a setter,
// you might store it elsewhere or log a warning.
// For this example, we'll simulate adding it if possible or ignore.
// A real-world scenario would depend on the actual StructureStats class definition.
}
return $stats;
},
10, // Priority
2 // 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/services/recipe/structure.php:190
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;
}