WP Manifestindependent plugin directory

fragWP

Utility plugin for fragment caching in WordPress

★ 0stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/cphcloud/fragwp/archive/refs/heads/master.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

This class provides a framework for fragment caching in Wordpress. It handles both functions and files as the source of the fragments which makes it useful for caching both data and template parts.

Based on an original concept by @markjaquith

Usage

Output a fragment with a file as the source

$template = 'var/www/themes/mytheme/my_fragment.php';
frag('unique_key', $template);

Output a fragment with a function as the source

function do_frag(){
  echo 'Fragment content';
}

frag('unique_key', 'do_frag');

Output a fragment with a file as the source and set the fragment to expire in an hour

function do_frag(){
  echo 'Fragment content';
}
$ttl = 60*60; // One hour in seconds
frag('unique_key', 'do_frag', $ttl));

Output a fragment with a file as the source and set the fragment to expire in an hour or if the save_post hook is called

function do_frag(){
  echo 'Fragment content';
}
$ttl = 60*60; // One hour in seconds
frag('unique_key', 'do_frag', $ttl, array('save_post)));

Contribute

Pull requests are welcome :)

Practical

Maintained by @supertroels for @CPHCloud