You need to build a checking function and hook it to the “create member” procedure, like this:
add_action('user_register', 'pin_check');
where “pin_check” is the name of your function. Best is to do this as a PHP file at “wp-content/mu-plugins” directory.
Thanks krumch – I appreciate you’re response but I am still lost. Also, I don’t have a mu-plugins folder, is this something I have to create? Sorry if I sound really clueless to this stuff – I just design websites and I’m not an expert at this stuff.
I want to use s2Member so members can only register if their first, last names and pin match. Otherwise, they would be denied registration.
I currently have this code that I added to my theme’s functions file with WP-Members – I also created a PIN field – but I no longer want to use WP-Members. Is there a way to do something like this with s2Member?
<?php
add_action( 'wpmem_pre_register_data', 'validate_pin' );
function validate_pin( $fields )
{
global $wpmem_themsg, $wpdb;
$query = 'SELECT * FROM my_table WHERE LOWER( first_name ) = LOWER( "'
. $fields['first_name'] . '" ) AND LOWER( last_name ) = LOWER( "'
. $fields['last_name'] . '" ) LIMIT 1';
$result = $wpdb->get_results( $query, 'ARRAY_A' );
if( ! $result ) {
$wpmem_themsg = 'Sorry, that name was not found.';
return;
}
foreach( $result as $the_user ) {
$wpmem_themsg = ( $fields['pin'] != $the_user['pin'] ) ? 'Incorrect PIN!' : '';
}
return;
}
Just modify your code along the lines krumch suggested. In other words, change the first line so that the code reads:
<?php
add_action( 'user_register', 'validate_pin' );
function validate_pin( $fields )
{
global $wpmem_themsg, $wpdb;
$query = 'SELECT * FROM my_table WHERE LOWER( first_name ) = LOWER( "'
. $fields['first_name'] . '" ) AND LOWER( last_name ) = LOWER( "'
. $fields['last_name'] . '" ) LIMIT 1';
$result = $wpdb->get_results( $query, 'ARRAY_A' );
if( ! $result ) {
$wpmem_themsg = 'Sorry, that name was not found.';
return;
}
foreach( $result as $the_user ) {
$wpmem_themsg = ( $fields['pin'] != $the_user['pin'] ) ? 'Incorrect PIN!' : '';
}
return;
Save that in a plain text file called something like pin.php
You will need to create the mu-plugins
folder (e.g. by using FTP). Again, just put it where krumch said.
Then just upload the pin.php
file to the mu-plugins
folder.
Thanks KTS915. I created the php just as you mentioned above as well as the mu-plugins folder then added the php to the folder. I then registered with incorrect information to see if the registration would be denied and unfortunately the registration went through. So this did not work 🙁
Then it appears either that you will need to modify the code or that you will need a different hook from user_register
You could start by experimenting by using a different hook. The full list of registration-related hooks is here.
I’ve tried several of the hooks. Nothing has worked yet, I’m probably not doing this right. Thanks again KTS915.
My fault: the hook I show fires after the user is created. You must fine some, that fires before the creation of the new user. Maybe “init”. Maybe inside s2M…