Filter
uncanny-automator
automator_review_get_usage_count
Filters the usage count for automator reviews before it's displayed or saved.
add_filter( 'automator_review_get_usage_count', $callback, 10, 2 );
Description
Filters the calculated paid usage count for Automator features. Developers can use this hook to override the default count, perhaps for custom tracking or testing. The hook receives the current usage count and the Automator review object.
Usage
add_filter( 'automator_review_get_usage_count', 'your_function_name', 10, 2 );
Parameters
-
$usage_count(mixed) - The `$usage_count` parameter contains the current usage count retrieved from the API, which can be modified by the filter.
-
$this(mixed) - This parameter contains the current usage count, which can be filtered or overridden.
Return Value
The filtered value.
Examples
/**
* Example: Adjust the usage count for Automator plugin reviews.
*
* This filter allows you to modify the calculated usage count before it's used.
* For instance, you might want to add a buffer for specific scenarios or
* exclude certain types of usage from the count.
*
* @param mixed $usage_count The current usage count (int or false if not available).
* @param Automator_Review $this The instance of the Automator_Review class.
* @return int The adjusted usage count.
*/
add_filter( 'automator_review_get_usage_count', function( $usage_count, $automator_review_instance ) {
// Let's say we want to artificially inflate the usage count by 10% for a specific user role.
// This is purely for demonstration purposes.
if ( current_user_can( 'manage_options' ) && is_numeric( $usage_count ) ) {
$adjusted_count = $usage_count * 1.10;
// Ensure it remains an integer.
$usage_count = floor( $adjusted_count );
}
// If the original usage_count was false (meaning no paid usage found),
// and we haven't adjusted it, we can return 0 to indicate no usage.
if ( $usage_count === false ) {
return 0;
}
// Return the potentially adjusted usage count.
return absint( $usage_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/admin/class-automator-review.php:1052
protected function get_usage_count() {
$credits = Api_Server::is_automator_connected();
$usage_count = isset( $credits['paid_usage_count'] ) ? absint( $credits['paid_usage_count'] ) : false;
// Allow overide for testing purposes.
return absint( apply_filters( 'automator_review_get_usage_count', $usage_count, $this ) );
}