Filter uncanny-automator

automator_review_get_completed_recipes_count

Filters the count of completed recipes before they are returned, allowing modification of the cached completion number.

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

Description

Filters the count of completed recipes. Allows developers to modify the cached count before it's returned, useful for custom logic or debugging. The current `$cached_n_completion` and the `$this` object are provided.


Usage

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

Parameters

$cached_n_completion (mixed)
This parameter holds the cached count of completed recipes, used to avoid recalculating the value on subsequent requests.
$this (mixed)
This parameter holds the previously cached count of completed recipes, if available.

Return Value

The filtered value.


Examples

<?php
/**
 * Example filter for automator_review_get_completed_recipes_count.
 *
 * This example demonstrates how to modify the count of completed recipes.
 * For instance, you might want to exclude recipes completed by a specific user role
 * or recipes that have a certain tag.
 *
 * @param int   $completed_recipes_count The current count of completed recipes.
 * @param object $automator_get_data_instance The instance of the AutomatorGet_Data class.
 * @return int The modified count of completed recipes.
 */
add_filter( 'automator_review_get_completed_recipes_count', function( $completed_recipes_count, $automator_get_data_instance ) {
	// For demonstration purposes, let's say we want to subtract 5 from the count
	// if the current user has the 'administrator' role.
	if ( current_user_can( 'administrator' ) ) {
		$modified_count = max( 0, $completed_recipes_count - 5 ); // Ensure count doesn't go below zero
		return $modified_count;
	}

	// If the condition is not met, return the original count.
	return $completed_recipes_count;
}, 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/lib/utilities/class-automator-get-data.php:1605
src/core/lib/utilities/class-automator-get-data.php:1613

public function completed_recipes_count() {
		$cached_n_completion = Automator()->cache->get( 'get_completed_recipes_count' );

		if ( ! empty( $cached_n_completion ) ) {

			return apply_filters( 'automator_review_get_completed_recipes_count', absint( $cached_n_completion ), $this );

		}

		$total_recipe_completion = $this->total_completed_runs();

		Automator()->cache->set( 'get_completed_recipes_count', $total_recipe_completion );

		return apply_filters( 'automator_review_get_completed_recipes_count', absint( $total_recipe_completion ), $this );
	}

Scroll to Top