PHP code example of rarst / fragment-cache

1. Go to this page and download the library: Download rarst/fragment-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rarst / fragment-cache example snippets


global $fragment_cache;

// completely remove handler, only use before init
unset( $fragment_cache['widget'] );

// or disable handler, use after init
$fragment_cache['widget']->disable();

add_filter( 'fc_skip_cache', function ( $skip, $type, $name, $args, $salt ) {

	// Widget by class.
	if ( 'widget' === $type && is_a( $args['callback'][0], 'WP_Widget_Meta' ) ) {
		return true;
	}

	// Menu by theme location.
	if ( 'menu' === $type && isset( $args['theme_location'] ) && 'header' === $args['theme_location'] ) {
		return true;
	}

	// Menu by name.
	if ( 'menu' === $type && isset( $args['menu'] ) ) {

		if ( 'Menu with login' === $args['menu'] ) {
			return true;
		}

		if ( is_a( $args['menu'], 'WP_Term' ) && 'Menu with login' === $args['menu']->name ) {
			return true;
		}
	}

	// Gallery by ID of post.
	if ( 'gallery' === $type && 123 === $args['post_id'] ) {
		return true;
	}

	return $skip;
}, 10, 5 );