Skip to content

Instantly share code, notes, and snippets.

@mishterk
mishterk / acf-export-group_63799935b6476.json
Last active Nov 30, 2022
Testing multiple calculated fields in Advanced Forms Pro for ACF. These resources are for the video: https://www.loom.com/share/fcf6179162374c599b61eb6a1040eb02
View acf-export-group_63799935b6476.json
[
{
"key": "group_63799935b6476",
"title": "Calculated Fields",
"fields": [
{
"key": "field_637999367d114",
"label": "Number 1",
"name": "number_1",
"aria-label": "",
@mishterk
mishterk / count-new-members-between-two-dates.sql
Last active Oct 9, 2022
Helpful SQL queries for working with the MemberPress WordPress plugin
View count-new-members-between-two-dates.sql
SELECT count(DISTINCT txns.user_id)
FROM (
SELECT
user_id,
min(created_at) AS first_txn_created_at
FROM wp_mepr_transactions
WHERE status IN ('complete', 'confirmed')
GROUP BY user_id
) AS first_txns
INNER JOIN wp_mepr_transactions AS txns
View filter-acf-relationship-field-post-titles.php
<?php
add_filter( 'acf/fields/relationship/result/name=related_posts', function ( $title, WP_Post $post, $field_arr ) {
$posted_at = get_post_time( 'U', false, $post->ID );
$now = current_time( 'timestamp' );
$diff = human_time_diff( $posted_at, $now );
return $title . sprintf( ' (%s ago)', $diff );
}, 10, 3 );
View 0-woocommerce-snippets.md

WooCommerce Snippets

Just a handy collection of small snippets for customising WooCommerce.

@mishterk
mishterk / acf-field-group-php-to-json.php
Last active Aug 29, 2022
Convert an ACF Field Group from PHP to ACF-JSON
View acf-field-group-php-to-json.php
<?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 / load-images-from-production.php
Last active Jul 14, 2022
WordPress plugin for loading images from production on a staging/development website. See https://hookturn.io/load-media-images-from-production-wordpress-plugin/
View load-images-from-production.php
<?php
/**
* Plugin Name: Load Images From Production (for staging/dev)
* Description: Hooks into WP's media URL generation and replaces the domain with the production domain.
* Author: Phil Kurth
* Author URI: https://hookturn.io
*/
// If this file is called directly, abort.
defined( 'WPINC' ) or die();
@mishterk
mishterk / replace-images-with-kittens.php
Last active Jul 14, 2022
Replace all attachment images with kitten placeholders...
View replace-images-with-kittens.php
<?php
add_filter( 'wp_get_attachment_image_src', function ( $image ) {
$image[0] = "https://placekitten.com/$image[1]/$image[2]";
return $image;
}, 10 );
@mishterk
mishterk / LocalValetDriver.php
Last active Jul 14, 2022
A local Valet driver for proxying images to a remote host
View LocalValetDriver.php
<?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 {
View register-custom-admin-columns.php
<?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';
View how-to-update-acf-google-map-field.php
<?php
// The field accepts a value with this structure
$value = [
'address' => '123 Example St, Townsville XYZ 1234, Country',
'lat' => - 38.1486228,
'lng' => 144.360414,
'zoom' => 14,
'place_id' => 'Ei0xMjMgTW9vcmFib29sIFN0LCBHZWVsb25nIFZJQyAzMjIwLCBBdXN0cmFsaWEiMBIuChQKEgmX0JaIHBTUahFyH_LC9sYD8hB7KhQKEglDz-DYDxTUahECZY8QisCjzg',
'street_number' => 123,