CMS Framework - v2.5.1
Themes - Theme Base Class
Added in 2.5.0 (#198).
Themes may ship an optional themes/{slug}/Theme.php that extends ArtisanPackUI\CMSFramework\Modules\Themes\Contracts\Theme to hook into the per-request lifecycle. Themes without a Theme.php stay fully backward compatible — the base class is opt-in.
What it unlocks
- Enqueue front-end and editor CSS + JS from PHP.
- Register custom image sizes.
- Register custom REST endpoints or block filters.
- Override the resolved theme class through the manifest (
themeClass), guarded by aReflectionClassprovenance check so an uploadedtheme.jsoncannot instantiate an unrelated first-party or vendorThemesubclass.
Example
<?php
namespace App\Themes\DigitalShopfront;
use ArtisanPackUI\CMSFramework\Modules\Themes\Contracts\Theme;
class DigitalShopfrontTheme extends Theme
{
public function frontendStyles(): array
{
return [
'digital-shopfront/main' => asset( 'themes/digital-shopfront/assets/main.css' ),
];
}
public function editorStyles(): array
{
return [
'digital-shopfront/editor' => asset( 'themes/digital-shopfront/assets/editor.css' ),
];
}
public function frontendScripts(): array
{
return [
'digital-shopfront/main' => asset( 'themes/digital-shopfront/assets/main.js' ),
];
}
}
Filter surface
Three filters let third parties add or mutate enqueue lists without subclassing:
ap.themes.frontendStylesap.themes.editorStylesap.themes.frontendScripts
Each carries the array of handles the theme returned from its matching method, so subscribers can array_merge or unset entries.
Static assets route
A new /themes/{slug}/assets/{path} route serves static assets from the theme's assets/ directory with:
- Slug, extension, and traversal validation.
- An explicit MIME map (so CSS/JS are never served as
text/plain). X-Content-Type-Options: nosniff.- CSP sandbox +
Content-Dispositionfor SVG to close the stored-XSS vector on uploaded themes.