Skip to content

Instantly share code, notes, and snippets.

View smwoll's full-sized avatar
🏠
Working from home

Sky smwoll

🏠
Working from home
View GitHub Profile
@smwoll
smwoll / cta-block-index.js
Last active April 26, 2022 15:12
Example Call to Action Block in React. Uses InnerBlocks for the editable content within. For brevity in this example, all functionality is kept in the same index.js file.
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { InnerBlocks } from '@wordpress/block-editor';
import { useBlockProps } from '@wordpress/block-editor';
/**
* Block Name.
* Create an example Call to Action Block
* Uses InnerBlocks for editable content within.
*/
@smwoll
smwoll / acf-cta-block-lock-template.php
Last active April 26, 2022 15:05
Example of the same ACF Call to Action Block, with individual blocks locked in the template. Learn more at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/#individual-block-locking
<?php
/**
* ACF Call to Action example block template.
*
* More info: https://www.advancedcustomfields.com/resources/acf_register_block_type/
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
@smwoll
smwoll / acf-cta-block-template.php
Last active April 26, 2022 15:06
Example template for an ACF powered custom WordPress block using innerBlocks.
<?php
/**
* ACF Call to Action example block template.
*
* More info: https://www.advancedcustomfields.com/resources/acf_register_block_type/
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
@smwoll
smwoll / acf-cta-block-registration.php
Last active April 26, 2022 15:18
Example registration for an ACF powered custom WordPress block using innerBlocks.
<?php
/**
* Template for registering an ACF powered custom block.
*
* More info: https://www.advancedcustomfields.com/resources/blocks/
*/
/**
* Register the block.
*/
@smwoll
smwoll / IO-scroll-to-top.js
Last active August 16, 2021 21:26
Simple scroll to top using intersection observer. Expects a wrapping div, or another element that contains the full length of the page.
// use intersection observer to show and hide a scroll to top button - target the site-footer
const footer = document.querySelector('.site-footer');
const siteWrap = document.querySelector('.site-wrap');
const scrollBtnOffset = siteWrap.offsetHeight * 0.45;
const scrollToTopBtn = document.querySelector('.scroll-to-top-button');
const rootElement = document.documentElement;
@smwoll
smwoll / wp-rest-api-auth.php
Created February 9, 2021 22:04
Simple MU plugin to prevent WordPress REST API access without login
<?php
/**
* Plugin Name: WP REST API Login Filter
* Plugin URI: https://skyland.dev
* Description: Disables the WP rest API without login.
* Version: 1
* Author: Sky
* Author URI: https://skyland.dev
*
*/