Filter
Dynamic
uncanny-automator
automator_restart_user_walkthrough_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the progress and context of a user walkthrough restart, allowing modification before it's applied.
add_filter( 'automator_restart_user_walkthrough_{dynamic}', $callback, 10, 3 );
Description
This dynamic filter hook allows developers to modify the progress data before a user walkthrough is restarted. Use it to customize walkthrough starting points or disable restarts entirely. The actual hook name is `automator_restart_user_walkthrough_{walkthrough_id}`.
Usage
add_filter( 'automator_restart_user_walkthrough_{dynamic}', 'your_function_name', 10, 3 );
Parameters
-
$progress(mixed) - This parameter contains the progress data for the user walkthrough, which can be modified by the filter.
-
$this(mixed) - This parameter contains the user's walkthrough progress data that is about to be restarted.
-
$this(mixed) - This parameter holds the current user's ID.
Return Value
The filtered value.
Examples
add_filter( 'automator_restart_user_walkthrough_my_custom_walkthrough', 'my_automator_custom_walkthrough_restart_logic', 10, 3 );
/**
* Example: Modify progress for a specific walkthrough restart.
*
* This filter hook allows developers to inject custom logic when a specific
* walkthrough ('my_custom_walkthrough') is being restarted for a user.
*
* @param array $progress The current progress array for the walkthrough.
* @param int $user_id The ID of the user whose walkthrough is being restarted.
* @param object $walkthrough_instance The instance of the Automator user walkthrough class.
*
* @return array The modified progress array.
*/
function my_automator_custom_walkthrough_restart_logic( array $progress, int $user_id, object $walkthrough_instance ) {
// Example: Add a custom flag to the progress when this specific walkthrough restarts.
// This might be useful for triggering other actions or for tracking.
if ( isset( $progress['custom_flags'] ) && is_array( $progress['custom_flags'] ) ) {
$progress['custom_flags']['just_restarted_custom'] = true;
} else {
$progress['custom_flags'] = array( 'just_restarted_custom' => true );
}
// Example: Optionally, you might want to pre-fill certain steps for this specific walkthrough.
// For demonstration, let's say we want to ensure step 2 is marked as complete immediately.
// This logic would depend heavily on the structure of your `$progress` array.
// Assuming a structure like: $progress['steps'][step_id]['status'] = 'completed';
if ( isset( $progress['steps']['step_2'] ) ) {
$progress['steps']['step_2']['status'] = 'completed';
$progress['steps']['step_2']['completed_at'] = current_time( 'mysql' );
}
// It's crucial to 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:211
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 );
}