Skip to content

Commit

Permalink
feat: add filter to $output before it is cached (#2910)
Browse files Browse the repository at this point in the history
Add `timber/output/pre-cache` filter to hook into cache output before it's cached.

---------

Co-authored-by: Nicolas Lemoine <nico.lemoine@gmail.com>
  • Loading branch information
jl-a and nlemoine committed Feb 24, 2024
1 parent 5d1470f commit d1356fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ImageHelper.php
Expand Up @@ -396,7 +396,7 @@ public static function get_sideloaded_file_loc($file)

/**
* Filters basename for sideloaded files.
* @since 2.0.1
* @since 2.1.0
* @example
* ```php
* // Change the basename used for sideloaded images.
Expand Down
11 changes: 11 additions & 0 deletions src/Loader.php
Expand Up @@ -176,6 +176,17 @@ public function render($file, $data = null, $expires = false, $cache_mode = self

$template = $twig->load($file);
$output = $template->render($data);

/**
* Filters $output before it is cached.
*
* @since 2.1.0
*
* @param string $output
* @param array $data
* @param string $file
*/
$output = \apply_filters('timber/output/pre-cache', $output, $data, $file);
}

if (false !== $output && false !== $expires && null !== $key) {
Expand Down

0 comments on commit d1356fd

Please sign in to comment.