Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

New Organizer in EventsCalendar when registering with UserManager WordPress

  • SOLVED

My problem is similar to the one at [LINK]http://wpquestions.com/question/showChrono/id/8498[/LINK]

I have two plugins: Events Calendar and WP User Manager.
I have created two roles: Guest and Organizer.
I have also created 4 custom fields in WP User Manager:

wpum_event_organizer
wpum_organizer_tel
wpum_organizer_website
wpum_organizer_email

When a new user fills in the registration form and hits the submit button, I need to achieve the following:

- the user registration gets stored (no problems here)
<strong>- a new organizer with the data from the above 4 custom fields is created in Events Calendar</strong>

And here comes the problem.

I have tried to adapt Arnav Joy answer to the question linked above and I get no errors (and new user registration happens and gets stored correctly), but no new organizer is created in Events Calendar.

This is the code I am using on my child theme functions.php file:


add_action('wpum_before_user_update', 'format_ec_event_meta_from_wpum');



function format_ec_event_meta_from_wpum(){


//Organizer details

$organizerName = event_organizer;

$organizerPhone = organizer_tel;

$organizerWebsite = organizer_website;

$organizerEmail = organizer_email;


$savedOrganizer = get_page_by_title($_POST['wpum_'. $organizerName], 'OBJECT', 'tribe_organizer');



if (isset($savedOrganizer)){

$_POST['organizer']['OrganizerID'] = $savedOrganizer->ID;

} else {


$_POST['organizer']['Organizer'] = $_POST['wpum_'. $organizerName];

$_POST['organizer']['Phone'] = $_POST['wpum_'. $organizerPhone];



if( isset( $_POST['wpum_'. $organizerWebsite] ) )

$_POST['organizer']['Website'] = $_POST['wpum_'. $organizerWebsite] == 'http://' ? '' : $_POST['wpum_'. $organizerWebsite];

if( isset( $_POST['wpum_'. $organizerEmail] ) )

$_POST['organizer']['Email'] = $_POST['wpum_'. $organizerEmail];

}

}

add_action('save_post', 'save_ec_event_meta_from_wpum', 11, 2);



function save_ec_event_meta_from_wpum($postId, $post) {

if( class_exists('TribeEvents') ) {


if ( $post->post_type != TribeEvents::POSTTYPE || defined('DOING_AJAX') ) {

return;

}


if( class_exists('TribeEventsAPI') ) {

$_POST['Organizer'] = stripslashes_deep($_POST['organizer']);


if( !empty($_POST['Organizer']['OrganizerID']) )

$_POST['Organizer'] = array('OrganizerID' => $_POST['Organizer']['OrganizerID']);



TribeEventsAPI::saveEventMeta($postId, $_POST, $post);


}

}

}


Answers (1)

2016-04-24

Rempty answers:

Hello Sadeepa you need to use the action user_register
Delete your code and add this code to your functions.php please

add_action('user_register', 'create_organizer_after_register',10,1);
function create_organizer_after_register($user_id) {
if( class_exists('TribeEvents') ) {
$organizerName = 'wpum_event_organizer';
$organizerPhone = 'wpum_organizer_tel';
$organizerWebsite = 'wpum_organizer_website';
$organizerEmail = 'wpum_organizer_email';
$post_2 = array(
'post_author' => $user_id,
'post_status' => 'publish',
'post_title' => $_POST[$organizerName],
'post_content' => '',
'Organizer' => $_POST[$organizerName],
'Email' => $_POST[$organizerEmail],
'Website' => $_POST[$organizerWebsite],
'Phone' => $_POST[$organizerPhone],
);
tribe_create_organizer( $post_2 );
}
}


Sadeepa comments:

Rempty you are a star! It works like a charm, thank you very much! I'm going to award you the money. Do you have any idea if I could turn that into a plugin easily, instead of putting it inside the functions file?


Rempty comments:

OK i created the plugin, you can download from:

https://mega.nz/#!8xNiBQha!ICJe2WRKEan5TfYPV41ODgQRZmFjA0xaezjYp_LUZ64

Maybe you can rise a bit the prize pool

Thank you


Sadeepa comments:

Uhm, I had already voted to award you the money, Daniel I'm sorry. Did you get it assigned? The link on HOW TO PAY is broken, so I'm not sure I have done it correctly...I have clicked on VOTE TO AWARD PRIZE and assigned 25 to you. Let me know if it was or wasn't the correct way. And check your gmail: I've sent you a message.


Sadeepa comments:

Uhm, I had already voted to award you the money, Daniel I'm sorry. Did you get it assigned? The link on HOW TO PAY is broken, so I'm not sure I have done it correctly...I have clicked on VOTE TO AWARD PRIZE and assigned 25 to you. Let me know if it was or wasn't the correct way. And check your gmail: I've sent you a message.