Initial public release of BreznFlow, an n8n workflow renderer for WordPress. Fully PHPCS-compliant (WordPress Coding Standards), security-hardened, and ready for WordPress.org plugin review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
106 lines
2.4 KiB
PHP
106 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Registry of built-in and custom viewer themes.
|
|
*
|
|
* @package BreznFlow
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
namespace BreznFlow\Features;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Manages built-in and custom visual themes for the workflow renderer.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class ThemeRegistry {
|
|
|
|
/**
|
|
* Built-in theme IDs and display names.
|
|
* IDs are used as CSS data-theme attribute values and as stylesheet handles.
|
|
*/
|
|
const BUILTIN = array(
|
|
'dark' => 'Dark',
|
|
'light' => 'Light',
|
|
'minimal' => 'Minimal',
|
|
'tech' => 'Tech',
|
|
'brezn' => 'Brezn',
|
|
);
|
|
|
|
/**
|
|
* Returns all available themes (built-in + custom) as:
|
|
* [ 'id' => ['name' => string, 'custom' => bool], ... ]
|
|
*
|
|
* @return array<string, array{name: string, custom: bool}>
|
|
*/
|
|
public static function discover(): array {
|
|
$themes = array();
|
|
|
|
foreach ( self::BUILTIN as $id => $name ) {
|
|
$themes[ $id ] = array(
|
|
'name' => $name,
|
|
'custom' => false,
|
|
);
|
|
}
|
|
|
|
$customs = get_option( 'breznflow_custom_themes', array() );
|
|
foreach ( $customs as $theme ) {
|
|
$themes[ $theme['id'] ] = array(
|
|
'name' => $theme['name'],
|
|
'custom' => true,
|
|
);
|
|
}
|
|
|
|
return $themes;
|
|
}
|
|
|
|
/**
|
|
* Returns all theme IDs as a flat array.
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function get_theme_ids(): array {
|
|
return array_keys( self::discover() );
|
|
}
|
|
|
|
/**
|
|
* Returns the URL to a built-in theme CSS file.
|
|
*
|
|
* @param string $id Built-in theme ID.
|
|
* @return string
|
|
*/
|
|
public static function get_builtin_url( string $id ): string {
|
|
return BREZNFLOW_URL . 'assets/themes/' . sanitize_key( $id ) . '.css';
|
|
}
|
|
|
|
/**
|
|
* Generates a CSS block for all custom themes, suitable for wp_add_inline_style().
|
|
* Tokens are mapped: token_name → --breznflow-token-name
|
|
*
|
|
* @return string CSS string (empty if no custom themes stored).
|
|
*/
|
|
public static function get_custom_theme_css(): string {
|
|
$themes = get_option( 'breznflow_custom_themes', array() );
|
|
$css = '';
|
|
|
|
foreach ( $themes as $theme ) {
|
|
$id = $theme['id'];
|
|
$sel = '.breznflow-wrap[data-theme="' . $id . '"],'
|
|
. '.breznflow-modal-overlay[data-theme="' . $id . '"],'
|
|
. '.breznflow-fs-portal[data-theme="' . $id . '"]';
|
|
|
|
$css .= $sel . '{';
|
|
foreach ( $theme['tokens'] as $token => $value ) {
|
|
$var = '--breznflow-' . str_replace( '_', '-', $token );
|
|
$css .= $var . ':' . $value . ';';
|
|
}
|
|
$css .= '}';
|
|
}
|
|
|
|
return $css;
|
|
}
|
|
}
|