• I posted this in plugins last night and was then told to try the hacks section. I STINK AT PHP. You’ve been warned. I haven’t no freaking clue what I’m doing.

    I use the WPL plugin which automatically adds new WP users into the WPL database. I am trying to figure out how to have the new users added based on their WP roles. In WPL, there are different memberships. The new users should fall into different memberships based on their WP role. Right now, everyone falls into the default membership.

    public static function add_user_to_wpl($user_id)
    	{
    		/** first validation **/
    		if(wpl_users::get_wpl_user($user_id)) return true;
    
    		$user_data = wpl_users::get_user($user_id);
    		$default_data = wpl_users::get_wpl_data(-1);
    
    		$forbidden_fields = array('id', 'first_name', 'last_name');
    		$auto_query1 = '';
    		$auto_query2 = '';
    
    		foreach($default_data as $key=>$value)
    		{
    			if(in_array($key, $forbidden_fields)) continue;
    
    			$auto_query1 .= "<code>$key</code>,";
    			$auto_query2 .= "'$value',";
    		}
    
    		if($user_data)
    		{
    			$auto_query1 .= "<code>first_name</code>,<code>last_name</code>,";
    			$auto_query2 .= "'".$user_data->data->meta['first_name']."','".$user_data->data->meta['last_name']."',";
    		}
    
    		$auto_query1 = trim($auto_query1, ', ');
    		$auto_query2 = trim($auto_query2, ', ');
    
    		$query = "INSERT INTO <code>#__wpl_users</code> (<code>id</code>, ".$auto_query1.") VALUES ('".$user_id."', ".$auto_query2.")";
    		$result = wpl_db::q($query);
    
            /** trigger event **/
    		wpl_global::event_handler('user_added_to_wpl', array('id'=>$user_id));
    
    		return $result;
    	}

    This line from above (I believe) tells the new data to fall into the default membership (-1) is the ID of the default membership).

    $default_data = wpl_users::get_wpl_data(-1);

    This code comes from WPL’s users.php

    I feel like I just need some ‘if’ statements here but I do not know much about PHP and need some massive help. I’ve been working with WPL but I ran out of money so they won’t help anymore. C’est la vie.

    My previous post is here in the plugin forum. It has more info.

    Any help would be appreciated. It’s my last issue to be resolved – so frustrating!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m sorry you’ve been getting the run around. I’m unfamiliar with this plugin, so I may not be much help. If you are correct and feeding different IDs to wpl_users::get_wpl_data() returns data that causes the user to placed in the correct membership, you need some code between $user_data and $default_data that determines what the ID is based on role. Assign that ID to a variable, and pass that variable to get_wpl_data() instead of -1.

    You could use a switch-case structure to do this, where each case is a different role. After case is where you assign the proper membership ID, then break;

    If you hack the plugin this way, anytime the plugin is updated, your hack could be lost. You should never forgo updates because of this. Just be ready to re-insert your hack as needed.

    Thread Starter Booka800

    (@booka800)

    Thanks bcwrokz.
    I can see the methodology and it seems almost simple – if I fully understood the code. But your thoughts are exactly what I had in mind, I just don’t know enough to implement it.

    Such a small hack – and they wanted $250 for it.

    Seriously.

    Unfortunately, I already gave them all I had.

    I thought about that – making a small hack like this would be lost during upgrades so I would have to make a note on how and what I changed. Thanks for the boost. I will keep trying to fix this when I have time.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: WPL] Adding WP User into WPL with User Role Specific Membership’ is closed to new replies.