WordPress.org

Ready to get started?Download WordPress

Forums

WP-Members
[resolved] Query an SQL database? (5 posts)

  1. skblues
    Member
    Posted 2 years ago #

    Hello,

    I am trying to help an organization set up a members area that offers free content to members only. When a user registers, they want the site to query an SQL database for the email and grant or deny access based on that. Is it possible to set this up, and if so, is there documentation? I am not a database programmer by any means, and I'm relatively new to WordPress and haven't used this plugin before.

    Any help would be greatly appreciated!

    http://wordpress.org/extend/plugins/wp-members/

  2. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, it can be done. However, to pull it off, you (or whoever is going to do the work) will not only need to know how to query a database, but also how to use WordPress hooks.

    The plugin has an action hook that comes in the registration process before the user is registered. Hooking in at this point would allow you to take the email the user is using to register and verify it against your other database.

    The hook is wpmem_pre_register_data and it is documented in the plugin's User Guide.

    I don't know what your php skills are, but if you have limited skills with databases and you are new to WordPress, I'll be honest and say you are going to run into some challenges.

    <?php
    add_action( 'wpmem_pre_register_data', 'my_reg_hook', 1 );
    
    function my_reg_hook( $fields ) {
    
    	/*
    	$fields is an array of the registration fields
    	with data at the point where the plugin has
    	done its validation, but the user hasn't been
    	inserted yet.
    
    	This is where you would need to query the other
    	database (for which you'd obviously need a
    	connection to) and compare the email in the
    	$fields array with the email you have in your
    	database.
    
    	If they didn't match, you'd return an error;
    	if they did, you could allow registration to
    	proceed.
    	*/
    }
    ?>
  3. skblues
    Member
    Posted 2 years ago #

    Hi Chad,

    Thanks for your response. Yes, this is probably beyond what I can work with, so I will find another solution. Thank you!

  4. rkenne02
    Member
    Posted 2 years ago #

    I've added a field to wp-members registration form and would like to get access to [email] and [the other field] to use to display on a page and also use to access an external database. How can I display this information on a page?

  5. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    Yes - but rather than come into a resolved thread, you should start a new one...

    You could use the shortcode [wp-members field="name-of-field"] or WordPress get_user_meta

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.