alexfuller123
Forum Replies Created
-
Forum: Plugins
In reply to: [Unlist Posts & Pages] Posibility to be Compatible with WordPres 6.6.2Thanks @bsfaradhy,
I’ll let my team know about this update. Thanks for all of the work your team has been doing to get this done!
Also, I was able to get the booking form to show successfully. I was looking at the post id and not the event id. Thanks so much for all your help!
It’s because I already have an events plugin built in my WordPress and we just needed a way for users to register for certain events and found this plugin. We thought a booking shortcode would fit better since we didn’t want to duplicate what we already have in the front end, unless we have to, but to utilize the tool to place in every event that we want to have a booking form under.
Thanks joneiseman, unfortunately, when I added this code to the script, it gave me this error:
PHP Fatal error: Uncaught Error: Call to a member function get_bookings() on null in /home9/eliminds/staging.elimindset.com/staging/wp-content/themes/eli/includes/shortcodes.php:23 Stack trace: #0 /home9/eliminds/staging.elimindset.com/staging/wp-includes/shortcodes.php(433): my_booking_form(Array, '', 'em-booking-form')
Is this because $EM_Event calling a function from another folder? Also, because we’re not going to use user login for event bookings, can I exclude the member booking and view bookings code?
So I did this:
<?php function em_get_event() { $EM_Event = EM_Events::get(['event' => $event]); //Setting $EM_EVENT variable //Placeholders preg_match_all("/(#@?_?[A-Za-z0-9_]+)({([^}]+)})?/", $event_string, $placeholders); $replaces = array(); foreach($placeholders[1] as $key => $result) { $match = true; $replace = ''; $full_result = $placeholders[0][$key]; $placeholder_atts = array($result); if( !empty($placeholders[3][$key]) ) $placeholder_atts[] = $placeholders[3][$key]; switch( $result ){ case '#_BOOKINGFORM': if( get_option('dbem_rsvp_enabled')){ if( !defined('EM_XSS_BOOKINGFORM_FILTER') && locate_template('plugins/events-manager/placeholders/bookingform.php') ){ //xss fix for old overridden booking forms add_filter('em_booking_form_action_url','esc_url'); define('EM_XSS_BOOKINGFORM_FILTER',true); } ob_start(); // We are firstly checking if the user has already booked a ticket at this event, if so offer a link to view their bookings. $EM_Booking = $EM_Event->get_bookings()->has_booking(); //count tickets and available tickets $template_vars = array( 'EM_Event' => $EM_Event, 'tickets_count' => count($EM_Event->get_bookings()->get_tickets()->tickets), 'available_tickets_count' => count($EM_Event->get_bookings()->get_available_tickets()), //decide whether user can book, event is open for bookings etc. 'can_book' => is_user_logged_in() || (get_option('dbem_bookings_anonymous') && !is_user_logged_in()), 'is_open' => $EM_Event->get_bookings()->is_open(), //whether there are any available tickets right now 'is_free' => $EM_Event->is_free(), 'show_tickets' => true, 'id' => absint($EM_Event->event_id), 'already_booked' => is_object($EM_Booking) && $EM_Booking->booking_id > 0, 'EM_Booking' => $EM_Event->get_bookings()->get_intent_default(), // get the booking intent if not supplied already ); //if user is logged out, check for member tickets that might be available, since we should ask them to log in instead of saying 'bookings closed' if( !$template_vars['is_open'] && !is_user_logged_in() && $EM_Event->get_bookings()->is_open(true) ){ $template_vars['is_open'] = true; $template_vars['can_book'] = false; $template_vars['show_tickets'] = get_option('dbem_bookings_tickets_show_unavailable') && get_option('dbem_bookings_tickets_show_member_tickets'); } em_locate_template('placeholders/bookingform.php', true, $template_vars); EM_Bookings::enqueue_js(); $replace = ob_get_clean(); } break; case '#_BOOKINGBUTTON': if( get_option('dbem_rsvp_enabled') && $EM_Event->event_rsvp ){ ob_start(); em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event'=>$EM_Event)); $replace = ob_get_clean(); } break; } } } add_shortcode('em-booking-form', 'em_get_event'); ?>
I added the shortcode to a test page and added what I believe is the event id and it’s not showing the booking form
Thanks so much for this! I will try to figure this out as this will be my first time creating a custom shortcode. Will I need to add any other functions like get_bookings or just stritcly look at the #_BOOKINGFORM placeholder code?