Add expiration param to static template function
This commit is contained in:
parent
53769425dd
commit
96dcbbeb4c
@ -3066,12 +3066,13 @@ function fictioneer_get_post_patreon_data( $post = null ) {
|
||||
* @since 5.19.0
|
||||
* @see get_template_part()
|
||||
*
|
||||
* @param string $slug The slug name for the generic template.
|
||||
* @param string|null $name Optional. The name of the specialized template.
|
||||
* @param array $args Optional. Additional arguments passed to the template.
|
||||
* @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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user