Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Kurth mishterk

View GitHub Profile
@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 / _markup.html
Created May 20, 2020
Delegate jQuery event handlers when working with dynamic content. For more info see https://philkurth.com.au/tips/delegate-jquery-event-handlers-when-working-with-dynamic-content/
View _markup.html
<div class="PostsGrid">
<!-- This is our div containing our post items -->
<div class="PostsGrid__posts">
<a href="#" class="PostsGrid__post"><!-- …Post grid item here… --></a>
<a href="#" class="PostsGrid__post"><!-- …Post grid item here… --></a>
<a href="#" class="PostsGrid__post"><!-- …Post grid item here… --></a>
</div>
<!-- A button to load more posts -->
@mishterk
mishterk / responsive-oembeds-class-for-wp.php
Created Jan 9, 2020
Wraps oEmbed output in markup which we can then target with CSS for fluid responsiveness.
View responsive-oembeds-class-for-wp.php
<?php
class ResponsiveOEmbeds {
/**
* Regex patterns for matching specific embeddable URLs
*
* @var array
*/
@mishterk
mishterk / acfcdt-how-to-activate-support-for-custom-field-type.php
Last active Jan 7, 2020
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/.
View acfcdt-how-to-activate-support-for-custom-field-type.php
<?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;
}
View advanced-forms-pro-calculated-field-update-intercept.js
// 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 ) {
// …
});
View unset-woocommerce-order-actions.php
<?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'] );
View class-make-release-command.php
<?php
namespace WpLandingKitPlugin;
use WP_CLI;
use WP_CLI_Command;
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 acf-load-field-options-example.php
<?php
add_filter( 'acf/load_field/name=countries', function ( $field ) {
$field['choices'] = [
'au' => 'Australia',
'nz' => 'New Zealand',
'gb' => 'United Kingdom',
'us' => 'United States',
// …
View php-alternative-syntax-example.php
<?php
get_header();
?>
<div class="Main">
<?php if ( have_posts() ): ?>
<?php while ( have_posts() ): ?>
<?php the_post(); ?>
You can’t perform that action at this time.