Skip to content

Instantly share code, notes, and snippets.

@mishterk
mishterk / acfcdt-how-to-activate-support-for-custom-field-type.php
Last active January 7, 2020 21:23
How to activate support for a custom field type when using the ACF Custom Database Tables plugin. For more information, see https://support.hookturn.io.test/acf-custom-database-tables/doc/how-to-activate-support-for-a-custom-field-type/.
<?php
// This will register a custom field type as supported by the plugin.
// This affects table definition generation and can go in your functions.php
// file or a plugin.
add_filter( 'acfcdt/is_supported_field', function ( $is_supported, $field ) {
if ( $field['type'] === 'custom_acf_field_type' ) {
$is_supported = true;
}
@mishterk
mishterk / advanced-forms-pro-calculated-field-update-intercept.js
Last active December 27, 2019 06:38
Calculated field enhancements in Advanced Forms Pro version 1.6.6. For more info see https://hookturn.io/2019/11/advanced-forms-pro-calculated-field-enhancements/
// This will intercept the rendered calculated field and insert the markup
// into an element with the id `#preview-container`
acf.addAction( 'af/field/calculated/value_updated', function( value, field, form ) {
$('#preview-container').html(value);
});
// You may intercept the return values of specific fields by field name
acf.addAction( 'af/field/calculated/value_updated/name=FIELD_NAME', function( value, field, form ) {
// …
});
<?php
add_filter( 'woocommerce_order_actions', function ( $actions ) {
// Unset whatever actions you don't need available in the
// WooCommerce order edit screen.
unset( $actions['send_order_details_admin'] );
unset( $actions['send_order_details'] );
unset( $actions['regenerate_download_permissions'] );
@mishterk
mishterk / class-make-release-command.php
Last active July 1, 2020 11:19
Use a WP CLI command to prepare your plugins for release. For more info see https://philkurth.com.au/tips/use-a-wp-cli-command-to-prepare-your-plugins-for-release/
<?php
namespace WpLandingKitPlugin;
use WP_CLI;
use WP_CLI_Command;
@mishterk
mishterk / filter-acf-relationship-field-post-titles.php
Last active September 18, 2022 23:16
How to show the age of each post in an ACF relationship field. For more info see https://philkurth.com.au/tips/customise-the-post-titles-in-acf-relationship-field/
<?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 );
<?php
add_filter( 'acf/load_field/name=countries', function ( $field ) {
$field['choices'] = [
'au' => 'Australia',
'nz' => 'New Zealand',
'gb' => 'United Kingdom',
'us' => 'United States',
// …
<?php
get_header();
?>
<div class="Main">
<?php if ( have_posts() ): ?>
<?php while ( have_posts() ): ?>
<?php the_post(); ?>
@mishterk
mishterk / dump-all-defined-variables-formatted.php
Created October 25, 2019 09:08
Dump defined variables for a quick look at what's available in the current context. For more info see https://philkurth.com.au/tips/dump-defined-variables-for-a-quick-look-at-what's-available-in-the-current-context/
<?php
echo '<pre>';
var_dump(get_defined_vars());
echo '</pre>;
@mishterk
mishterk / limit-login-attempts-unblock-all.sql
Last active October 24, 2019 07:33
How to clear lockouts from the awesome Limit Login Attempts plugin via SQL. For more info see https://philkurth.com.au/articles/how-to-clear-lockouts-from-the-awesome-limit-login-attempts-plugin-via-sql/
UPDATE wp_options SET option_value = '' WHERE option_name = 'limit_login_lockouts' LIMIT 1;
@mishterk
mishterk / class-view.php
Last active May 14, 2021 06:28
Using generic views inside WordPress for a more flexible UI system. For more info see https://philkurth.com.au/articles/use-generic-views-with-data-arrays-for-a-flexible-context-independent-ui-system/
<?php
class View {
public static $view_dir = '';
/**
* Render View Template With Data