FEATURE Introducing utlities functions for the plugin
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
706f394438
commit
6ba42ac0ed
41
plugins/dynamiques-blocks/_utilities/utilities.php
Normal file
41
plugins/dynamiques-blocks/_utilities/utilities.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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;
|
||||
}
|
||||
|
|
@ -19,6 +19,9 @@ if (! defined('ABSPATH')) {
|
|||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/_utilities/utilities.php';
|
||||
|
||||
|
||||
function create_block_dynamiques_blocks_block_init()
|
||||
{
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user