Action
uncanny-automator
tva_drip_content_unlocked_for_specific_user
Fires when specific drip content is unlocked for a user, passing customer and content details.
add_action( 'tva_drip_content_unlocked_for_specific_user', $callback, 10, 2 );
Description
Fires after drip content has been unlocked for a specific user. Developers can use this hook to perform actions based on content being unlocked, such as sending notifications or granting additional access. It passes the user object, unlocked content details, and an empty array.
Usage
add_action( 'tva_drip_content_unlocked_for_specific_user', 'your_function_name', 10, 2 );
Parameters
-
$customer(mixed) - This parameter represents the customer whose content has been unlocked.
-
$content(mixed) - This parameter represents the customer object or identifier associated with the user for whom the content is being unlocked.
Examples
add_action( 'tva_drip_content_unlocked_for_specific_user', 'my_custom_drip_content_unlock_handler', 10, 3 );
/**
* Custom handler for the tva_drip_content_unlocked_for_specific_user action.
* This function can be used to perform additional actions when drip content is unlocked for a user,
* such as sending a notification email or updating user meta.
*
* @param WP_User $user The user object for whom the content was unlocked.
* @param WP_Post $content The WordPress post object representing the unlocked content.
* @param array $extra_args Any additional arguments passed with the action.
*/
function my_custom_drip_content_unlock_handler( WP_User $user, WP_Post $content, array $extra_args ) {
// Example: Send a custom email notification to the user when new content is unlocked.
$user_email = $user->user_email;
$subject = sprintf( 'New Content Unlocked for You: %s', $content->post_title );
$message = sprintf(
"Hi %s,nnWe're excited to let you know that new content has been unlocked for you in our system.nnContent Title: %snnView it now: %s",
$user->display_name,
$content->post_title,
get_permalink( $content->ID )
);
// Using wp_mail() for sending emails. You might want to adjust headers or use a more advanced email sending plugin.
$sent = wp_mail( $user_email, $subject, $message );
if ( ! $sent ) {
// Log an error if the email could not be sent.
error_log( sprintf( 'Failed to send drip content unlocked notification email to user ID: %d for content ID: %d', $user->ID, $content->ID ) );
}
// Example: Update user meta to track unlocked content.
// This is a simplified example; you might want to store a more structured list or count.
$unlocked_content_meta_key = '_tva_drip_content_unlocked_' . $content->ID;
update_user_meta( $user->ID, $unlocked_content_meta_key, time() );
// You can also use the $extra_args if they are being populated by the source.
// For example, if the source passed an array of unlocked content IDs, you could iterate through them.
// if ( ! empty( $extra_args['unlocked_content_ids'] ) && is_array( $extra_args['unlocked_content_ids'] ) ) {
// foreach ( $extra_args['unlocked_content_ids'] as $unlocked_id ) {
// // Perform actions for each unlocked content ID
// }
// }
}
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/integrations/thrive-apprentice/actions/thrive-apprentice-unlock-content.php:139
protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
try {
$content_ids = json_decode( $parsed[ $this->get_action_meta() ] );
if ( empty( $content_ids ) ) {
throw new Exception( esc_html_x( 'Content ID is missing.', 'Thrive Apprentice', 'uncanny-automator' ) );
}
// Validate content post
$content = get_post( $content_ids );
$customer = new TVA_Customer( $user_id );
foreach ( $content_ids as $id ) {
$customer->set_drip_content_unlocked( $id );
}
do_action( 'tva_drip_content_unlocked_for_specific_user', $customer->get_user(), $content, array() );
return true;
} catch ( Exception $e ) {
$this->add_log_error( $e->getMessage() );
return false;
}
}