Skip to content

Instantly share code, notes, and snippets.

View colorful-tones's full-sized avatar
💓
Don’t believe the hype!

Damon Cook colorful-tones

💓
Don’t believe the hype!
View GitHub Profile
@colorful-tones
colorful-tones / demo-block-bindings.php
Created October 1, 2024 20:48
Testing WP 6.7 Block Bindings stuff
<?php
/**
* Testing out WP 6.7 Block Bindings stuff.
*
* @see Block Bindings iteration for WordPress 6.7 #63018
* @link https://github.com/WordPress/gutenberg/issues/63018
*
* @package demo-plugin
*/
{
"name": "acf/car-details-condensed",
"title": "Car Details condensed (ACF Block)",
"description": "Display car details in a query loop.",
"category": "demo-acf-blocks",
"icon": "car",
"acf": {
"mode": "preview",
"renderTemplate": "template.php"
},
<!-- wp:group {"tagName":"section","metadata":{"name":"Cards","categories":["text","about"],"patternName":"twentytwentyfour/cards-4"},"align":"wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|30"}}},"layout":{"type":"grid","columnCount":null,"minimumColumnWidth":"16rem"}} -->
<section class="wp-block-group alignwide" style="margin-top:var(--wp--preset--spacing--30)"><!-- wp:cover {"url":"https://images.rawpixel.com/editor_1024/czNmcy1wcml2YXRlL3Jhd3BpeGVsX2ltYWdlcy93ZWJzaXRlX2NvbnRlbnQvbHIvcHgxMDg2NTYxLWltYWdlLWt3dnk1Y2l1LmpwZw.jpg","dimRatio":70,"customOverlayColor":"#515151","isUserOverlayColor":true,"tagName":"article","metadata":{"name":"Card"},"className":"is-style-card\u002d\u002danimated-default","style":{"border":{"radius":"12px"},"color":[]},"layout":{"type":"default"}} -->
<article class="wp-block-cover is-style-card--animated-default" style="border-radius:12px"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-70 has-background-dim" style="background-color:#
<!-- CURRENT block markup -->
<div class="wp-block-group cards">
<div class="wp-block-cover">
</div><!-- .wp-block-cover -->
</div><!-- .wp-block-group -->
<!-- DESIRED block markup -->
<ul class="wp-block-group cards">
<li class="wp-block-cover card"></li>
@colorful-tones
colorful-tones / twentytwentyfour-mock.json
Last active June 10, 2024 21:12
Testing Section Styles in WP 6.6 Beta 1
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"title": "Mock",
"blockTypes": [ "core/paragraph" ],
"styles": {
"color": {
"background": "#93008A",
"text": "#FFFB20"
},
@colorful-tones
colorful-tones / acf-field-group-demo.php
Last active April 26, 2024 14:29
ACF Chat Fridays - April 26, 2024 - Block Bindings with ACF demo
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_662ae89971cc7',
'title' => 'Call to action',
'fields' => array(
array(
@colorful-tones
colorful-tones / functions-alternative-approach.php
Last active August 29, 2024 19:24
Override core/navigation block styles without using `!important` (see comment below for implementation details)
/**
* Enqueues custom block styles for the theme.
*
* This function scans the styles folder in the theme to locate block styles.
* It then enqueues each block style using the `wp_enqueue_block_style` function.
*
* @url https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/
*/
function devrel_enqueue_custom_block_styles() {
@colorful-tones
colorful-tones / my_link.php
Created January 9, 2024 16:30
Parsing an ACF Link field type with defaults
@colorful-tones
colorful-tones / my-plugin.php
Last active December 6, 2023 21:35
Load JavaScript once on the page if a core block exists. As adapted from https://wordpress.stackexchange.com/a/328553
function enqueue_my_awesome_script_if_there_is_block( $content = '' ) {
if ( has_block( 'core/list' ) ) {
wp_enqueue_script(
'my-awesome-script',
plugins_url( 'hello-world.js', __FILE__ ),
array(),
'0.1.1',
true
);
}
<?php
/**
* Limit capabilities of editing ACF fields,
* post types, taxonomies and more in WP Admin.
*/
/**
* @link https://www.advancedcustomfields.com/resources/how-to-hide-acf-menu-from-clients/
*/
add_filter( 'acf/settings/show_admin', 'demo_acf_show_admin' );