Utilities
URLs
cleanUrl(string $type, string $slug = null, int $page = null, string $category = null): string
Single source of truth for all front-end URLs.
cleanUrl('home') // https://example.com/
cleanUrl('article', 'my-article') // https://example.com/article/my-article/
cleanUrl('articles', null, 2) // https://example.com/articles/page/2/
cleanUrl('category', null, null, 'news') // https://example.com/category/news/
getBaseUrl(): string
Base URL with a trailing slash. Derives the CMS sub-directory from CMS_ROOT compared against $_SERVER['DOCUMENT_ROOT'], falling back to SCRIPT_NAME — reliable regardless of which entry script handles the request, including from plugin subdirectories.
url_slug(string $type): string
Localized URL prefix for a content type, from the active front-end locale. Supported: article, articles, project, projects, page, pages, category, tag.
getThemeResourcePath(string $resource, string $file = ''): string
Relative path to a resource inside the active theme directory.
loadThemePartial(string $name, array $vars = []): ?string
Loads theme/{active}/partials/{name}.php, returns buffered output, or null if not found (caller supplies its own fallback).
loadThemeTemplate(string $template, array $params = []): void
Includes theme/{active}/{template}.php, cascading to theme/default/ for any missing file.
SEO & data
generateSEO(string $pageTitle, string $type, string $slug, array $data, array $settings): array
Merges item-level SEO overrides with site defaults. Returns ['title' => ..., 'description' => ...].
getCategoryPath(string $categorySlug, array $data): string
Full hierarchical slug path of a category, e.g. 'naturopathy/supplements'.
getCategoryDescendants(string $categorySlug, array $categories): array
Every descendant slug at any depth below the given category — what powers category pages including content from their sub-categories.
output_canonical_url(?array $pageData = null): string
<link rel="canonical">, from $pageData['canonical_url'] if set, otherwise auto-generated from the current URI.
Settings & themes
loadConfig(): array
Loads and merges config.json with defaults. Handles the theme-preview token (_tp) to override active_theme per-request without touching disk, and sets the configured timezone for all date() calls. (Renamed from loadSettings() in the 1.3.3 restructure — settings.json itself was renamed to config.json at the same time.)
getAvailableThemes(): array
Scans /theme/, returns folder names containing a valid css/style.css.
Page detection
is_home(): bool
is_current_page(string $type, string $slug = ''): bool
if (is_home()) { echo '<div class="hero">…</div>'; }
if (is_current_page('article', 'my-article')) { /* … */ }
Formatting
format_date(string $date): string
Formats a Y-m-d[ H:i] string per the site's configured date_format. Returns '' for an empty input — a theme checking !empty($item['date']) before calling this is the correct guard.
sanitizeSlug(string $text, bool $allowSpecialChars = false): string
URL-safe slug, transliterating accented characters.
decodeHtmlEntities(string $text): string
Decodes entities (ENT_QUOTES | ENT_HTML5, UTF-8).
get_social_icon(string $platform): string
Inline SVG icon. Supported: instagram, x (and legacy twitter, kept for backward compatibility), facebook, github, linkedin, youtube, tiktok, discord, whatsapp, snapchat, pinterest, threads, twitch, telegram, reddit, mastodon, bluesky — 18 platforms total.
_clean_excerpt(string $html, int $length = 150): string
Strips shortcodes and HTML, truncates at a word boundary. Raw primitive — prefer get_article_summary() in templates.
_asset_version(string $absPath): string
?v=<mtime> cache-busting query string; '' if the file doesn't exist. Used internally by render_header_scripts().
i18n
__t(string $key, string $fallback = ''): string
Translated string for the active locale.
_e(string $key): void
Direct echo of __t().
__n(string $singular, string $plural, int $count): string
Plural-aware translation — picks the singular or plural locale string based on $count.
