Support

Home Forums WP User Integration Upon registration create user and store all registration fields in user-meta

Upon registration create user and store all registration fields in user-meta

Posted: August 1, 2016 at 12:19 pm

Viewing 14 reply threads


ARAGATO

August 1, 2016 at 12:19 pm

I am using the EE WP User Integration Plugin.
I have set “Auto Create users with registrations?” to Yes.
Thus, upon registration a new WP User is created with the name and email provided.

However, I need additional personal information to be stored for the registered user in the wp-user oder user-meta.

I know how to add additional questions etc. But those are obviously not stored. What do you suggest to add additional fields and store them in the newly created wp-user (wp-user meta)?


Seth Shoultes

  • Support Staff

August 2, 2016 at 5:38 am

Hello,

You will have to develop a custom integration to make this happen. You might want to look at the EE4 Model System. There’s a section about storing meta information here.

If you want, you could build an add-on for this feature using our EE4 Add-on API.

If you have any developer related questions, please feel free to create a new issue via the EE4 Github page.


ARAGATO

August 5, 2016 at 7:09 am

Thanks for the info.
Could you tell me where exactly the user creation takes place (in the code)?
The user gets created by pressing the continue/confirmation button on the “attende information” stage. I cannot find the location where the ee-wp-user-integration plugin kicks in and creates the user.


Josh

  • Support Staff

August 5, 2016 at 8:20 am

You’ll look in EED_WP_Users_SPCO.module.php, in the process_wpuser_for_attendee() method.


ARAGATO

August 5, 2016 at 9:29 am

Great Josh. I found the function I was looking for.
What do you recommend to modify a function? What is the best practice?

Let’s say I want to modify the public static function process_wpuser_for_attendee. What would be the best way to do it, instead of just directly hacking the plugin file?


Josh

  • Support Staff

August 5, 2016 at 10:11 am

You use the hooks inside that method, or unhook the method (with remove_action()) so it doesn’t run and replace with your own custom function based on that method (with add_action()).

See also:
https://developer.wordpress.org/reference/functions/remove_action/
https://developer.wordpress.org/reference/functions/add_action/
https://carlalexander.ca/wordpress-adventurous-plugin-api/


ARAGATO

August 10, 2016 at 6:16 am

Great information. However, it is not working yet.
I am trying to remove the hook by
remove_action( 'AHEE__EE_Single_Page_Checkout__process_attendee_information__end', array( 'EED_WP_Users_SPCO', 'process_wpuser_for_attendee' ), 11 );

I reduced the priority to 11, because in EE the hook is added with prio 10. It needs to be added before it can be removed, right?

I also added the global class variable
global $EED_WP_Users_SPCO;

But it still does not work. Do I need to add anything else?


ARAGATO

August 10, 2016 at 8:36 am

Apart from that, could you tell me what kind of data structure the $valid_data is? According to the description: $valid_data The incoming form post data (that has already been validated).
It somehow looks like json, but json_decode throws a syntax error.

That what $valid_data contains:

a:2:{s:21:"default_hidden_inputs";a:4:{s:6:"action";s:16:"process_reg_step";s:9:"next_step";s:15:"payment_options";s:14:"e_reg_url_link";s:0:"";s:7:"revisit";s:0:"";}s:34:"1-36a252cc9bd35c68c354e53f3f2f2845";a:6:{s:31:"personal-information-1467288847";a:7:{i:17;s:4:"Herr";s:5:"fname";s:3:"sdf";s:5:"lname";s:3:"sdf";s:5:"email";s:17:"hein2@aragato.com";i:18;s:7:"Student";i:12;s:3:"234";i:20;s:0:"";}s:28:"additional_attendee_reg_info";s:1:"1";s:30:"address-information-1467288847";a:6:{s:7:"address";s:3:"234";s:8:"address2";s:3:"234";s:3:"zip";s:3:"234";s:4:"city";s:3:"234";s:5:"phone";s:0:"";i:11;s:0:"";}s:16:"sepa-lastschrift";a:2:{i:14;s:3:"234";i:15;s:3:"234";}s:30:"allgemeine-nutzungsbedingungen";a:1:{i:19;a:1:{i:0;s:0:"";}}s:18:"primary_registrant";s:34:"1-36a252cc9bd35c68c354e53f3f2f2845";}}


