Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Well, you shouldn’t be using the signup form for an existing record, you need to use the [pdb_record] form. One way to do this is to save the new ID from the completed signup, then insert that into the shortcode using the “record_id” attribute. You can do this in a special WP template for the signup thanks page.

    Thread Starter gld

    (@gld)

    No. It’s a completely new record.

    Plugin Author xnau webdesign

    (@xnau)

    OK, I see…If you want to set the default (or initial) values of a signup form, you can do that in a custom template by setting the values of the fields as the form is generated.

    Thread Starter gld

    (@gld)

    Da. Of course. It never crossed my mind. Thanks man!!

    Thread Starter gld

    (@gld)

    Just one thing I’m not clear about is where is the pdb_signup-XXX.php form submitted to? I need to do some error checking prior to committing the addition of the new record. Where (or how) am I able to do that?

    Thread Starter gld

    (@gld)

    Hi Roland, I really seem to be stuck between methods here.

    What I ultimately need a single signup form which creates both the WP DB user login and an associated PDB record. I want to be able to do it at the one time. I don’t want the user to have to create a WP DB user login, then login, then create a PDB record.

    I have two choices for this:

    1. Do it all in PDB but then generate the WP DB record via PHP. Fine however WP DB requires unique record for the login ID and the e-mail address. PDB can only check validity on one field correct? If so, it means I cannot use this method, or
    2. Create the WP DB record first and once accepted, move on to create an associated PDB record.

    Your tutorial at https://xnau.com/using-participants-database-with-wordpress-users/ assumes the user is already logged on to the WP DB. Since ‘current_user->user_login’ is only visible if currently logged in. I tried to force the login after the creation of the WP DB entry but before calling pdb-signup using the wp_authenticate PHP function however this appears only to validate credentials, not cause a login.

    I have found however that the pdb-signup form takes any variable defined in earlier php scripting if it has the same name and assigns it as the field’s default. This is great but the field must be visible for that to occur which we don’t want. If the field is set as hidden it doesn’t appear on the form at all, even as a type-hidden. This will cause an error on submission since it is a mandatory field. If I manually add these as hidden fields to the pdb-signup template, I cannot seem to obtain the same value defaulting behavior since the variable isn’t visible when I test for it in the template script.

    So I’m still stuck. I guess my options are:

    1. find a way to automatically login via PHP code (that works)
    2. find a way to pass the default values to the php-signup template
    3. figure out how to intercept the submission and inset code there
    4. Understand if there is a way for PDB to validate uniqueness on 2 fields, not just one

    Please let me know the best way forward.

    Thanks! Greg

    Plugin Author xnau webdesign

    (@xnau)

    While space and time do not permit me to fully address your questions, I will say that you’re on the right track, but just need to keep at it and get a better understanding of how all this stuff works.

    It is quite possible to use a Participants Database signup form to establish a WP user account, but you need to write code that uses plugin API filters to accomplish your tasks. That’s the easiest way to do it. If you’re familiar with using WordPress filters, you already know the basic technique. For instance, there is a plugin filter that grabs the newly-entered data from a form submission. You can write a function that gets that info and uses it to establish a WP user account before the record is stored. Then grab the new WP user ID and store it with the record. Now that record is associated with the WP user. In your receipt email to the new user, you can include the WP login info, including the password if you want.

    This is advanced stuff, so if you don’t know how to do it, keep at it until you do. There’s tons of examples of using WP filters out there. Once you understand the power of using filters, all this stuff becomes much more possible.

    Read the page on using the plugin filters, it will give you some ideas how to develop your application: Participants Database 1.5 API

    Thread Starter gld

    (@gld)

    Thanks Roland. Using a filter does sound like the most elegant approach. Question though: if (via the filter) there is an error (eg a duplicate e-mail and/or login) can I prevent the plugin from committing the new PDB record once the filter exists and control is reverted?

    Plugin Author xnau webdesign

    (@xnau)

    You only need to check the email field (which the plugin will do for you), there is no need to check the user ID or login because that is set by WP when the new user is registered. You should never have the user enter things like usernames or user IDs, (unless they are logging in) because either they’re logged in and you have the information already, or they’re not logged in and don’t have the right to use that information. If you want to be sure that the WP login account is unique to the user, force them to log in. If they don’t have an account, then your filter callback can create a new one, and you know that will be unique account as long as you have the plugin checking the email for uniqueness. If you want to let them create another record that is attached to their WP user account, force them to log in. To do anything else is insecure.

    Thread Starter gld

    (@gld)

    I’ve got the filter intercepting the form via the pdb-before_submit_signup tag just fine and it runs a function. What I’m not clear on is what the data is that the form is submitting in order to interrogate it and of course to ensure I return it. Where do I find reference to that? I assume it is the array?

    Plugin Author xnau webdesign

    (@xnau)

    The filter callback is getting an associative array of all the data fields in the form submission. It’s a good idea to use an error log or screen dump to see what’s going on…try using the “print_r” function to see what’s coming in. You need to return the array when the function is finished because the plugin will use that array to store the record.

    In your function, you just need to grab the fields needed to establish the WP account. It’s a bit complicated because there will be additional fields to store (such as the user id) so you should set those up as hidden fields so that when the submission comes in there will be a blank user id. After you create the WP account you will have your user id, so you can save that with the record. You can’t just add items to the submission array because they won’t be saved if the plugin is not expecting them. This is for security reasons.

    Thread Starter gld

    (@gld)

    Roland thanks. I think that answers the last piece of the puzzle as to how to identify the incoming and there what needs to be returned by way of data. Thank you!

    Thread Starter gld

    (@gld)

    Hi Roland. Still struggling with this. I don’t know how to return the data back from the hooked function. No matter what I try to return, I get several errors of:

    “Warning: Illegal string offset …. “

    followed by a final error:

    Warning: Cannot modify header information – headers already sent by (output started at …./wp-content/plugins/participants-database/participants-database.php:1377) in …./wp-includes/pluggable.php on line 1121

    ( I’ve changed the source path to ‘….’ )

    Also, I assume that somehow I am needing to return the original posted string right? I can evaluate that just fine but it still generates the above mentioned error when I used the PHP ‘return’ command

    Thread Starter gld

    (@gld)

    So far as I can tell, these errors are being caused by participants-database.php because I’m not forwarding the posted content correctly.

    Thread Starter gld

    (@gld)

    here is the code I added to functions.php (in my theme’s folder) which works in case anyone else out there can benefit from it:

    function addUserToWPDA() {
    
    	// grab the values we need
    	$user_login = $_POST['email'];
    	$user_password = $_POST['password'];
    	$email = $_POST['email'];
    
    	// now create the account in the WP User Database
    	$returnVal = wp_create_user( $user_login, $user_password, $email );
    
    	// just in case!
    	if ( is_wp_error($returnVal) ) {
    		echo $returnVal->get_error_message() . "<p>";
    	}
    
    	// make sure we return the posted values to ensure the plugin that we have hooked in front of will continue to function properly
    	return ($_POST);
    
    }
    add_filter( 'pdb-before_submit_signup', 'addUserToWPDA', 10, 1 );

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘pdb_signup and WP user DB Integration’ is closed to new replies.