Skip to content

Instantly share code, notes, and snippets.

@mishterk
mishterk / LocalValetDriver.php
Last active August 15, 2024 19:05
A local Valet driver for proxying images to a remote host
<?php
/**
* Class LocalValetDriver
*
* This class demonstrates how we might go about proxying any missing local images to a remote host. i.e; the production
* site. This has been created with WordPress in mind but could be adjusted to work with any other system.
*/
class LocalValetDriver extends WordPressValetDriver {
@mishterk
mishterk / acf-field-group-php-to-json.php
Last active June 21, 2024 19:28
Convert an ACF Field Group from PHP to ACF-JSON
<?php
// Get all the local field groups and loop through them for processing.
$field_groups = acf_get_local_field_groups();
foreach ( $field_groups as $group ) {
// If the field group has fields, load them into the 'fields' key.
if ( acf_have_local_fields( $group['key'] ) ) {
$group['fields'] = acf_get_local_fields( $group['key'] );
}
@mishterk
mishterk / register-basic-wysiwyg-toolbar-for-acf.php
Last active April 19, 2024 02:08
Register custom WYSIWYG field toolbar options with Advanced Custom Fields for WordPress (ACF).
<?php
add_filter( 'acf/fields/wysiwyg/toolbars', function ( $toolbars ) {
$toolbars['Bare'] = [];
$toolbars['Bare'][1] = [ 'forecolor', 'link', 'strikethrough', 'bold', 'italic' ];
return $toolbars;
} );
@mishterk
mishterk / bypass-elementors-maintenance-mode.php
Last active April 4, 2024 13:29
Using this snippet, you can bypass Elementor's maintenance mode by adding ?bypass_maintenance=1 to the query string
<?php
add_filter( 'pre_option_elementor_maintenance_mode_mode', function ( $option ) {
$parameter = 'bypass_maintenance'; // change this to whatever you like
if ( isset( $_GET['bypass_maintenance'] ) and $_GET['bypass_maintenance'] ) {
return 0; // needs to be falsy but not FALSE
}
<?php
add_action( 'af/form/submission', function ( $form, $args ) {
// Append a custom value to the submission array
AF()->submission['some_extra_data'] = 'some value here';
}, 10, 2 );
<?php
$post_type = 'my_post_type';
// Register the columns.
add_filter( "manage_{$post_type}_posts_columns", function ( $defaults ) {
$defaults['custom-one'] = 'Custom One';
$defaults['custom-two'] = 'Custom Two';
@mishterk
mishterk / 0-readme.md
Last active December 10, 2023 21:39
This script replaces Breakdance's GSAP script URLs using a data URI scheme with a base64 encoded empty string which represents an empty JS file. This effectively removes Breakdance's copy of GSAP allowing third parties like Motion.page to load their version of it without conflict.

Disable Breakdance GSAP assets

This can be used to disable the GSAP scripts in Breakdance when something like Motion.page needs to be used instead. Motion.page and Breakdance both load the same scripts with different versions and this causes Motion.page's scrollTrigger feature to fail. I found this when using a Breakdance popup with animations on entry and exit.

This snippet comes with no support or guarantee so use at your own risk. If you do use it, feel free to comment below with any findings for others to consider.

Caveats

WooCommerce Snippets

Just a handy collection of small snippets for customising WooCommerce.

@mishterk
mishterk / define-google-maps-api-key-for-acf.php
Last active August 20, 2023 19:16
Register Google Maps API Key for ACF
<?php
// Define this in the site's wp-config.php file.
define('GOOGLE_API_KEY', 'your-google-api-key-here');
// Add this to your functions.php file, or a config plugin/MU plugin.
add_filter( 'acf/fields/google_map/api', function ( $api ) {
$api['key'] = GOOGLE_API_KEY;
return $api;
<?php
add_filter( 'acf/fields/wysiwyg/toolbars', function ( $toolbars ) {
// Register a basic toolbar with a single row of options
$toolbars['Custom One'][1] = [ 'bold', 'italic', 'underline', 'forecolor', 'link', 'unlink' ];
// Register another toolbar, this time with two rows of options.
$toolbars['Custom Two'][1] = [ 'bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'wp_adv' ];
$toolbars['Custom Two'][2] = [ 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright' ];