Skip to content

Instantly share code, notes, and snippets.

@mumin91
Created November 28, 2018 10:35
Show Gist options
  • Select an option

  • Save mumin91/f4dc5ee38faeb462c8ac8c6c37a26a67 to your computer and use it in GitHub Desktop.

Select an option

Save mumin91/f4dc5ee38faeb462c8ac8c6c37a26a67 to your computer and use it in GitHub Desktop.
Riderect user to django app after logging in to the wordpress.
<?php
/**
* Plugin Name: Ethis Redirect
* Description: A simple plugin to send users to EthisCrowd dashboard after logging in dynamically with user id
*/
function redirect_user_to_db( $redirect_to, $user )
{
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for customers
if ( in_array( 'customer', $user->roles ) ) {
$nons = wp_create_nonce( 'wp_rest' );
$dashboard_link = 'http://localhost:8000/';
$user_id = $user->ID;
$user_id = (string) $user_id;
$redirect_to = $dashboard_link.$user_id; // redirect URL
}
}
return $redirect_to;
}
add_filter( 'woocommerce_login_redirect', 'redirect_user_to_db', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment