Last active
May 10, 2019 15:14
-
-
Save Pebblo/f6991ebb41ca7a6c31ba6eb6d25db342 to your computer and use it in GitHub Desktop.
Example of how to parse a custom shortcode ([DATETIME_ID]) added to the EE_Datetime_Shortcodes library.
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 | |
/* | |
* This filter allows you to hook in to the shortcode parser, check for a shortcode added above and return a value for it using the data passed to the parser. | |
* $parsed are the current values being parsed. | |
* $shortcode is the current shortcode passed to the parser. | |
* $data is the current data available, this can be different types of objects depending on the parser. | |
* $extra_data is a collaction of various data available within the messages system. | |
*/ | |
function ee_register_new_custom_messages_shortcodes_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) { | |
//Check for the datetime shortcodes library as that's one of the libraries we added a custom shortcode to above. | |
//also check that $data is the expected object (in this case an EE_Datetime as its for the EE_Datetime_Shortcodes library) | |
if ( $lib instanceof EE_Datetime_Shortcodes && $data instanceof EE_Datetime ) { | |
//Then check if we are parsing one of our custom shortcodes above. | |
if ( $shortcode === '[DATETIME_ID]' ) { | |
//Do whatever you need to do here and return the value for that specific datetime. | |
//In this example it simply returns the ID of the related EE_Datetime. | |
return $data->ID(); | |
} | |
} | |
//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', 'ee_register_new_custom_messages_shortcodes_parser', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment