• I don’t seem to be able to insert something in the UAM database after inserting a new user, i want a default group for every new user (without role affiliation)

    I made this code, and the output to the logfile is 100 % correct but it doesn’t insert anything into the database ??

    
    function custom_logs($message) { 
        if(is_array($message)) { 
            $message = json_encode($message); 
        } 
        $file = fopen("../custom_logs.log","a"); 
        echo fwrite($file, "\n" . date('Y-m-d h:i:s') . " :: " . $message); 
        fclose($file); 
    }
    
    function myplugin_registration_save($user_id) {  
      global $wpdb;   
      $group_id = 20;
      
      $wpdb->insert($wpdb->prefix.'uam_accessgroup_to_object', array(
         'object_id' => $user_id,
         'general_object_type' => '_user_',
         'object_type' => '_user_',
    	 'group_id' => $group_id,
         'group_type' => 'UserGroup',
      ));
      
      custom_logs("User ID        : ". $user_id);  
      custom_logs("User Group     : ". $group_id); 
      custom_logs("Query used     : ". $wpdb->last_query);   
    }
    
    add_action( 'user_register', 'myplugin_registration_save', 10, 1 );

    Output of the log :

    
    2019-04-16 07:57:24 :: User ID        : 55
    2019-04-16 07:57:24 :: User Group     : 20
    2019-04-16 07:57:24 :: Query used     : INSERT INTO bp_uam_accessgroup_to_object (object_id, general_object_type, object_type, group_id, group_type) VALUES (55, '_user_', '_user_', '20', 'UserGroup')
    • This topic was modified 5 years, 11 months ago by a3vd.
    • This topic was modified 5 years, 11 months ago by a3vd.
    • This topic was modified 5 years, 11 months ago by a3vd.
    • This topic was modified 5 years, 11 months ago by a3vd.
  • The topic ‘Trying to add default group to new user’ is closed to new replies.