Advertisement
Guest User

Shortcode for event registrant

a guest
Apr 26th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.05 KB | None | 0 0
  1. /* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
  2. function register_new_tony_shortcodes( $shortcodes, EE_Shortcodes $lib ) {
  3.  
  4.     //Add a shortcode to be used with the EE Datetimes within messages
  5.     if ( $lib instanceof EE_Datetime_Shortcodes ) {
  6.         //Add your shortcode to the add as the key, the value should be a description of the shortcode.
  7.         $shortcodes['[EVENT_URL_GENERATE]'] = _('The shortcode to generate the access url');
  8.     }
  9.     //Add a shortcode to be used with the EE Event List within messages
  10.     if ( $lib instanceof EE_Event_Shortcodes ) {
  11.         //Add your shortcode to the add as the key, the value should be a description of the shortcode.
  12.         $shortcodes['[EVENT_URL_GENERATE]'] = _('The shortcode to generate the access url');
  13.     }
  14.     //Return the shortcodes.
  15.     return $shortcodes;
  16. }
  17. add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'register_new_tony_shortcodes', 10, 2 );
  18. function register_new_tony_shortcodes_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) {
  19.    
  20.     //Check for the datetime shortcodes as that's were we added the custom shortcode above
  21.     //also check that $data is the expected object (in this case an EE_Datetime)
  22.     if ( $lib instanceof EE_Datetime_Shortcodes  && $data instanceof EE_Datetime ) {
  23.         //Then check for our specific shortcode
  24.         if ( $shortcode == '[EVENT_URL_GENERATE]' ) {
  25.            
  26.             //Do whatever you need to do here and return the value for that specific datetime.
  27.             return $data->ID();
  28.         }
  29.     }
  30.     if ( $lib instanceof EE_Event_Shortcodes )
  31.     {
  32.         //Then check for our specific shortcode
  33.         if ( $shortcode == '[EVENT_URL_GENERATE]' )
  34.         {
  35.             //global $wpdb;
  36.             //First check we have an event object.
  37.             $event = $extra_data instanceof EE_Event ? $data : null;
  38.             $aee = $extra_data instanceof EE_Messages_Addressee ? $data : NULL;
  39.             if ($aee !== null) return $aee; else return 'Object not Found';
  40.             $primary_reg = $aee->primary_reg_obj;
  41.             $prmary_attendee = $aee->primary_att_obj;
  42.            
  43.             if( $primary_reg instanceof EE_Registration )
  44.             {
  45.                 //Is a valid EE_Registration object, do something with it here.
  46.  
  47.             }
  48.            
  49.             if ( $primary_attendee instanceof EE_Attendee )
  50.             {
  51.                 //$primary_attendee is a valid EE_Attendee object, as it's the primary
  52.                 //attendee object you can pull the email from it.
  53.                 $primary_att_email = $primary_attendee->email();
  54.                 return 'Result ' . $primary_att_email;
  55.             }
  56.             //if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
  57.             /*if ( empty( $event ) )
  58.             {
  59.                 $aee = $data instanceof EE_Messages_Addressee ? $data : NULL;
  60.                 $aee = $extra_data instanceof EE_Messages_Addressee ? $extra_data : $aee;
  61.                 $event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : NULL;
  62.                 $event_att =  $aee instanceof EE_Messages_Addressee && $aee->att_obj instanceof EE_Attendee ? $aee->att_obj->email() : NULL;
  63.                 $primary_reg = $aee->primary_reg_obj;
  64.                 $primary_attendee = $aee->primary_att_obj;
  65.                 if ( $primary_attendee instanceof EE_Attendee )
  66.                 {
  67.                     //$primary_attendee is a valid EE_Attendee object, as it's the primary
  68.                     //attendee object you can pull the email from it.
  69.                     $primary_att_email = $primary_attendee->email();
  70.                     $message = 'This is a valid attendee object<br/>';
  71.                 }
  72.                 else
  73.                 {
  74.                     $message ='could not find attendee object<br/>';
  75.                 }
  76.                
  77.                 $message .= 'Result : <br/> test - '. print_r($aee,true);
  78.                 //$result = $wpdb->get_var('SELECT ATT_EMAIL FROM ');
  79.                 wp_mail('john-henry@dieselbrook.co.za', 'Debug' , $message);
  80.                 return $message;
  81.             }
  82.            
  83.            
  84.             //Check we do now actually have the event object.
  85.             if ( !empty( $event ) ) {
  86.                
  87.                 //return $page_id;
  88.             //}
  89.         }
  90.     }
  91.     //If not within the correct section, or parsing the correct shortcode,
  92.     //Return the currently parsed content.
  93.     return $parsed;
  94. }
  95. add_filter( 'FHEE__EE_Shortcodes__parser_after', 'register_new_tony_shortcodes_parser', 10, 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement