Advertisement
BakerMan

WooTickets Shortcode

Jan 17th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. /**
  2.  * Register a shortcode that can be embedded in pages/posts and will generate
  3.  * the Woo Tickets form and potentially the ticket forms for any other plugin
  4.  * using the same framework.
  5.  */
  6. add_shortcode('wooticketform', 'wooticketshortcode');
  7.  
  8. /**
  9.  * Handler for the wooticketform shortcode. Usage is:
  10.  *
  11.  *  [wooticketform eventid="123"]
  12.  *
  13.  * Where 123 is the post ID of the event you are selling tickets to.
  14.  *
  15.  * @param $args
  16.  * @return string
  17.  */
  18. function wooticketshortcode($args) {
  19.     if (!isset($args['eventid'])) return '';
  20.  
  21.     // We're going to meddle with the post global
  22.     $original_post = $GLOBALS['post'];
  23.     $GLOBALS['post'] = get_post($args['eventid']);
  24.  
  25.     // Get the ticket form (we may end up with an empty string if nothing has
  26.     // been setup or the wrong ID was specified)
  27.     ob_start();
  28.     tribe_get_ticket_form();
  29.     $form = ob_get_clean();
  30.  
  31.     // Clean up and return the form
  32.     $GLOBALS['post'] = $original_post;
  33.     return $form;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement