• I have a table in my database called my_table with members. This table has each persons first and last names along with a unique pin for each individual. In order for a member to be allowed to register the person’s first, last name and pin must match. I created a custom field and named it “pin” now I need to be able to get the pin to validate when someone tries to register. I believe this is something I would have to put into the functions but I have no idea how to create this script. I looked through here but I am absolutely clueless ANY help would be appreciated. Thanks!

    https://wordpress.org/plugins/s2member/

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter InvitationFascination

    (@invitationfascination)

    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.

    Thread Starter InvitationFascination

    (@invitationfascination)

    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.

    Thread Starter InvitationFascination

    (@invitationfascination)

    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…

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Register members via s2Member with a PIN’ is closed to new replies.