Add expiration param to static template function

This commit is contained in:
Tetrakern 2024-05-17 19:16:48 +02:00
parent 53769425dd
commit 96dcbbeb4c

View File

@ -3067,11 +3067,12 @@ function fictioneer_get_post_patreon_data( $post = null ) {
* @see get_template_part()
*
* @param string $slug The slug name for the generic template.
* @param int|null $expiration Optional. Seconds until the cache expires. Default 24 hours in seconds.
* @param string|null $name Optional. The name of the specialized template.
* @param array $args Optional. Additional arguments passed to the template.
*/
function fictioneer_get_static_template_part( $slug, $name = null, $args = [] ) {
function fictioneer_get_static_template_part( $slug, $expiration = null, $name = null, $args = [] ) {
// Use default function if...
if (
! get_option( 'fictioneer_enable_static_partials' ) ||
@ -3098,7 +3099,7 @@ function fictioneer_get_static_template_part( $slug, $name = null, $args = [] )
if ( file_exists( $path ) ) {
$filemtime = filemtime( $path );
if ( time() - $filemtime < DAY_IN_SECONDS ) {
if ( time() - $filemtime < ( $expiration ?? DAY_IN_SECONDS ) ) {
echo file_get_contents( $path );
return;
}
@ -3141,7 +3142,7 @@ function fictioneer_clear_cached_html() {
$todo = ( $fileinfo->isDir() ? 'rmdir' : 'unlink' );
if ( ! $todo( $fileinfo->getRealPath() ) ) {
error_log( "Failed to delete " . $fileinfo->getRealPath() );
error_log( 'Failed to delete ' . $fileinfo->getRealPath() );
}
}
}