Josh

  • Support Staff

August 10, 2016 at 9:38 am

I reduced the priority to 11, because in EE the hook is added with prio 10. It needs to be added before it can be removed, right?

It’s also important when your remove_action call is executed.

There’s an example in our code snippet repository:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php

Apart from that, could you tell me what kind of data structure the $valid_data is?

It’s a serialized array.


ARAGATO

August 10, 2016 at 3:28 pm

I copied it 1:1 from your example and still it does not work.
Upon proceeding with the attende information it throws an error.

Besides, when looking at the code you linked. It looks like there is something not wrong. The linked functions do not exist/have a different name.
http://uploads.aragato-server.net/screenshots/2016081035c1c52cbb.jpg

Here is the corrected code for my version.
http://uploads.aragato-server.net/screenshots/20160810dc4d281e18.jpg

As far as the function content is concerned, I just copied the code from EED_WP_Users_SPCO.module.php 1:1. But it is not working. What am I doing wrong?


Josh

  • Support Staff

August 10, 2016 at 3:36 pm

I don’t know what you’re doing wrong, but you should be able to figure this out since you’re able to point out where the example code is wrong. Thanks for pointing that out!


ARAGATO

August 11, 2016 at 1:56 pm

Unfortunately, I am unable to figure it out.
I explained it badly and will try again more thoroughly.

1) I created plugin and activated it. I copied the exactly the code from your link into it the plugin file.
https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php

2) I removed all the code inside the main function ‘jf_ee_process_wpuser_for_attendee’ and replaced it with the original code from the same function ‘process_wpuser_for_attendee’ from the EED_WP_Users_SPCO.module.php
This leads to the following code:
http://uploads.aragato-server.net/files/code.txt

3) Theoretically, the only thing this plugin in does is remove the original EE hook and add my own hook. The code is exactly the same and it should behave exactly the same.
However, it does not.

When the plugin is deactivated and the original EE hook is used. The process works. A user is created based on the attendee information.
As soon as I activated the plugin and the EE hook is replaced with my own hook (having the exact same code as the original one) the registration form throws and error:
http://uploads.aragato-server.net/screenshots/201608119a8e2db4d9.jpg

Why does it throw the error although the processed code is exactly the same?


Tony

  • Support Staff

August 11, 2016 at 2:15 pm

3) Theoretically, the only thing this plugin in does is remove the original EE hook and add my own hook. The code is exactly the same and it should behave exactly the same.

That it is… but it is now outside the EED_WP_Users_SPCO class, which means the you can not use any of the classes protected methods, which the default function does.

EED_WP_Users_SPCO::_can_attach_user_to_attendee()

Is a protected method, you can not access that method from outside of the class.

One way around that is to add the code from the protected method into the code you are using, take a look at how Joshes example does that:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/jf_ee_process_multi_wpuser_for_attendees.php#L112-L119


Josh

  • Support Staff

August 11, 2016 at 2:16 pm

Because there’s a private method in your hooked function, which is visible in its own class only
_can_attach_user_to_attendee

http://php.net/manual/en/language.oop5.visibility.php


ARAGATO

August 11, 2016 at 2:34 pm

BAM! I knew you would find the issue.
Fixed it along with the line
'$registrations = self::_get_registrations( $spco );'
which does not work as well for the same reasons.
Et voila, it went through smoothly.

Solved. Jumpinh right onto the next issue. 😀

Viewing 14 reply threads

The support post ‘Upon registration create user and store all registration fields in user-meta’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso