Filter
uncanny-automator
automator_get_user_walkthroughs
Filters the list of user walkthroughs before they are returned for display or processing.
add_filter( 'automator_get_user_walkthroughs', $callback, 10, 3 );
Description
Allows modification of the user walkthroughs array before it's assigned. Developers can filter this hook to add, remove, or alter walkthroughs for a specific user, offering fine-grained control over their onboarding experience. This hook fires when walkthroughs are initially retrieved for a user.
Usage
add_filter( 'automator_get_user_walkthroughs', 'your_function_name', 10, 3 );
Parameters
-
$walkthroughs(mixed) - This parameter contains an array of user walkthroughs.
-
$this(mixed) - This parameter contains an array of user walkthroughs that will be returned by the filter.
-
$this(mixed) - This parameter represents the current instance of the `Automator_User_Walkthroughs` class.
Return Value
The filtered value.
Examples
/**
* Conditionally removes the "Create Recipe" walkthrough for users who have already created a recipe.
*
* @param array $walkthroughs The current array of user walkthroughs.
* @param int $user_id The ID of the user.
* @param object $object The object instance of AutomatorUserWalkthroughs.
*
* @return array The modified array of user walkthroughs.
*/
function my_automator_filter_user_walkthroughs( $walkthroughs, $user_id, $object ) {
// Check if the 'create_recipe' walkthrough exists in the array.
if ( isset( $walkthroughs['create_recipe'] ) ) {
// Query to see if the user has already created any recipes.
$recipes_created = get_posts( array(
'post_type' => 'uo-recipe', // Assuming 'uo-recipe' is the recipe post type.
'author' => $user_id,
'posts_per_page' => 1,
'post_status' => 'publish',
) );
// If the user has created at least one recipe, remove the 'create_recipe' walkthrough.
if ( ! empty( $recipes_created ) ) {
unset( $walkthroughs['create_recipe'] );
}
}
return $walkthroughs;
}
add_filter( 'automator_get_user_walkthroughs', 'my_automator_filter_user_walkthroughs', 10, 3 );
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-user-walkthroughs.php:112
public function get_user_walkthroughs() {
// Check if walkthroughs are disabled.
if ( defined( 'AUTOMATOR_DISABLE_WALKTHROUGHS' ) && AUTOMATOR_DISABLE_WALKTHROUGHS ) {
$this->user_walkthroughs = array();
return $this->user_walkthroughs;
}
// Property not set yet.
if ( is_null( $this->user_walkthroughs ) ) {
$walkthroughs = array();
$walkthroughs = apply_filters( 'automator_get_user_walkthroughs', $walkthroughs, $this->user_id, $this );
$this->user_walkthroughs = empty( $walkthroughs ) || ! is_array( $walkthroughs ) ? array() : $walkthroughs;
}
// Parse default values.
if ( ! empty( $this->user_walkthroughs ) ) {
foreach ( $this->user_walkthroughs as $id => $walkthrough ) {
$this->user_walkthroughs[ $id ] = wp_parse_args( $walkthrough, $this->default_progress );
}
}
return $this->user_walkthroughs;
}
Internal Usage
Found in src/core/automator-post-types/uo-recipe/class-recipe-post-utilities.php:492:
add_filter( 'automator_get_user_walkthroughs', array( $this, 'should_show_create_recipe_walkthrough' ), 10, 3 );