Add constant for cache directory path and uri
This commit is contained in:
parent
d91472d36a
commit
cf9de78607
@ -1567,6 +1567,7 @@ define( 'CONSTANT_NAME', value );
|
||||
| FICTIONEER_DISCORD_EMBED_COLOR | string | Color code for Discord notifications. Default `'9692513'`.
|
||||
| FICTIONEER_TRUNCATION_ELLIPSIS | string | Appended to truncated strings. Default `…`.
|
||||
| FICTIONEER_AGE_CONFIRMATION_REDIRECT | string | Redirect URL if a visitor reject the age confirmation. Default `https://search.brave.com/`.
|
||||
| FICTIONEER_CACHE_DIR | string | Server path to the theme cache directory.
|
||||
| FICTIONEER_COMMENTCODE_TTL | integer | How long guests can see their private/unapproved comments in _seconds_. Default `600`.
|
||||
| FICTIONEER_AJAX_TTL | integer | How long to cache certain AJAX requests locally in _milliseconds_. Default `60000`.
|
||||
| FICTIONEER_AJAX_LOGIN_TTL | integer | How long to cache AJAX authentications locally in _milliseconds_. Default `15000`.
|
||||
|
@ -130,6 +130,16 @@ if ( ! defined( 'FICTIONEER_DEFAULT_CHAPTER_ICON' ) ) {
|
||||
define( 'FICTIONEER_DEFAULT_CHAPTER_ICON', 'fa-solid fa-book' );
|
||||
}
|
||||
|
||||
// String: Path to cache directory (without trailing slash)
|
||||
if ( ! defined( 'FICTIONEER_CACHE_DIR' ) ) {
|
||||
define( 'FICTIONEER_CACHE_DIR', WP_CONTENT_DIR . '/themes/fictioneer/cache' );
|
||||
}
|
||||
|
||||
// String: Path to cache URL (without trailing slash)
|
||||
if ( ! defined( 'FICTIONEER_CACHE_URL' ) ) {
|
||||
define( 'FICTIONEER_CACHE_URL', WP_CONTENT_URL . '/themes/fictioneer/cache' );
|
||||
}
|
||||
|
||||
/*
|
||||
* Date Strings
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ function fictioneer_watch_for_customizer_updates() {
|
||||
fictioneer_clear_all_cached_partials();
|
||||
|
||||
// Files
|
||||
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css';
|
||||
$bundled_fonts = FICTIONEER_CACHE_DIR . '/bundled-fonts.css';
|
||||
|
||||
if ( file_exists( $bundled_fonts ) ) {
|
||||
unlink( $bundled_fonts );
|
||||
|
@ -466,7 +466,7 @@ function fictioneer_get_font_data() {
|
||||
function fictioneer_build_bundled_fonts() {
|
||||
// Setup
|
||||
$base_fonts = WP_CONTENT_DIR . '/themes/fictioneer/css/fonts-base.css';
|
||||
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css';
|
||||
$bundled_fonts = FICTIONEER_CACHE_DIR . '/bundled-fonts.css';
|
||||
$fonts = fictioneer_get_font_data();
|
||||
$disabled_fonts = get_option( 'fictioneer_disabled_fonts', [] );
|
||||
$disabled_fonts = is_array( $disabled_fonts ) ? $disabled_fonts : [];
|
||||
@ -477,8 +477,8 @@ function fictioneer_build_bundled_fonts() {
|
||||
$fonts = apply_filters( 'fictioneer_filter_pre_build_bundled_fonts', $fonts );
|
||||
|
||||
// Make sure directory exists
|
||||
if ( ! file_exists( dirname( $bundled_fonts ) ) ) {
|
||||
mkdir( dirname( $bundled_fonts ), 0755, true );
|
||||
if ( ! is_dir( FICTIONEER_CACHE_DIR ) ) {
|
||||
mkdir( FICTIONEER_CACHE_DIR, 0755, true );
|
||||
}
|
||||
|
||||
// Build
|
||||
@ -621,7 +621,7 @@ function fictioneer_get_theme_color( $mod, $default = null ) {
|
||||
function fictioneer_build_customize_css( $context = null ) {
|
||||
// --- Setup -----------------------------------------------------------------
|
||||
|
||||
$file_path = WP_CONTENT_DIR . '/themes/fictioneer/cache/customize.css';
|
||||
$file_path = FICTIONEER_CACHE_DIR . '/customize.css';
|
||||
$site_width = (int) get_theme_mod( 'site_width', 960 );
|
||||
$header_image_style = get_theme_mod( 'header_image_style', 'default' );
|
||||
$header_style = get_theme_mod( 'header_style', 'default' );
|
||||
@ -634,12 +634,12 @@ function fictioneer_build_customize_css( $context = null ) {
|
||||
$css = '';
|
||||
|
||||
if ( $context === 'preview' ) {
|
||||
$file_path = WP_CONTENT_DIR . '/themes/fictioneer/cache/customize-preview.css';
|
||||
$file_path = FICTIONEER_CACHE_DIR . '/customize-preview.css';
|
||||
}
|
||||
|
||||
// Make sure directory exists
|
||||
if ( ! file_exists( dirname( $file_path ) ) ) {
|
||||
mkdir( dirname( $file_path ), 0755, true );
|
||||
if ( ! is_dir( FICTIONEER_CACHE_DIR ) ) {
|
||||
mkdir( FICTIONEER_CACHE_DIR, 0755, true );
|
||||
}
|
||||
|
||||
// --- Assets ----------------------------------------------------------------
|
||||
|
@ -884,7 +884,7 @@ function fictioneer_get_cache_salt() {
|
||||
|
||||
function fictioneer_create_html_cache_directory( $dir = null ) {
|
||||
// Setup
|
||||
$default_dir = get_template_directory() . '/cache/html/';
|
||||
$default_dir = FICTIONEER_CACHE_DIR . '/html/';
|
||||
$dir = $dir ?? $default_dir;
|
||||
$result = true;
|
||||
|
||||
@ -945,7 +945,7 @@ function fictioneer_get_cached_partial( $slug, $identifier = '', $expiration = n
|
||||
// Setup
|
||||
$args_hash = md5( serialize( $args ) . $identifier . fictioneer_get_cache_salt() );
|
||||
$static_file = $slug . ( $name ? "-{$name}" : '' ) . "-{$args_hash}.html";
|
||||
$path = get_template_directory() . '/cache/html/' . $static_file;
|
||||
$path = FICTIONEER_CACHE_DIR . '/html/' . $static_file;
|
||||
|
||||
// Make sure directory exists and handle failure
|
||||
if ( ! fictioneer_create_html_cache_directory( dirname( $path ) ) ) {
|
||||
@ -995,7 +995,7 @@ function fictioneer_clear_all_cached_partials() {
|
||||
$done = true;
|
||||
|
||||
// Setup
|
||||
$cache_dir = get_template_directory() . '/cache/html/';
|
||||
$cache_dir = FICTIONEER_CACHE_DIR . '/html/';
|
||||
|
||||
// Regenerate cache salt
|
||||
fictioneer_generate_cache_salt();
|
||||
@ -1053,7 +1053,7 @@ function fictioneer_get_static_content( $more_link_text = \null, $strip_teaser =
|
||||
|
||||
// Setup
|
||||
$hash = md5( $post->ID . fictioneer_get_cache_salt() );
|
||||
$dir = get_template_directory() . '/cache/html/' . substr( $hash, 0, 2 );
|
||||
$dir = FICTIONEER_CACHE_DIR . '/html/' . substr( $hash, 0, 2 );
|
||||
$path = "{$dir}/{$hash}_{$post->ID}.html";
|
||||
|
||||
// Make sure directory exists and handle failure
|
||||
@ -1112,7 +1112,7 @@ function fictioneer_the_static_content( $more_link_text = \null, $strip_teaser =
|
||||
function fictioneer_clear_cached_content( $post_id ) {
|
||||
// Setup
|
||||
$hash = md5( $post_id . fictioneer_get_cache_salt() );
|
||||
$dir = get_template_directory() . '/cache/html/' . substr( $hash, 0, 2 );
|
||||
$dir = FICTIONEER_CACHE_DIR . '/html/' . substr( $hash, 0, 2 );
|
||||
$path = "{$dir}/{$hash}_{$post_id}.html";
|
||||
|
||||
// Delete file
|
||||
|
@ -284,8 +284,7 @@ function fictioneer_purge_caches_after_update() {
|
||||
fictioneer_regenerate_cache_bust();
|
||||
|
||||
// Delete cached files
|
||||
$cache_dir = WP_CONTENT_DIR . '/themes/fictioneer/cache/';
|
||||
$files = glob( $cache_dir . '*' );
|
||||
$files = glob( trailingslashit( FICTIONEER_CACHE_DIR ) . '*' );
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
if ( is_file( $file ) ) {
|
||||
@ -922,7 +921,7 @@ add_action( 'wp_enqueue_scripts', 'fictioneer_style_queue' );
|
||||
|
||||
function fictioneer_output_customize_css() {
|
||||
// Setup
|
||||
$file_path = WP_CONTENT_DIR . '/themes/fictioneer/cache/customize.css';
|
||||
$file_path = FICTIONEER_CACHE_DIR . '/customize.css';
|
||||
|
||||
// Create file if it does not exist
|
||||
if ( ! file_exists( $file_path ) ) {
|
||||
@ -933,7 +932,7 @@ function fictioneer_output_customize_css() {
|
||||
if ( file_exists( $file_path ) ) {
|
||||
wp_enqueue_style(
|
||||
'fictioneer-customize',
|
||||
get_template_directory_uri() . "/cache/customize.css",
|
||||
FICTIONEER_CACHE_URL . "/customize.css",
|
||||
get_option( 'fictioneer_bundle_stylesheets' ) ? ['fictioneer-complete'] : ['fictioneer-application'],
|
||||
fictioneer_get_cache_bust()
|
||||
);
|
||||
@ -952,7 +951,7 @@ if ( ! is_customize_preview() ) {
|
||||
|
||||
function fictioneer_output_customize_preview_css() {
|
||||
// Setup
|
||||
$file_path = WP_CONTENT_DIR . '/themes/fictioneer/cache/customize-preview.css';
|
||||
$file_path = FICTIONEER_CACHE_DIR . '/customize-preview.css';
|
||||
|
||||
// Create file if it does not exist
|
||||
fictioneer_build_customize_css( 'preview' );
|
||||
@ -961,7 +960,7 @@ function fictioneer_output_customize_preview_css() {
|
||||
if ( file_exists( $file_path ) ) {
|
||||
wp_enqueue_style(
|
||||
'fictioneer-customize',
|
||||
get_template_directory_uri() . "/cache/customize-preview.css",
|
||||
FICTIONEER_CACHE_URL . "/customize-preview.css",
|
||||
['fictioneer-application'],
|
||||
time() // Prevents caching in preview
|
||||
);
|
||||
@ -1055,7 +1054,7 @@ if ( ! function_exists( 'fictioneer_add_font_awesome' ) ) {
|
||||
function fictioneer_build_dynamic_scripts() {
|
||||
// --- Setup -----------------------------------------------------------------
|
||||
|
||||
$file_path = WP_CONTENT_DIR . '/themes/fictioneer/cache/dynamic-scripts.js';
|
||||
$file_path = FICTIONEER_CACHE_DIR . '/dynamic-scripts.js';
|
||||
$last_version = get_transient( 'fictioneer_dynamic_scripts_version' );
|
||||
$scripts = '';
|
||||
|
||||
@ -1065,8 +1064,8 @@ function fictioneer_build_dynamic_scripts() {
|
||||
}
|
||||
|
||||
// Make sure directory exists
|
||||
if ( ! file_exists( dirname( $file_path ) ) ) {
|
||||
mkdir( dirname( $file_path ), 0755, true );
|
||||
if ( ! is_dir( FICTIONEER_CACHE_DIR ) ) {
|
||||
mkdir( FICTIONEER_CACHE_DIR, 0755, true );
|
||||
}
|
||||
|
||||
// --- AJAX Settings ---------------------------------------------------------
|
||||
@ -1126,7 +1125,7 @@ function fictioneer_add_custom_scripts() {
|
||||
// Dynamic scripts
|
||||
fictioneer_build_dynamic_scripts();
|
||||
|
||||
wp_register_script( 'fictioneer-dynamic-scripts', get_template_directory_uri() . '/cache/dynamic-scripts.js', [], $cache_bust, $strategy );
|
||||
wp_register_script( 'fictioneer-dynamic-scripts', FICTIONEER_CACHE_URL . '/dynamic-scripts.js', [], $cache_bust, $strategy );
|
||||
|
||||
// Register and enqueue single scripts or complete script
|
||||
if ( ! get_option( 'fictioneer_bundle_scripts' ) ) {
|
||||
@ -1522,7 +1521,7 @@ if ( ! function_exists( 'fictioneer_output_head_fonts' ) ) {
|
||||
fictioneer_output_critical_fonts();
|
||||
|
||||
// Setup
|
||||
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css';
|
||||
$bundled_fonts = FICTIONEER_CACHE_DIR . '/bundled-fonts.css';
|
||||
$last_built_timestamp = get_option( 'fictioneer_bundled_fonts_timestamp', '123456789' );
|
||||
$cache_bust = "?timestamp={$last_built_timestamp}";
|
||||
$loading_pattern = fictioneer_get_async_css_loading_pattern();
|
||||
@ -1535,7 +1534,7 @@ if ( ! function_exists( 'fictioneer_output_head_fonts' ) ) {
|
||||
// Output font stylesheets...
|
||||
if ( file_exists( $bundled_fonts ) ) {
|
||||
// ... base and custom
|
||||
$custom_fonts_href = get_template_directory_uri() . '/cache/bundled-fonts.css' . $cache_bust;
|
||||
$custom_fonts_href = FICTIONEER_CACHE_URL . '/bundled-fonts.css' . $cache_bust;
|
||||
|
||||
// Start HTML ---> ?>
|
||||
<link rel="stylesheet" id="fictioneer-bundled-fonts-stylesheet" href="<?php echo $custom_fonts_href; ?>" data-no-optimize="1" data-no-minify="1" <?php echo $loading_pattern; ?>>
|
||||
|
@ -470,8 +470,7 @@ function fictioneer_purge_theme_caches() {
|
||||
fictioneer_delete_transients_like( 'fictioneer_' );
|
||||
|
||||
// Delete cached files
|
||||
$cache_dir = WP_CONTENT_DIR . '/themes/fictioneer/cache/';
|
||||
$files = glob( $cache_dir . '*' );
|
||||
$files = glob( trailingslashit( FICTIONEER_CACHE_DIR ) . '*' );
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
if ( is_file( $file ) ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user