I’m building a setup for a client that allows them to use a number of colour swatches throughout their gutenberg blocks in a post. They define the colour swatches in the document inspector panel (post-wide). This works works great for all of the custom blocks that I’ve built, however, when it comes to supporting core blocks, some of them display a wordpress colour palette that shows different colours.
All my custom colour palettes in the blocks update in realtime if the user changes the colour palette in the document inspector. However, in order to make the WordPress colour palettes show those same colours I need to edit the WordPress colour palettes via JavaScript (as they’re defined in the editor – so PHP can’t do it)
I was hoping there would be a block or editor filter like addFilter("block.registerBlockType", myFunction)
(link below) that could be tied into, but I can’t find one.
https://developer.wordpress.org/block-editor/developers/filters/block-filters/#filters
Is there any way to edit the colours in the WordPress color palettes with JavaScript?
I’m using WordPress 5.5.1
Self Hosted.
Without a way to edit the WordPress colour palettes client-side, I’ve attempted to change them with PHP or simply revert to hiding them…
PHP:
While not client-side, this would help a little (If I could get it working).
According to documentation it should work.
Even if I pass in a new array of colours it doesn’t work:
Am I missing something with the PHP?
Since PHP doesn’t do the job, hacking through JS works but it’s delicate – and still doesn’t get me what I actually want (which is to populate the colours dynamically).
JavaScript:
CSS:
Any ideas on how to edit the colours with JS or why the PHP isn’t working?
Thanks,
Dale.
- Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
- Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
- Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.
Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com