Action
Since 5.8
uncanny-automator
automator_user_walkthrough_progress_updated
Fires when a walkthrough mode is updated. Fires when a user's progress within a walkthrough mode is updated.
add_action( 'automator_user_walkthrough_progress_updated', $callback, 10, 1 );
Description
Fires after a user's walkthrough progress is successfully updated via the REST API. Developers can hook into this action to perform custom actions, such as sending notifications, logging progress, or triggering other automations based on the updated status. The `$updated` and `$return` parameters provide details about the update operation.
Usage
add_action( 'automator_user_walkthrough_progress_updated', 'your_function_name', 10, 1 );
Parameters
-
$updated(mixed) - - **$return** `mixed`
Examples
add_action( 'automator_user_walkthrough_progress_updated', 'my_automator_walkthrough_progress_handler', 10, 2 );
/**
* Handles updates to user walkthrough progress.
*
* This function is triggered when a user's progress in a walkthrough is updated.
* It logs the progress update and potentially performs other actions based on the update.
*
* @param mixed $updated The data representing the updated walkthrough progress.
* @param mixed $return The response data from the update operation.
*/
function my_automator_walkthrough_progress_handler( $updated, $return ) {
// Check if the update was successful by examining the $return array.
// This assumes $return is an array and 'success' is a key indicating the status.
if ( is_array( $return ) && isset( $return['success'] ) && $return['success'] === true ) {
// Log the successful walkthrough progress update for debugging or auditing.
// In a real-world scenario, you might want to store this in a custom log table
// or use a more robust logging library.
error_log( "User walkthrough progress updated successfully. Progress data: " . print_r( $updated, true ) );
// Example: If this is the final step of a key walkthrough, trigger a welcome email.
// This is a hypothetical example; the logic would depend on your specific walkthroughs.
if ( isset( $updated['step'] ) && $updated['step'] === 'completion' ) {
$user_id = get_current_user_id(); // Assumes the current user is the one updating their progress.
if ( $user_id ) {
// wp_mail is a WordPress function to send emails.
wp_mail(
get_userdata( $user_id )->user_email,
__( 'Welcome to Our Platform!', 'your-text-domain' ),
__( 'Congratulations on completing the initial walkthrough. We hope you find our platform useful!', 'your-text-domain' )
);
error_log( "Sent welcome email to user ID: " . $user_id . " after walkthrough completion." );
}
}
} else {
// Log failed walkthrough progress updates.
error_log( "Failed to update user walkthrough progress. Return data: " . print_r( $return, true ) );
}
}
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/automator-post-types/uo-recipe/class-recipe-post-rest-api.php:1020
public function set_walkthrough_progress( WP_REST_Request $request ) {
if ( $request->has_param( 'id' ) && $request->has_param( 'progress_percentage' ) && $request->has_param( 'step_id' ) && $request->has_param( 'close_requested' ) ) {
$walkthrough_id = sanitize_text_field( $request->get_param( 'id' ) );
$step = sanitize_text_field( $request->get_param( 'step_id' ) );
$percent = $request->has_param( 'progress_percentage' ) ? absint( $request->get_param( 'progress_percentage' ) ) : 0;
$close_requested = $request->has_param( 'close_requested' ) ? filter_var( $request->get_param( 'close_requested' ), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) : false;
$show = ! $close_requested && $percent < 100;
$updated = Automator()->utilities->set_user_walkthrough_progress(
get_current_user_id(),
$walkthrough_id,
array(
'show' => $show ? 1 : 0,
'step' => $step,
'progress' => $percent,
'dismissed' => $close_requested,
)
);
if ( false !== $updated ) {
$return = array(
'message' => 'Updated!',
'success' => true,
'action' => 'updated_option',
);
/**
* Fires when a walkthrough mode is updated.
*
* @since 5.8
*/
do_action( 'automator_user_walkthrough_progress_updated', $updated, $return );
return new WP_REST_Response( $return, 200 );
}
}
$return = array(
'message' => 'Failed to update',
'success' => false,
'action' => 'show_error',
);
return new WP_REST_Response( $return, 200 );
}