Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active March 4, 2019 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/e03fe3a4fe02c2803a8786e63b8d6978 to your computer and use it in GitHub Desktop.
Save Pebblo/e03fe3a4fe02c2803a8786e63b8d6978 to your computer and use it in GitHub Desktop.
An example of how to include conditional tags within the messages system
<?php
//Do not include the opening PHP tag if you already have one.
function tw_ee_register_template_shortcodes( $shortcodes, EE_Shortcodes $lib ) {
//Which sections of the messages system do we add the shrotcodes.
if ( $lib instanceof EE_Datetime_Shortcodes ||
$lib instanceof EE_Event_Shortcodes ||
$lib instanceof EE_Registration_Shortcodes ||
$lib instanceof EE_Transaction_Shortcodes ||
$lib instanceof EE_Attendee_List_Shortcodes ||
$lib instanceof EE_Ticket_List_Shortcodes
)
{
//Add custom shortcodes here.
//The shortcode is the key, the 'help text' is the shortcodes value.
$shortcodes['[if gte mso 9]'] = _('Testing template shortcodes');
$shortcodes['[endif]'] = _('Testing template shortcodes');
$shortcodes['[if mso]'] = _('Testing template shortcodes');
$shortcodes['[CUSTOM_SHORTCODE_*]'] = _('A custom shortcode that outputs whichever text after the * in a shortcode');
}
//Return the shortcodes.
return $shortcodes;
}
add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'tw_ee_register_template_shortcodes', 10, 2 );
function tw_ee_parse_template_shortcodes( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) {
if ( $shortcode == '[if gte mso 9]' ) {
return '[if gte mso 9]';
}
if ( $shortcode == '[endif]' ) {
return '[endif]';
}
if ( $shortcode == '[if mso]' ) {
return '[if mso]';
}
if (strpos($shortcode, '[CUSTOM_SHORTCODE_*') !== false) {
$shortcode = str_replace('[CUSTOM_SHORTCODE_*', '', $shortcode);
echo $shortcode;
$shortcode = trim(str_replace(']', '', $shortcode));
return '[' . $shortcode . ']';
}
return $parsed;
}
add_filter( 'FHEE__EE_Shortcodes__parser_after', 'tw_ee_parse_template_shortcodes', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment