Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Edge Side Includes (ESI) Shortcode
- */
- function esi_shortcode($attrs){
- $attrs = shortcode_atts(array(
- 'src' => '',
- 'ttl' => '1h',
- 'dca' => 'none',
- 'onerror' => 'continue'
- ), $attrs);
- // Serialize $attrs into HTML attributes
- $html_attrs = array();
- foreach($attrs as $name => $value){
- $html_attrs[] = $name . '="' . esc_attr($value) . '"';
- }
- // Yes, we return the esi shortcode back with the updated attributes because
- // WordPress will strip out <esi:include> at this point. The content filter
- // below will do the final replacement just in time.
- return sprintf('[esi %s ]', join(' ', $html_attrs));
- }
- add_shortcode( 'esi', 'esi_shortcode' );
- /**
- * Since <esi:include> tags don't make it through the WordPress content filter
- * when output by shortcode, do the replacement at the end.
- */
- function esi_shortcode_content_filter( $content ){
- return preg_replace_callback( '/\[esi(.+?)\]/', 'esi_shortcode_content_filter_callback', $content );
- }
- add_filter( 'the_content', 'esi_shortcode_content_filter', 100 );
- /**
- * This is because Akamai b0rks on & appearing in esi:include attributes
- */
- function esi_shortcode_content_filter_callback( $matches ){
- $attrs = str_replace( '&', '&', $matches[1] );
- return "<esi:include $attrs />";
- }
Add Comment
Please, Sign In to add comment