Skip to content

Instantly share code, notes, and snippets.

@rahilwazir
Last active December 5, 2016 09:49
Show Gist options
  • Save rahilwazir/a5437bf7b2a29d1616c98c823329daee to your computer and use it in GitHub Desktop.
Save rahilwazir/a5437bf7b2a29d1616c98c823329daee to your computer and use it in GitHub Desktop.
WP Super Cache - Framentation (Dynamic data)

Dynamic Data

Example:

This is dynamic data replacement for EDD wallet plugin which uses [edd_deposit] shortcode called in post/page content.

define( 'TEST_EDD_DEPOSIT', '781e6e7d1d2735746aed85da550aac72' );

function test_dynamic_ob_test( &$cachedata ) {
    ob_start();
    do_shortcode( '[edd_deposit]' );
    $text = ob_get_contents();
    ob_end_clean();

    return str_replace( TEST_EDD_DEPOSIT, $text, $cachedata );
}
add_cacheaction( 'wpsc_cachedata', 'test_dynamic_ob_test' );

function test_dynamic_ob_safety_test( $safety ) {
    return 1;
}
add_cacheaction( 'wpsc_cachedata_safety', 'test_dynamic_ob_safety_test' );

Usage

Use the constant value 781e6e7d1d2735746aed85da550aac72 in your post/page content instead of shortcode [edd_deposit]

Note: The default shortcode definition of [edd_deposit] uses Output buffer, you need remove_shortcode and copy the same definition except the buffering part and add_shortcode with same name edd_deposit with new function definition.

Idea Source:

  1. http://www.xoogu.com/dynamic-shortcodes-plugin-for-wp-super-cache/#comment-3196
  2. http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment