Action uncanny-automator

automator_user_walkthroughs_init

Add action hook for user walkthroughs to register filters. Fires when user walkthroughs are initialized, allowing for the registration of filters and custom actions.

add_action( 'automator_user_walkthroughs_init', $callback, 10, 2 );

Description

Fires when user walkthroughs are initialized for a specific user. Developers can use this action to register custom filters for walkthrough logic or to perform actions related to user walkthrough progress upon initialization. It passes the current `Automator_User_Walkthroughs` instance and the `user_id`.


Usage

add_action( 'automator_user_walkthroughs_init', 'your_function_name', 10, 2 );

Parameters

$this (Automator_User_Walkthroughs)
- Instance of Automator_User_Walkthroughs.
$user_id (int)
- User ID.

Examples

// Example function to handle the 'automator_user_walkthroughs_init' action.
// This function might be used to check if a user has started a particular walkthrough
// and potentially display it if they haven't or if they've completed a prerequisite.
function my_automator_init_user_walkthrough( $automator_walkthroughs_instance, $user_id ) {

    // Ensure we have a valid user ID.
    if ( ! $user_id ) {
        return;
    }

    // Get the user's completed walkthroughs.
    // This is a hypothetical function call based on the context.
    // In a real scenario, you'd interact with the $automator_walkthroughs_instance
    // or a related WordPress option/meta to get this data.
    $completed_walkthroughs = get_user_meta( $user_id, 'automator_completed_walkthroughs', true );
    $completed_walkthroughs = is_array( $completed_walkthroughs ) ? $completed_walkthroughs : array();

    // Let's say we have a specific walkthrough we want to initiate if not completed.
    $target_walkthrough_slug = 'onboarding_steps';

    // Check if the target walkthrough has already been completed.
    if ( ! in_array( $target_walkthrough_slug, $completed_walkthroughs ) ) {

        // If not completed, we might want to mark it as started or queue it for display.
        // This could involve setting another user meta flag.
        update_user_meta( $user_id, 'automator_walkthrough_status_' . $target_walkthrough_slug, 'started' );

        // Potentially log this event or trigger another process.
        error_log( "User {$user_id} is starting the {$target_walkthrough_slug} walkthrough." );

        // In a real application, you might also dispatch an event to trigger
        // the display of the walkthrough on the front-end or back-end.
        // For demonstration, we'll just log and set a status.

    } else {
        // If completed, we might do nothing or log that it's already done.
        error_log( "User {$user_id} has already completed the {$target_walkthrough_slug} walkthrough." );
    }
}

// Add the action hook with the correct number of arguments.
// The priority (10) is standard, and '2' indicates that the callback function
// accepts two arguments ($automator_walkthroughs_instance, $user_id).
add_action( 'automator_user_walkthroughs_init', 'my_automator_init_user_walkthrough', 10, 2 );

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

public function __construct( $user_id = 0 ) {

		if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
			throw new Exception( esc_html__( 'Invalid user ID.', 'uncanny-automator' ) );
		}

		$this->user_id = $user_id;

		$meta = $this->get_user_progress_meta();

		/**
		 * Add action hook for user walkthroughs to register filters.
		 *
		 * @param Automator_User_Walkthroughs $this - Instance of Automator_User_Walkthroughs.
		 * @param int $user_id - User ID.
		 */
		do_action( 'automator_user_walkthroughs_init', $this, $user_id );
	}

Scroll to Top