Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Kurth mishterk

View GitHub Profile
@mishterk
mishterk / register-basic-wysiwyg-toolbar-for-acf.php
Last active Aug 11, 2020
Register custom WYSIWYG field toolbar options with Advanced Custom Fields for WordPress (ACF).
View register-basic-wysiwyg-toolbar-for-acf.php
<?php
add_filter( 'acf/fields/wysiwyg/toolbars', function ( $toolbars ) {
$toolbars['Bare'] = [];
$toolbars['Bare'][1] = [ 'forecolor', 'link', 'strikethrough', 'bold', 'italic' ];
return $toolbars;
} );
View class-view.php
<?php
class View {
public static $view_dir = '';
/**
* Render View Template With Data
@mishterk
mishterk / filter-repeater-sub-fields-before-insert-into-custom-database-tables.php
Last active Aug 4, 2020
How to filter repeater sub field values before they are stored in a custom table in ACF Custom Database Tables version 1.1
View filter-repeater-sub-fields-before-insert-into-custom-database-tables.php
<?php
add_filter( 'acfcdt/filter_value_before_update', 'xyz_filter_repeater_value_before_insert', 10, 3 );
/**
* @param mixed $value The field value being stored.
* @param string $selector Either the post ID or a compound ACF selector depending on the object type. e.g; user_1.
* @param array $field_array The ACF field array.
*
* @return mixed
@mishterk
mishterk / class-disable-comments.php
Last active Jul 1, 2020
A static class that basically removes all (I think) comment related functionality in WordPress
View class-disable-comments.php
<?php
namespace PhilKurth\WP\Tools;
@mishterk
mishterk / post-revision-meta.sql
Last active Jul 1, 2020
Useful SQL snippets for WordPress DB analysis
View post-revision-meta.sql
# Lists revision post IDs and their meta data count in descending order
SELECT post_id, count(*) AS count FROM wp_postmeta LEFT JOIN wp_posts ON post_id = ID WHERE post_type = 'revision' GROUP BY post_id ORDER BY count DESC;
# Tells you how many (total figure) meta rows belong to revision posts
SELECT count(*) as total_revision_meta FROM wp_postmeta INNER JOIN wp_posts ON post_id = ID WHERE post_type = 'revision';
# Lists the post_id number of revisions for posts in descending order by number of revisions
SELECT post_parent as post_id, count(*) AS n_revisions FROM wp_posts WHERE post_type = 'revision' GROUP BY post_parent ORDER BY n_revisions DESC;
View BenchMarker.php
<?php
/**
* Class BenchMarker
* @author Phil Kurth <phil@philkurth.com.au>
*
* A simple benchmarking utility. Easiest way to use this:
*
* BenchMarker::start();
*
* … run stuff here …
@mishterk
mishterk / CustomOrderEmail.php
Last active Jul 1, 2020
Registering custom emails for WooCommerce
View CustomOrderEmail.php
<?php
class CustomOrderEmail extends \WC_Email {
// This is a just a simple example. See \WC_Email and child classes for more examples
public function __construct() {
$this->id = 'custom_order_email';
$this->title = 'Custom Order Email';
@mishterk
mishterk / custom-wordpress-menu-items-template.php
Last active Jul 1, 2020
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' ) ?>"
@mishterk
mishterk / 0-readme.md
Last active Jul 1, 2020
A basic example for querying data from custom tables created using ACF Custom Database Tables. For more info see https://hookturn.io/2019/09/how-to-use-acf-custom-database-tables-data-with-wp_query-objects/
View 0-readme.md

How to use your custom table data with WP_Object queries

This example illustrates how to query an array of post IDs from a custom DB table then use the array in a WP_Query.

This can be much faster than using meta queries on a WP_Query object, particularly if you are matching multiple fields.

View automatically-version-wordpress-assets-using-filemtime.php
<?php
add_action( 'wp_enqueue_scripts', function () {
$uri = get_stylesheet_directory_uri();
$dir = get_stylesheet_directory();
$script_last_updated_at = filemtime( "$dir/scripts/my-script.js" );
$style_last_updated_at = filemtime( "$dir/styles/my-style.css" );
You can’t perform that action at this time.