Hi,
Yes, I have a problem. I want that newly registered users are getting a level from pmpro as standard. By default the must to register and then upgrade. There isn't any default button or something like that in pmpro.
So, I need that make a certain level standard in registration. I have some suggestions.
Adding a checkbox in the users/all user in the admin area that automatically gives certain users that level.
Or using this code:
I have a code that is really handy, that I found in the bp forum. This by checking the users you can add user to a group by using the bulk actions. If something like that could be use to add a certain level to the a user would be great:
/* ------------------------------------------------------------
:: ADD USER TO GROUP
--------------------------------------------------------------- */
function add_users_to_3CA() {
if( bp_is_active('groups') ):
if( isset( $_GET['action'] ) && isset( $_GET['bp_gid'] ) && isset( $_GET['users'] ) ) {
$group_id = $_GET['bp_gid'];
$users = $_GET['users'];
foreach ( $users as $user_id ) {
groups_join_group( $group_id, $user_id );
}
}
//form submission
add_action( 'admin_footer', function() { ?>
<script type="text/javascript" charset="utf-8">
jQuery("select[name='action']").append(jQuery('<option value="groupadd">Add to Group</option>'));
jQuery("#doaction").click(function(e){
if(jQuery("select[name='action'] :selected").val()=="groupadd") { e.preventDefault();
gid=prompt("Enter a Group ID","11");
jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
}
});
</script>
<?php
});
endif;
}
add_action ( 'load-users.php', 'add_users_to_3CA' );
Any suggestions?
John Cotton answers:
Why not hook into each registration (assuming it's done via the API route) and set like this?
function set_default_group( $user_id ) {
groups_join_group( MY_DEFAULT_GROUP_ID, $user_id );
}
add_action( 'user_register', 'set_default_group', 10, 1 );
Veritus comments:
Yes, good idea, but that is not what I'm asking for or maybe I don't understand you really. I want a level from pmpro (paid membership pro) to be set as standard when people register. So people get that level direct after registration.
John Cotton comments:
<blockquote>I want a level from pmpro (paid membership pro) to be set as standard when people register</blockquote>
I don't know the plugin, but looking at it's code there is a function that seems to do that:
pmpro_changeMembershipLevel($_REQUEST['membership_level'], $user_ID)
So you could call that (with your default value in place of the $_REQUEST) and that would seem to do what you want.
Test it though as this is just an educated guess on my part.
John Cotton comments:
function set_default_group( $user_id ) {
pmpro_changeMembershipLevel( MY_DEFAULT_GROUP_ID, $user_id );
}
add_action( 'user_register', 'set_default_group', 10, 1 );
Veritus comments:
yeah, I'll check this out so they get that level direct after registration, otherwise you must do that by hand which is not good at all, giving the level to hundred of users by hand would take all the day. hehe..
Veritus comments:
John Cotton, can you please check if that works so a level works as default after registration, a level is given direct after registration? I'll double the price for the code. I need to split myself in two right know hehe...
Veritus comments:
I think I found a solution, give me a minute!
Veritus comments:
Yes, This seems to do the job/* ------------------------------------------------------------
:: ADD DEFAULT LEVEL AT PMPPRO
--------------------------------------------------------------- */
add_action('user_register', 'kleo_pmpro_default_level');
function kleo_pmpro_default_level($user_id) {
pmpro_changeMembershipLevel(1,$user_id);
}
John Cotton comments:
<blockquote>Yes, This seems to do the job</blockquote>
Good. I prefer my style with the add_action below, and - personally - I'd make the level a constant defined elsewhere but other than that it's the same :)
Veritus comments:
I understand John Cotton, would the latest code work also if you add the also group id, so it gets the level but also adds him/she to a certain group with the id? So all that goes on auto.
John Cotton comments:
Sorry, Felipe, I don't understand what you mean. Could you explain again?
Veritus comments:
Haha, I got it a little wrong. Would that be possible to add by using this code below and add that when the user register is added to a certain group in bp?
/* ------------------------------------------------------------
:: ADD DEFAULT LEVEL AT PMPPRO
--------------------------------------------------------------- */
add_action('user_register', 'kleo_pmpro_default_level');
function kleo_pmpro_default_level($user_id) {
pmpro_changeMembershipLevel(1,$user_id);
}
John Cotton comments:
Just about anything is possible, but you're asking a different question now...I think you need a new question so those with expertise on BP can answer.
Veritus comments:
ok, I understand. I'm just wondering if that is possible. I thought you could add that to the code to this..
John Cotton comments:
I'm sure you can, but I don't know that much about BP these days so better to ask someone else.
Veritus comments:
Ok. Thank you for your help John Cotton! Because you are nice person and always answer, also you found a solution. You are 20$ buck richer! :) Thank you for your time and have a nice Saturday! :)