block background colours and tint

This commit is contained in:
2026-01-02 01:15:56 +00:00
parent b0d6d90616
commit 70e995cbd5
6 changed files with 175 additions and 15 deletions

View File

@@ -6,8 +6,8 @@ class DisablePost
{
public function __construct()
{
add_filter('register_post_type_args', [$this, 'args'], 0, 2);
add_filter('register_taxonomy_args', [$this, 'args'], 0, 2);
// add_filter('register_post_type_args', [$this, 'args'], 0, 2);
// add_filter('register_taxonomy_args', [$this, 'args'], 0, 2);
}
public function args($args, $type)

48
app/Admin/Theme.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
namespace App\Admin;
use ourcodeworld\NameThatColor\ColorInterpreter as NameThatColor;
use App\Utilities;
class Theme
{
public function __construct()
{
add_action( 'after_setup_theme', [$this, 'DynamicPalette'] );
// add_action( 'init' , [$this, 'BackgroundTints']);
}
public function DynamicPalette()
{
$colour = new Utilities\Colour;
$NameThatColour = new NameThatColor;
$palette = [];
$colours = $colour->values();
foreach($colours as $slug => $hex) {
$palette[] = [
'name' => esc_html__(@$NameThatColour->name($hex)['name'], 'badegg'),
'slug' => $slug,
'color' => $hex,
];
}
if(!empty($colours)) {
add_theme_support('editor-color-palette', $palette);
}
}
public function BackgroundTints()
{
register_block_style(
'badegg/article',
[
'name' => 'badegg-colour-tint',
'label' => __('Tint', 'badegg'),
// 'inline_style' =>'.wp-block-image.is-style-badegg-colour-tint { }',
]
);
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Utilities;
use ourcodeworld\NameThatColor\ColorInterpreter as NameThatColor;
class RestAPI
{
@@ -13,18 +14,27 @@ class RestAPI
{
$restBase = 'badegg/v1';
register_rest_route($restBase, '/blocks/container-widths', [
register_rest_route($restBase, '/blocks/config', [
'methods' => 'GET',
'callback' => [ $this, 'containerWidths'],
'callback' => [ $this, 'config'],
'permission_callback' => function(){
return true;
},
]);
}
public function config()
{
return rest_ensure_response([
'container' => $this->containerWidths(),
'colours' => $this->colours(),
'tints' => $this->tints(),
]);
}
public function containerWidths()
{
$containerWidths = [
return [
[ 'label' => __('Auto', 'badegg'), 'value' => 0 ],
[ 'label' => __('Narrow', 'badegg'), 'value' => 'narrow' ],
[ 'label' => __('Small', 'badegg'), 'value' => 'small' ],
@@ -32,7 +42,39 @@ class RestAPI
[ 'label' => __('Large', 'badegg'), 'value' => 'large' ],
[ 'label' => __('Edge to edge', 'badegg'), 'value' => 'full' ],
];
return rest_ensure_response($containerWidths);
}
public function colours()
{
$colour = new Colour;
$NameThatColour = new NameThatColor;
$palette = [];
$colours = $colour->values();
foreach($colours as $slug => $hex) {
$palette[] = [
'name' => esc_html__(@$NameThatColour->name($hex)['name'], 'badegg'),
'slug' => $slug,
'color' => $hex,
];
}
return $palette;
}
public function tints()
{
return [
['label' => __('Lightest', 'badegg'), 'value' => 'lightest'],
['label' => __('Lighter', 'badegg'), 'value' => 'lighter' ],
['label' => __('Light', 'badegg'), 'value' => 'light' ],
['label' => __('None', 'badegg'), 'value' => 0 ],
['label' => __('Dark', 'badegg'), 'value' => 'dark' ],
['label' => __('Darker', 'badegg'), 'value' => 'darker' ],
['label' => __('Darkest', 'badegg'), 'value' => 'darkest' ],
];
}
}