• I’m trying to use dynamic content, as explained in this post:
    http://ocaoimh.ie/y/6j

    I defined the cache tag

    define( 'DYNAMIC_CACHE_TEST_TAG', 'my-placeholder-string' );

    and put this markup in my template (I need the cart widget not to be cached)

    <!--my-placeholder-string-->
    <?php woocommerce_mini_cart(); ?>
    <!-- woocommerce_mini_cart(); -->
    <!--/my-placeholder-string-->

    Now I get this error:
    PHP Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

    If I delete the DYNAMIC_CACHE_TEST_TAG, then the site works again.

    I’m using PHP cache, with dynamic cache and lazy loading options enabled.

    What am I doing wrong?

    https://wordpress.org/plugins/wp-super-cache/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter stebcom

    (@stebcom)

    I forgot to replace

    add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );

    with

    add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );

    but I’m not able to get things working: I simply don’t see the code replacement.

    Thread Starter stebcom

    (@stebcom)

    Ok,

    now I figured out how to make the dynamic cache work, but I have another problem now: I’m using the output buffer but it’s working only with Google Chrome, as the string replacement is not being performed with IE, nor Firefox. Unfortunately, I can’t spot any error and the cache logs the same lines after a page request made by Chrome and a page request made by Firefox or IE.

    Any idea about this?

    Hey!
    I have the same problem! How did you get working?
    In pagesource I see Hello world with time… but if I do this
    <!–dynamiccontent–>
    <?php echo date_i18n(‘l, j. F Y’); ?>
    <!– echo date_i18n(‘l, j. F Y’); –>
    <!–/dynamiccontent–>

    The date still gets cached. Please tell how did you get to work! I’m search for solution a week now!

    Thread Starter stebcom

    (@stebcom)

    This is an example of usage for a woocommerce cart widget.
    I use this code in functions.php:

    if ( DYNAMIC_OUTPUT_BUFFER_TAG != '' ) {
    
      function dynamic_output_buffer_minicart( &$cachedata = 0 ) {
      	if ( defined( 'DYNAMIC_OB_TEXT' ) )
      		return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
    
      	ob_start();
      	// call the sidebar function, do something dynamic
      	woocommerce_mini_cart();
    
      	$text = ob_get_contents();
      	ob_end_clean();
    
      	if ( $cachedata === 0 ) { // called directly from the theme so store the output
      		define( 'DYNAMIC_OB_TEXT', $text );
      	} else // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php
      		return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
      }
    
      function dynamic_output_buffer_init() {
      	add_action( 'wp_footer', 'dynamic_output_buffer_minicart' );
        //add_action( 'wp_footer', 'dynamic_output_buffer_sidebar' );
      }
    
      function dynamic_output_buffer_test_safety( $safety ) {
      	if ( defined( 'DYNAMIC_OB_TEXT' ) ) // this is set when you call dynamic_output_buffer_test() from the theme
      		return 1; // ready to replace tag with dynamic content.
      	else
      		return 0; // tag cannot be replaced.
      }  
    
      add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_minicart' );
      add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
      add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
    
    }

    And this code in my template page:

    <?php
        if ( function_exists( 'dynamic_output_buffer_minicart' ) )
          dynamic_output_buffer_minicart();
        ?>Loading cart...

    You should also enable late_init option in the WP Super Cache configuration.

    Thanks a lot for reply. Did you also managed to get working the first way with ‘DYNAMIC_CACHE_TEST_TAG’ ?

    Yes late_init is enable, dynamic cache is enabled in php caching mode.

    Wrote my placeholder > define( ‘DYNAMIC_CACHE_TEST_TAG’ ‘dynamiccontent’ ); // Changed this to a secret placeholder tag // in dynamic-cache-test.php and upladed it back in WP Super Cache/plugins folder.

    I also replaced add_cacheaction( ‘wpsc_cachedata_safety’, ‘dynamic_output_buffer_test_safety’ );
    with
    add_cacheaction( ‘wpsc_cachedata_safety’, ‘dynamic_cache_test_safety’ );

    All these steps are correct?

    And is this worng <!–dynamiccontent–>
    <?php echo date_i18n(‘l, j. F Y’); ?>
    <!– echo date_i18n(‘l, j. F Y’); –>
    <!–/dynamiccontent–> ?

    I have to use this <?php
    if ( function_exists( ‘dynamic_output_buffer_minicart’ ) )
    dynamic_output_buffer_minicart();
    ?>Loading cart… where I want dynamic content to appear?

    Ok, if I paste your code in functions.php my site crashes.
    Where do you define( ‘DYNAMIC_OUTPUT_BUFFER_TAG’, ” ); // Change this to a secret placeholder tag ? If I define in dynamic-cache-test.php and put back in wp super cache plugins folder, my site still crashes. 🙁

    Thread Starter stebcom

    (@stebcom)

    I worked on this a lot of time ago, so I don’t remember that much. I think I gave up on Dynamic Cache Tag (the first option) because it didn’t work the way I needed, calling my functions ecc.
    Speaking about the output buffer: the code is still quite simple. You can define your constant where you prefer, like this:

    define( 'DYNAMIC_OUTPUT_BUFFER_TAG', 'Your placeholder' );

    The dynamic cache is not the only option to keep part of your pages dynamic, anyway: if you have issues with that, you should try loading your content via ajax.

    So you defined you constnat
    define( ‘DYNAMIC_OUTPUT_BUFFER_TAG’, ‘Your placeholder’ );
    in dynamic-cache-test.php and upladed it back in WP Super Cache/plugins folder. Is that correct? In your case it was minicart, right?

    And the you inserted code in to functions.php and templte page which you mentioned before?

    and thats it?

    oh I’m really lost into this, and it drives me nuts that I can’t get it work.

    Any chance you know a link for that ajax tutorial?

    I just want my date to be dynamic.

    Thanks anyway for your help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Fatal error trying using dynamic content’ is closed to new replies.