Utils
in package
Calendar bucket ids and uploads-scoped paths.
Table of Contents
Constants
- BUCKET_PERIOD_SECONDS : mixed = 5184000
- FINGERPRINT_LENGTH : mixed = 10
Methods
- getBucketId() : mixed
- 10-char hex id for the active (or given) calendar bucket.
- getBucketIndex() : mixed
- Calendar bucket index (60-day periods).
- getUploadsRoot() : string|false
- Absolute path to the uploads base directory. Does not create it.
- readFileAndCorrectSourceMap() : mixed
- Read a JavaScript file and update the sourceMappingURL so the file can be served from any URL. Without a resolver the mapping comment is stripped.
- toUploadsUrl() : string|false
- HTTP URL for a path under the uploads `basedir`. False if the path is not under that root.
- writeFileCompletely() : bool
- Write `$content` to `$path` only when every byte lands. Uses a temp file + rename so readers never observe a truncated body at the final hashed URL; cleans up on failure.
Constants
BUCKET_PERIOD_SECONDS
public
mixed
BUCKET_PERIOD_SECONDS
= 5184000
FINGERPRINT_LENGTH
public
mixed
FINGERPRINT_LENGTH
= 10
Methods
getBucketId()
10-char hex id for the active (or given) calendar bucket.
public
static getBucketId(string $namespace[, int|null $bucketIndex = null ]) : mixed
Mixes install salt + plugin slug so the folder is neither a stable EasyList pin nor shared with another plugin.
Parameters
- $namespace : string
-
Plugin slug, e.g.
real-cookie-banner - $bucketIndex : int|null = null
getBucketIndex()
Calendar bucket index (60-day periods).
public
static getBucketIndex([int|null $now = null ]) : mixed
Parameters
- $now : int|null = null
getUploadsRoot()
Absolute path to the uploads base directory. Does not create it.
public
static getUploadsRoot() : string|false
Return values
string|falsereadFileAndCorrectSourceMap()
Read a JavaScript file and update the sourceMappingURL so the file can be served from any URL. Without a resolver the mapping comment is stripped.
public
static readFileAndCorrectSourceMap(string $path[, callable|null $resolver = null ]) : mixed
Parameters
- $path : string
-
The path to the original file (not the anonymous file)
- $resolver : callable|null = null
-
function (string $originalFilePath): stringreturning a URL prefix (directory) for the.mapfile
toUploadsUrl()
HTTP URL for a path under the uploads `basedir`. False if the path is not under that root.
public
static toUploadsUrl(string $absolutePath) : string|false
Uses WordPress' basedir/baseurl pair so a custom upload_path still yields a reachable URL.
Parameters
- $absolutePath : string
Return values
string|falsewriteFileCompletely()
Write `$content` to `$path` only when every byte lands. Uses a temp file + rename so readers never observe a truncated body at the final hashed URL; cleans up on failure.
public
static writeFileCompletely(string $path, string $content) : bool
Parameters
- $path : string
- $content : string