WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] em_booking_validate doesnt save my booking_meta (3 posts)

  1. Patrick Hesselberg
    Member
    Posted 1 year ago #

    Hooking into em_booking_validate:

    add_filter( 'em_booking_validate', 'dm_booking_validate' );
    function dm_booking_validate ( $result, $EM_Booking ) {

    My errors and succes works great. And it also registers the signup. Only problem is that I do not get my booking_meta with me.

    Im trying to do it like this:

    if( ! empty( $_REQUEST['city'] ) ) {
    	$EM_Booking->booking_meta['registration']['city'] = wp_kses( $_REQUEST['city'], array() );
    }

    Only thing im getting is the user_email.

    returning $result

    What im I doing wrong?
    How can I save my custom booking meta?

    http://wordpress.org/extend/plugins/events-manager/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    you probably want to hook into em_booking_get_post

  3. Patrick Hesselberg
    Member
    Posted 1 year ago #

    em_booking_validate hook works. The fix was to make $EM_Booking a global:

    Full code:

    // Validate and insert custom metadata
    add_filter( 'em_booking_validate', 'dm_booking_validate' );
    function dm_booking_validate ( $result, $EM_Booking ) {
    	global $EM_Notices, $EM_Booking;
    
    	if( empty($EM_Booking->booking_meta['registration']) ) $EM_Booking->booking_meta['registration'] = array();
    
    	if( ! empty( $_REQUEST['title'] ) ) {
    		$EM_Booking->booking_meta['registration']['title'] = wp_kses( $_REQUEST['title'], array() );
    		$EM_Booking->title = wp_kses( $_REQUEST['title'], array() );
    	}
    	if( ! empty( $_REQUEST['name'] ) ) {
    		$EM_Booking->booking_meta['registration']['name'] = wp_kses( $_REQUEST['name'], array() );
    	} else {
    		$result = false;
    		$EM_Notices->add_error( '<strong>Fejl</strong>: Indtast venligst dit Navn.' );
    	}
    	if ( $_REQUEST['user_email'] && !is_email( $_REQUEST['user_email'] ) ) {
    		$result = false;
    		$EM_Notices->add_error( __( '<strong>Fejl</strong>: E-mailadressen er ikke korrekt.', 'dbem') );
    	} elseif ( is_email( $_REQUEST['user_email'] ) ) {
    		$EM_Booking->booking_meta['registration']['user_email'] = wp_kses( $_REQUEST['user_email'], array() );
    	} else {
    		$result = false;
    		$EM_Notices->add_error(__( '<strong>Fejl</strong>: Indtast venligst din E-mailadresse.', 'dbem') );
    	}
    	if( ! empty( $_REQUEST['company'] ) ) {
    		$EM_Booking->booking_meta['registration']['company'] = wp_kses( $_REQUEST['company'], array() );
    	} else {
    		$result = false;
    		$EM_Notices->add_error( '<strong>Fejl</strong>: Indtast venligst din Virksomhed.' );
    	}
    	if( ! empty( $_REQUEST['billingaddress'] ) ) {
    		$EM_Booking->booking_meta['registration']['billingaddress'] = wp_kses( $_REQUEST['billingaddress'], array() );
    	}
    	if( ! empty( $_REQUEST['zip'] ) ) {
    		$EM_Booking->booking_meta['registration']['zip'] = wp_kses( $_REQUEST['zip'], array() );
    	}
    	if( ! empty( $_REQUEST['city'] ) ) {
    		$EM_Booking->booking_meta['registration']['city'] = wp_kses( $_REQUEST['city'], array() );
    	}
    	if( ! empty( $_REQUEST['tlf'] ) ) {
    		$EM_Booking->booking_meta['registration']['tlf'] = wp_kses( $_REQUEST['tlf'], array() );
    	}
    	if( ! empty( $_REQUEST['ean'] ) ) {
    		$EM_Booking->booking_meta['registration']['ean'] = wp_kses( $_REQUEST['ean'], array() );
    	}
    	return $result;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.