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 front-end registration form (courtesy of WP User Manager) and hits the submit button, I need to achieve the following:
- the user registration gets stored (no problems here) - a new organizer with the data from the above 4 custom fields is created in Events Calendar
And here comes the problem.
I have tried the code below (inserted in my child theme functions file) 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);
}
}
}
Because of my very limited experience with WordPress, I suspect that I'm breaking my own code when checking if tribe classes exist, but then even if I'm at a death point and I'm banging my head to the wall since 3 days. Any hint or, better, solution would be greatly appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire