New User Part 2

Home » Snippets » New User Part 2
0

Created with:

Visibility: 

public

Creator: admin@thinkadvanced.com

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
// Include the necessary WordPress files
require_once(ABSPATH . 'wp-load.php');
require_once(ABSPATH . 'wp-includes/pluggable.php');

// Process account activation
function wpturbo_process_account_activation() {
    if (isset($_GET['action']) && $_GET['action'] === 'activate') {
        $activation_key = $_GET['key'];
        $email = $_GET['email'];

        // Get the user ID based on the activation key and email
        $user = get_user_by('email', $email);
        $user_id = $user ? $user->ID : 0;

        // Verify the activation key
        $stored_key = get_user_meta($user_id, 'activation_key', true);

        if ($user_id && $stored_key === $activation_key) {
            // Update user status to 'active'
            update_user_meta($user_id, 'status', 'active');

            // Redirect the user to a success page
            wp_redirect(site_url('account-activated'));
            exit;
        }
    }
}

// Handle the account activation process
add_action('template_redirect', 'wpturbo_process_account_activation');
				

With these steps, the user will be redirected to the 'account-activation.php' template when they click on the activation link. The activation key and email will be validated, and if they match, the user's status will be updated to 'active'. Then, the user will be redirected to the 'account-activated.php' template, displaying a success message.

Please note that you may need to customize the templates and messages according to your specific requirements and styling.

Register an account to save your snippets or go Pro to get more features.