WordPress.org

Plugin Directory

Changeset 789969


Ignore:
Timestamp:
10/18/13 16:44:51 (6 months ago)
Author:
donncha
Message:

Revert the code that would allow output buffer callbacks to work in dynamic cached pages. It's too complicated/dangerous for too little payback. See http://wordpress.org/support/topic/mfunc-is-going-away-in-the-next-version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-super-cache/trunk/wp-cache-phase2.php

    r759244 r789969  
    55    global $cache_max_time, $wp_cache_request_uri, $super_cache_enabled, $wp_cache_object_cache, $cache_time_interval, $wp_cache_no_cache_for_get; 
    66    global $cache_enabled, $wp_cache_gmt_offset, $wp_cache_blog_charset, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval; 
    7     global $wp_cache_mfunc_enabled; 
    87 
    98    if ( $cache_enabled == false ) { 
     
    9291        header('Vary: Cookie'); 
    9392    ob_start( 'wp_cache_ob_callback' );  
    94  
    95     // cannot use output buffers in an output buffer callback so move the action to a shutdown function if using dynamic caching. 
    96     if ( $wp_cache_mfunc_enabled == 1 ) 
    97         add_action( 'shutdown', 'wpcache_shutdown' ); 
    98  
    9993    if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Created output buffer', 4 ); 
    10094 
     
    108102 
    109103    schedule_wp_gc(); 
    110 } 
    111  
    112 function wpcache_shutdown() { 
    113     global $wpsc_cached_data, $cache_compression, $wp_cache_gzip_encoding, $wp_cache_mfunc_enabled; 
    114     if ( isset( $wpsc_cached_data ) && $wpsc_cached_data != '' ) { 
    115         $wpsc_cachedata = do_cacheaction( 'wpsc_cachedata', $wpsc_cached_data ); // dynamic content for display 
    116  
    117         if ( !isset( $wp_cache_mfunc_enabled ) ) 
    118             $wp_cache_mfunc_enabled = 0; 
    119  
    120         // For some reason the first dynamic cached request for a page can't  
    121         // be gzipped as the browser shows gzipped data but my testing shows 
    122         // the browser still receives it gzipped even with this code commented out. 
    123         // Since this function is only called when dynamic caching is enabled 
    124         // this check effectively always returns false and it only sends 
    125         // uncompressed data when a page is generated 
    126         if ( !$wp_cache_mfunc_enabled && $cache_compression && $wp_cache_gzip_encoding ) { 
    127             wp_cache_add_to_buffer( $wpsc_cached_data, "Compression = gzip" ); 
    128             $gzdata = gzencode( $wpsc_cached_data, 6, FORCE_GZIP ); 
    129             if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Gzipping dynamic buffer for display: " . strlen( $wpsc_cached_data ) . " " . strlen( $gzdata ) ); 
    130             wpsc_send_headers( $gzdata ); 
    131             echo $gzdata; 
    132         } else { 
    133             wpsc_send_headers( $wpsc_cached_data ); 
    134             echo $wpsc_cached_data; 
    135         } 
    136     } 
    137104} 
    138105 
     
    302269 
    303270function wp_cache_ob_callback( $buffer ) { 
    304     global $wp_cache_pages, $wp_query, $wp_super_cache_query, $wp_cache_mfunc_enabled; 
     271    global $wp_cache_pages, $wp_query, $wp_super_cache_query; 
    305272    $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer ); 
    306273    if( defined( 'DONOTCACHEPAGE' ) ) { 
     
    348315    $buffer = &wp_cache_get_ob( $buffer ); 
    349316    wp_cache_shutdown_callback(); 
    350     // cannot use output buffers in an output buffer callback so move the action to a shutdown function. 
    351     if ( $wp_cache_mfunc_enabled == 1 ) { 
    352         global $wp_super_cache_late_init; 
    353         if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) 
    354             wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but late init not enabled. See the readme.txt for further details.' ); 
    355         global $wpsc_cached_data; 
    356         $wpsc_cached_data = $buffer; 
    357         return ''; 
    358     } 
    359317    return $buffer; 
    360318} 
     
    498456            if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) 
    499457                wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.' ); 
     458            return do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display 
    500459        } 
    501460 
     
    578537        } 
    579538        $wp_cache_meta[ 'dynamic' ] = true; 
    580         // see wpcache_shutdown() 
     539        $buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display 
     540 
     541        if ( $cache_compression && $wp_cache_gzip_encoding ) { 
     542            if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Gzipping dynamic buffer for display.", 5 ); 
     543            wp_cache_add_to_buffer( $buffer, "Compression = gzip" ); 
     544            $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); 
     545            $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); 
     546        } 
    581547    } else { 
    582548        if ( $gz || $wp_cache_gzip_encoding ) { 
     
    678644    } 
    679645    wp_cache_writers_exit(); 
    680     if ( $wp_cache_mfunc_enabled == 0 ) { 
    681         if ( $gzdata && $wp_cache_gzip_encoding ) 
    682             return wpsc_send_headers( $gzdata ); 
    683         else 
    684             return wpsc_send_headers( $buffer ); 
    685     } else { 
    686         return $buffer; 
    687     } 
    688 } 
    689  
    690 function wpsc_send_headers( &$buffer ) { 
    691     global $wp_cache_gzip_encoding; 
    692     if ( $wp_cache_gzip_encoding ) { 
    693         $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $buffer, '8bit' ) : strlen( $buffer ); 
     646    if ( !headers_sent() && $wp_cache_gzip_encoding && $gzdata) { 
     647        if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzip content headers. Sending buffer to browser", 5 ); 
    694648        header( 'Content-Encoding: ' . $wp_cache_gzip_encoding ); 
    695649        header( 'Vary: Accept-Encoding, Cookie' ); 
    696650        header( 'Content-Length: ' . $gzsize ); 
    697         if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Writing gzip content headers. Sending buffer to browser: $wp_cache_gzip_encoding, $gzsize", 5 ); 
     651        return $gzdata; 
    698652    } else { 
    699653        if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Sending buffer to browser", 5 ); 
    700     } 
    701     return $buffer; 
     654        return $buffer; 
     655    } 
    702656} 
    703657 
Note: See TracChangeset for help on using the changeset viewer.