-
-
Save Pebblo/dc950fde4e8bfd5a70c6d6fc5e2ac9c7 to your computer and use it in GitHub Desktop.
Example of pulling the primary registrant object from within the event based shortcodes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function register_new_tony_shortcodes( $shortcodes, EE_Shortcodes $lib ) { | |
//Add a shortcode to be used with the EE Event List within messages | |
if ( $lib instanceof EE_Event_Shortcodes ) { | |
//Add your shortcode to the add as the key, the value should be a description of the shortcode. | |
$shortcodes['[EVENT_URL_GENERATE]'] = _('The shortcode to generate the access url'); | |
} | |
//Return the shortcodes. | |
return $shortcodes; | |
} | |
add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'register_new_tony_shortcodes', 10, 2 ); | |
function register_new_tony_shortcodes_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) { | |
if ( $lib instanceof EE_Event_Shortcodes ) | |
{ | |
//Then check for our specific shortcode | |
if ( $shortcode == '[EVENT_URL_GENERATE]' ) | |
{ | |
//global $wpdb; | |
//First check we have an event object. | |
//You don't need the EE_Event object for this functionality, so this isn't needed currently. | |
$event = $data instanceof EE_Event ? $data : null; | |
//Pull the EE_Messages_Addressee object from extra data if it is available. | |
$aee = is_array( $extra_data ) && !empty( $extra_data['data'] ) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : null; | |
if ($aee ! instanceof EE_Messages_Addressee ) { | |
//After debugging I'd advise you change this to return an empty string. | |
return 'Object not Found'; | |
} | |
$primary_reg = $aee->primary_reg_obj; | |
$primary_attendee = $aee->primary_att_obj; | |
if( $primary_reg instanceof EE_Registration ) | |
{ | |
//Is a valid EE_Registration object, do something with it here. | |
} | |
if ( $primary_attendee instanceof EE_Attendee ) | |
{ | |
//$primary_attendee is a valid EE_Attendee object, as it's the primary | |
//attendee object you can pull the email from it. | |
$primary_att_email = $primary_attendee->email(); | |
return 'Result ' . $primary_att_email; | |
} | |
} | |
} | |
//If not within the correct section, or parsing the correct shortcode, | |
//Return the currently parsed content. | |
return $parsed; | |
} | |
add_filter( 'FHEE__EE_Shortcodes__parser_after', 'register_new_tony_shortcodes_parser', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment