Filter uncanny-automator

automator_restart_user_walkthrough

Filters the progress of a user's walkthrough when it's being restarted, allowing modification of the restart behavior.

add_filter( 'automator_restart_user_walkthrough', $callback, 10, 4 );

Description

Allows modification of user walkthrough progress before it's reset. Developers can alter the `$progress` array, effectively customizing how a walkthrough restarts for a specific user and ID. The `$this` parameter provides access to the walkthrough manager instance.


Usage

add_filter( 'automator_restart_user_walkthrough', 'your_function_name', 10, 4 );

Parameters

$progress (mixed)
This parameter contains the user's current walkthrough progress, which is modified before being returned.
$this (mixed)
This parameter contains the current progress data for the user's walkthrough, which will be modified before being saved.
$id (mixed)
This parameter represents the current instance of the `Automator_User_Walkthroughs` class.
$this (mixed)
This parameter represents the unique identifier of the user walkthrough being restarted.

Return Value

The filtered value.


Examples

// Example function to modify the progress of a user walkthrough restart.
// This function might add a custom flag or adjust the initial step for a specific walkthrough.
add_filter( 'automator_restart_user_walkthrough', 'my_custom_walkthrough_restart_progress', 10, 4 );

function my_custom_walkthrough_restart_progress( $progress, $user_id, $walkthrough_id, $walkthrough_instance ) {

	// Let's say we have a specific walkthrough with ID 'onboarding-tour'
	// and we want to ensure it always starts at step 1 and has a custom flag.
	if ( 'onboarding-tour' === $walkthrough_id ) {
		$progress['current_step'] = 1;
		$progress['custom_flags']['welcome_message_shown'] = false;
		$progress['notes'] = 'Restarted onboarding tour for user: ' . $user_id;
	}

	// For any other walkthroughs, we might want to simply log that it was restarted.
	// In a real scenario, you might do more complex logic here based on the user or walkthrough.
	if ( ! isset( $progress['notes'] ) ) {
		$progress['notes'] = 'Walkthrough restarted.';
	}

	// It's crucial to always return the modified progress array.
	return $progress;
}

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:210

public function restart_user_walkthrough( string $id ) {

		$this->validate_walkthrough_id( $id );

		$progress         = $this->default_progress;
		$progress['show'] = 1;
		$progress         = apply_filters( 'automator_restart_user_walkthrough', $progress, $this->user_id, $id, $this );
		$progress         = apply_filters( 'automator_restart_user_walkthrough_' . $id, $progress, $this->user_id, $this );

		$this->set_progress_by_id( $id, $progress );

	}


Scroll to Top