42 lines
997 B
PHP
42 lines
997 B
PHP
<?php
|
|
|
|
function get_color_hex_from_slug(?string $slug): ?string
|
|
{
|
|
if (!$slug) return null;
|
|
|
|
$settings = wp_get_global_settings();
|
|
$palette = $settings['color']['palette']['theme'] ?? [];
|
|
|
|
foreach ($palette as $c) {
|
|
if (($c['slug'] ?? null) === $slug) {
|
|
return $c['color'] ?? null; // ex "#0f6f63"
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
function is_color_light($color)
|
|
{
|
|
// Si pas de couleur, considérer comme claire
|
|
if (empty($color)) {
|
|
return true;
|
|
}
|
|
|
|
$hex = str_replace("#", "", $color);
|
|
|
|
// Gérer les codes hex courts (3 caractères)
|
|
if (strlen($hex) === 3) {
|
|
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
|
|
}
|
|
|
|
// Convertir hex en RGB
|
|
$r = hexdec(substr($hex, 0, 2));
|
|
$g = hexdec(substr($hex, 2, 2));
|
|
$b = hexdec(substr($hex, 4, 2));
|
|
|
|
// Calculer la luminance relative (formule standard)
|
|
$luminance = (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
|
|
|
|
// Si luminance > 0.5, la couleur est claire
|
|
return $luminance > 0.5;
|
|
}
|