[Plugin: WP Super Cache] Proposed alternative to mfunc/mclude
-
Hi, WP Super Cache is a great plugin. But I wanted to suggest an improvement.
The current mfunc/mclude syntax is a bit over complicated. I think people get confused with it because unless you read the PHP code you might not realise that WP Super Cache actually removed the PHP code from inbetween the tags, and then copies the code fragments in mfunc/mclude tags into its own templated PHP tags. A bit wierd!
Instead of something like this:
<!--mclude /scripts/adverts.php--> <?php require_once(ABSPATH . '/scripts/adverts.php'); ?> <!--/mclude--> <!--mfunc rml_banner_ad() --> <?php rml_banner_ad(); ?> <!--/mfunc--> <!--mfunc rml_stuff() --> <?php rml_stuff(); ?> <!--/mfunc-->
I propose a new dynamic-code tag so the above could be simplified to:
<!--dynamic-content--> <?php include_once(ABSPATH . '/scripts/adverts.php'); rml_banner_ad(); rml_stuff(); ?> <!--/dynamic-content-->
This looks simpler, and means you can put any amount of PHP in the tags.
I hacked together an update to make this work. It just needs an extra block in wp-cache-phase2.php I’m including the previous mfunc/mclude block for context.
if ( preg_match('/<!--mclude|<!--mfunc/', $buffer)) { //Dynamic content if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Dynamic content found in buffer.", 4 ); $store = preg_replace('|<!--mclude (.*?)-->(.*?)<!--/mclude-->|is', "<!--mclude-->\n<?php include_once('" . ABSPATH . "$1'); ?>\n<!--/mclude-->", $buffer); $store = preg_replace('|<!--mfunc (.*?)-->(.*?)<!--/mfunc-->|is', "<!--mfunc-->\n<?php $1 ;?>\n<!--/mfunc-->", $store); $wp_cache_meta[ 'dynamic' ] = true; /* Clean function calls in tag */ $buffer = preg_replace('|<!--mclude (.*?)-->|is', '<!--mclude-->', $buffer); $buffer = preg_replace('|<!--mfunc (.*?)-->|is', '<!--mfunc-->', $buffer); $store = apply_filters( 'wpsupercache_buffer', $store ); // Append WP Super Cache or Live page comment tag wp_cache_append_tag($buffer); global $wp_super_cache_late_init; if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) $buffer .= '<!-- Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details. -->'; if ( false == $wp_cache_object_cache ) { if( $fr ) fputs($fr, $store); } else { wp_cache_set( $oc_key, $store, 'supercache', $cache_max_time ); } } else if ( preg_match('/<!--dynamic-content-->/', $buffer)) { //Dynamic content if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Dynamic content found in buffer.", 4 ); $store = preg_replace('|<!--dynamic-content-->(.*?)<!--/dynamic-content-->|is', "<!--dynamic-content-->\n$1\n<!--/dynamic-content-->", $buffer); $wp_cache_meta[ 'dynamic' ] = true; /* Clean function calls in tag */ $store = apply_filters( 'wpsupercache_buffer', $store ); // Append WP Super Cache or Live page comment tag wp_cache_append_tag($buffer); global $wp_super_cache_late_init; if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) $buffer .= '<!-- Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details. -->'; if ( false == $wp_cache_object_cache ) { if( $fr ) fputs($fr, $store); } else { wp_cache_set( $oc_key, $store, 'supercache', $cache_max_time ); }
What do you think? Any chance of getting something like this into an updated version of WP Super Cache?
Cheers.
- The topic ‘[Plugin: WP Super Cache] Proposed alternative to mfunc/mclude’ is closed to new replies.