fork download
  1. function send_data_to_django_on_register( $user_id ) {
  2. echo '(registration hook2)';
  3.  
  4.  
  5. // Get the user data
  6. $user = get_userdata( $user_id );
  7.  
  8. // print_r ($user);
  9. // Build the data to send to the Django API
  10. $api_data = array(
  11. 'username' => $user->user_login,
  12. 'email' => $user->user_email,
  13. );
  14.  
  15. // print_r ($api_data);
  16.  
  17. // $plugin_name = "WORDPRESS ".$this->getWordpressVersion();
  18. // URL of the Django API endpoint
  19. $api_url = 'http://192.168.1.13:8000/merchant/loyalty_Plugin/';
  20.  
  21. // Make the POST request to the Django API
  22. $response = wp_remote_post( $api_url, array(
  23. 'body' => $api_data
  24. ) );
  25.  
  26. print_r ("<---Responce--->",$response);
  27.  
  28. // Check if the request was successful
  29. if ( is_wp_error( $response ) ) {
  30. return false;
  31. }
  32. // Decode the JSON data returned by the Django API
  33. $data = json_decode( wp_remote_retrieve_body( $response ), true );
  34.  
  35. print_r ("<---Data--->",$data);
  36. $plugin_name = "WORDPRESS ".$this->getWordpressVersion();
  37.  
  38. }
  39.  
  40. add_action( 'user_register', 'send_data_to_django_on_register' );
Success #stdin #stdout 0.03s 25868KB
stdin
 
stdout
function send_data_to_django_on_register( $user_id ) {
	echo '(registration hook2)';
	
	
    // Get the user data
    $user = get_userdata( $user_id );
	
// 	print_r ($user);
    // Build the data to send to the Django API
    $api_data = array(
        'username' => $user->user_login,
        'email'    => $user->user_email,
    );
	
// 	print_r ($api_data);
	
// 	$plugin_name = "WORDPRESS ".$this->getWordpressVersion();
    // URL of the Django API endpoint
    $api_url = 'http://192.168.1.13:8000/merchant/loyalty_Plugin/';

    // Make the POST request to the Django API
    $response = wp_remote_post( $api_url, array(
        'body' => $api_data
    ) );

	print_r ("<---Responce--->",$response);	

    // Check if the request was successful
    if ( is_wp_error( $response ) ) {
        return false;
    }
    // Decode the JSON data returned by the Django API
    $data = json_decode( wp_remote_retrieve_body( $response ), true );
	
	print_r ("<---Data--->",$data);
	$plugin_name = "WORDPRESS ".$this->getWordpressVersion();

}

add_action( 'user_register', 'send_data_to_django_on_register' );