Skip to content

Instantly share code, notes, and snippets.

Phil Kurth mishterk

Block or report user

Report or block mishterk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mishterk
mishterk / Dump.php
Created Oct 19, 2019
A simple static class for dumping information to a log file of your choosing. For more info, see https://philkurth.com.au/tips/a-php-class-for-dumping-data-to-a-separate-log-file/
View Dump.php
<?php
/**
* Class Dump
* A simple static class for dumping data to a separate log file to aid debugging and development.
*
* @author Phil Kurth <phil@philkurth.com.au>
*/
class Dump {
View mark-wordpress-scripts-as-async-or-defer.php
<?php
add_action( 'wp_enqueue_scripts', function () {
wp_register_script( 'my-script', get_stylesheet_directory_uri() . '/assets/js/my-script.js' );
wp_enqueue_script( 'my-script' );
} );
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
@mishterk
mishterk / aliased-one-liner-to-update-everything-in-wordpress.sh
Last active Oct 16, 2019
Simplify WordPress updates by bundling them by using WP CLI and running them all from the one 'command'. For more info see https://philkurth.com.au/tips/simplify-wordpress-updates-using-these-sequential-wp-cli-commands/
View aliased-one-liner-to-update-everything-in-wordpress.sh
alias wp-update-all="wp plugin update --all && wp language plugin update --all && wp theme update --all && wp language theme update --all && wp core update --force && wp language core update"
View define-custom-colour-palette-for-gutenberg.php
<?php
add_action( 'after_setup_theme', function () {
add_theme_support( 'editor-color-palette', [
[
'name' => 'Purple',
'slug' => 'purple',
'color' => '#2B265C'
],
View customising-acf-colour-picker-field-pallet.php
<?php
add_action( 'admin_footer', function () {
?>
<script>
if (window.acf) {
acf.addFilter('color_picker_args', function (args, $field) {
args.palettes = [
'#E6D8D5',
@mishterk
mishterk / custom-wordpress-menu-items-template.php
Last active Oct 12, 2019
How to render WordPress menu items without a custom walker
View custom-wordpress-menu-items-template.php
<?php $menu_location = 'some_menu_location'; ?>
<?php if ( has_nav_menu( $menu_location ) ): ?>
<?php $menu_items = wp_get_nav_menu_items( wp_get_nav_menu_name( $menu_location ) ); ?>
<?php foreach ( $menu_items as $menu_item ): ?>
<a href="<?= esc_url( $menu_item->url ) ?>"
target="<?= esc_attr( $menu_item->target ?: '_self' ) ?>"
View register-custom-acf-wysiwyg-field-toolbars.php
<?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' ];
View add-all-sub-directories-as-acf-json-load-points.php
<?php
add_filter( 'acf/settings/load_json', function ( array $directories ) {
$base_dir = get_stylesheet_directory() . '/components';
$resource = opendir( $base_dir );
while ( ( $file = readdir( $resource ) ) !== false ) {
// Skip current and parent directory references
@mishterk
mishterk / customise-advanced-forms-mail-payload.php
Created Oct 4, 2019
Intercept and modify the payload sent by Advanced Forms
View customise-advanced-forms-mail-payload.php
<?php
// Set the form key you wish to target
$form_key = 'form_5d97cf9edc0a8';
add_action( "af/email/before_send/key=$form_key", function ( $email, $form ) {
add_filter( 'wp_mail', function ( $data ) use ( $email ) {
// you can override any items in this array to customise the email that is sent...
View override-wp-post-context-function-usage-example.php
<?php
/*
* This is a rather simple and contrived example but it illustrates how this
* function can be used to temporarily change the post context.
*/
$alt_post_content = override_post_context( 1234, function ( $post ) {
ob_start();
// Do whatever you need here. The $post variable, in this scope, is the
You can’t perform that action at this time.