Skip to content

Instantly share code, notes, and snippets.

@Pebblo Pebblo/functions.php
Last active Mar 4, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.