Filter
uncanny-automator
automator_set_user_walkthrough_progress
Filters the progress data before it's set for a user's walkthrough, allowing for custom modifications.
add_filter( 'automator_set_user_walkthrough_progress', $callback, 10, 3 );
Description
Filters the user walkthrough progress before it's saved. Developers can use this to modify the progress data, perhaps to add custom steps or alter existing ones, before it's persisted for a specific user and walkthrough ID. The `$this` parameter refers to the `Automator_User_Walkthroughs` instance.
Usage
add_filter( 'automator_set_user_walkthrough_progress', 'your_function_name', 10, 3 );
Parameters
-
$progress(mixed) - This parameter contains the current progress for the user walkthrough.
-
$this(mixed) - The `$progress` parameter contains the user's existing walkthrough progress, which is then merged with the new update.
-
$id(mixed) - This parameter refers to the instance of the `Automator_User_Walkthroughs` class that is calling the hook.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Modify user walkthrough progress for a specific walkthrough.
*
* This filter allows developers to adjust the progress data for a user's
* walkthrough before it's saved. For instance, you might want to ensure
* a certain step is always marked as complete after another action.
*
* @param array $progress The current progress data for the walkthrough.
* @param int $user_id The ID of the user whose progress is being updated.
* @param string $walkthrough_id The unique identifier of the walkthrough.
* @return array The modified progress data.
*/
add_filter( 'automator_set_user_walkthrough_progress', function( $progress, $user_id, $walkthrough_id ) {
// Example: If the walkthrough ID is 'onboarding-flow' and the user has reached
// step 'setup-profile', ensure 'email-verification' is also marked as complete,
// even if it wasn't explicitly set in the update.
if ( 'onboarding-flow' === $walkthrough_id && isset( $progress['current_step'] ) && 'setup-profile' === $progress['current_step'] ) {
$progress['steps']['email-verification'] = 'complete';
// You might also want to update a completion percentage if applicable.
// For example, if 'setup-profile' and 'email-verification' are the first two steps
// out of five, and both are now complete:
if ( isset( $progress['total_steps'] ) && $progress['total_steps'] >= 5 ) {
$progress['completion_percentage'] = 40; // (2 steps complete / 5 total steps) * 100
}
}
// Example: Prevent certain progress data from being saved for a specific user.
// Let's say we don't want to track 'optional-feature' progress for admin users.
if ( user_can( $user_id, 'manage_options' ) && isset( $progress['steps']['optional-feature'] ) ) {
unset( $progress['steps']['optional-feature'] );
}
return $progress;
}, 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:168
public function set_progress_by_id( string $id, array $update ) {
$this->validate_walkthrough_id( $id );
if ( empty( $update ) ) {
$this->remove_user_walkthrough_progress( $id );
return;
}
$existing = $this->get_progress_by_id( $id );
$progress = wp_parse_args( $update, $existing );
$progress = apply_filters( 'automator_set_user_walkthrough_progress', $progress, $this->user_id, $id );
$progress = apply_filters( 'automator_set_user_walkthrough_progress_' . $id, $progress, $this->user_id );
if ( empty( $progress ) ) {
$this->remove_user_walkthrough_progress( $id );
return;
}
$this->user_progress_meta[ $id ] = $progress;
$this->save_progress();
}