Skip to content

Instantly share code, notes, and snippets.

@mishterk
mishterk / example-table-definition-for-page-post-type.json
Created February 20, 2018 19:00
ACF Custom Database Tables plugin: Table definition JSON example for post type of 'page'
{
"name": "page_metadata",
"relationship": "page",
"columns": [
"show_page_banner",
"page_layout",
"read_time"
]
}
@mishterk
mishterk / example-table-definition-for-user-type.json
Created February 20, 2018 19:04
ACF Custom Database Tables plugin: Table definition JSON example for user type
{
"name": "user_metadata",
"relationship": "user",
"columns": [
"profession",
"age",
"sex",
"is_member",
"instagram_url"
]
@mishterk
mishterk / example-bypassing-core-tables.php
Last active February 20, 2018 19:19
ACF Custom Database Tables plugin: Bypassing core meta tables example.
<?php
/*
* This will prevent data from being stored in WordPress' core meta tables where a custom database table has been set up instead.
* This will not affect meta data that does not have a custom database table – that meta data will be stored as usual.
*/
add_filter('acfcdt/settings/bypass_post_meta_table', '__return_true');
@mishterk
mishterk / example-table-definition-structure.json
Last active May 27, 2018 04:18
ACF Custom Database Tables plugin: Table definition JSON structure
{
"name": "{custom_database_table_name}",
"relationship": "{post_type}",
"columns": [
"{acf_field_name_1}",
"{acf_field_name_1}",
"{acf_field_name_3}"
]
}
@mishterk
mishterk / 0-readme.md
Last active April 14, 2019 23:48
A basic, static view handler for WordPress

Basic Usage

// set up
View::$view_dir = '/some/path';

// echos the view
View::render('relative/template', [
  'var1' => 'data',
 'var2' =&gt; 'more data'
<?php
/**
* Really simple GET request
*/
add_action( 'rest_api_init', function ( WP_REST_Server $wp_rest_server ) {
register_rest_route( '/custom-namespace/v1', '/no-param', [
'methods' => 'GET',
'callback' => function ( WP_REST_Request $request ) {
if ( $throw_error = false ) {
@mishterk
mishterk / ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass.php
Last active September 11, 2019 02:43
A hotfixed solution for bypassing custom database tables when using ACF's get_field() function. This will ONLY work with 1.0.x versions of the plugin. Version 1.1 will include built-in support for this capability.
<?php
use ACFCustomDatabaseTables\Intercept\ACFGetFieldIntercept;
use ACFCustomDatabaseTables\Vendor\Pimple\Container;
/**
* Class ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass
*
* This provides a 'hotfixed' approach for disabling custom database table intercept when using ACF's get_field()
* function. This will only work with version 1.0.x versions of the plugin as a built-in tool will be available in
.m-0-first-last > :first-child {
margin-top: 0;
}
.m-0-first-last > :last-child {
margin-bottom: 0;
}
@mishterk
mishterk / get-acf-sub-field-key-by-field-name-function.php
Last active October 1, 2019 22:27
A function for determining an ACF field's sub field key based on a field name. For more info see https://philkurth.com.au/tips/get-an-acf-sub-field-key-by-field-name/
<?php
/**
* Locates an ACF sub-field by field name and returns the sub-field's key.
*
* This is particularly useful if you need to construct a data array for programmatic field
* update where a complex field is in use (e.g; repeater, group, flexi).
*
* @param string $sub_field_name The sub field name we need a key for.
* @param array $field The ACF field array.
@mishterk
mishterk / customise-advanced-forms-mail-payload.php
Created October 4, 2019 23:48
Intercept and modify the payload sent by Advanced Forms
<?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...