Skip to content

WordPressUtilities/wpucacheblocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPU Cache Blocks

Cache Blocks

How to setup blocks.

add_filter('wpucacheblocks_blocks', 'demo_wpucacheblocks_blocks', 10, 1);
function demo_wpucacheblocks_blocks($blocks) {
    $blocks['headersearch'] = array(
        'path' => '/tpl/header/searchform.php'
    );
    return $blocks;
}

Global settings :

filter : wpucacheblocks_cacheprefix (string: default wpucacheblocks_)

String used to prefix cache keys & cache filenames (only [a-z0-9_] chars). Default : wpucacheblocks_.

filter : wpucacheblocks_cachetype (string: default file)

Cache method. You can choose between 'file' and 'apc'

filter : wpucacheblocks_cachedir (string: default wp-content/uploads/wpucacheblocks/)

Absolute path to the file cache dir.

Settings per block :

path (string)

Path to the file, relative to the Stylesheet Directory. You can also use 'fullpath', which is an absolute path to the file that will be cached.

expires (int: default 3600)

Duration in seconds after which the block will be refreshed. If 0, the block will never be refreshed in front, only via a hook.

reload_hooks (array of callbacks)

An array of hooks that will trigger a refresh for the block.

callback_prefix (callback function)

A callback for a function to prefix version of each cached block.

How to display a block content.

echo wpucacheblocks_block('headersearch');

Custom function to allow plugin deactivation :

function custom_wpucacheblocks_block($blockid) {
    if (function_exists('wpucacheblocks_block')) {
        return wpucacheblocks_block($blockid);
    }
    $blocks = apply_filters('wpucacheblocks_blocks', array());
    if (!is_array($blocks) || !isset($blocks[$blockid], $blocks[$blockid]['path'])) {
        return '';
    }
    ob_start();
    include $blocks[$blockid]['path'];
    return ob_get_clean();
}
echo custom_wpucacheblocks_block('headersearch');