Skip to content

Instantly share code, notes, and snippets.

View BruceMcKinnon's full-sized avatar

BruceMcKinnon

View GitHub Profile
add_filter( 'gform_field_validation', 'check_mailchimp_status', 10, 4 );
function check_mailchimp_status ( $result, $value, $form, $field ) {
$target_form = 10;
if ( ($field->formId == $target_form) && ($field->id == 1) ) {
if ( $field->type == 'email' && $result['is_valid'] && class_exists( 'GF_MailChimp_API' ) ) {
fb_log( 'gform_field_validation: running.' );
$api_key = gf_mailchimp()->get_plugin_setting( 'apiKey' );
@BruceMcKinnon
BruceMcKinnon / form.json
Created October 28, 2019 03:37
Check MC user status via GF
{"0":{"title":"Download Form","description":"","labelPlacement":"top_label","descriptionPlacement":"below","button":{"type":"text","text":"Submit","imageUrl":""},"fields":[{"type":"email","id":1,"label":"Email","adminLabel":"","isRequired":true,"size":"medium","errorMessage":"","visibility":"visible","inputs":null,"formId":5,"description":"","allowsPrepopulate":false,"inputMask":false,"inputMaskValue":"","inputMaskIsCustom":false,"maxLength":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"Your email","cssClass":"","inputName":"","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","productField":"","emailConfirmEnabled":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"fields":"","displayOnly":""}],"version":"2.4.14","id":5,"nextFieldId":3,"useCurrentUserAsAuthor":true,"postContentTemplateEnabled"
@BruceMcKinnon
BruceMcKinnon / functions.php
Created September 25, 2019 01:03
Add categories and tags to pages
function add_cats_tags_to_pages() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'add_cats_tags_to_pages' );
@BruceMcKinnon
BruceMcKinnon / functions.php
Created August 13, 2019 03:46
Display media images by category in a grid
add_shortcode('get-image-grid','get_images_by_category');
function get_images_by_category( $atts ) {
$retHtml = '';
$attribs = shortcode_atts( array(
'cat_slug' => "",
'link_to_file' => true,
'mime_type' => "image",
'class' => "cell small-6 medium-3",
@BruceMcKinnon
BruceMcKinnon / functions.php
Created May 7, 2019 05:44
Content Block Featured Image
// Add the ability to display the content block in a reqular post using a shortcode
function custom_post_image_shortcode( $atts ) {
$params = shortcode_atts( array(
'id' => '',
'slug' => '',
'class' => 'content_block_image',
'suppress_content_filters' => 'no'
), $atts );
@BruceMcKinnon
BruceMcKinnon / test.html
Last active May 2, 2019 00:53
Toggle HTML 5 video play/pause
<div class="home-video-wrap" >
<video id="home-video" autoplay mute preload loop data-origin-x="0" data-origin-y="0" poster="<?php echo( get_stylesheet_directory_uri() ); ?>/dist/assets/images/home-hero-3000.jpg">
<source src="<?php echo( get_stylesheet_directory_uri() ); ?>/dist/assets/images/TrevHomeHero.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
@BruceMcKinnon
BruceMcKinnon / gist:c7440fee026f78cfefb50f76f8f8ebdf
Last active August 26, 2023 23:46
Add MenuOrder for postd
// Add menu order to the Posts edit screen
add_action( 'init', 'ingeni_add_posts_menuorder' );
function ingeni_add_posts_menuorder()
{
add_post_type_support( 'post', 'page-attributes' );
}
// Reorder the loop sorting fro the the 'projects' category
function ingeni_change_category_order( $query ) {
if ( $query->is_category('projects') && $query->is_main_query() ) {
@BruceMcKinnon
BruceMcKinnon / functions.php
Created January 8, 2019 23:48
Woocommerce Repleace Read More with Out of Stock
//
// WooCommerce - replace read more buttons for out of stock items
//
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart() {
global $product;
if ( !$product->is_in_stock() ) {
echo '<a href="'.get_permalink().'" rel="nofollow" class="outofstock button">Out of Stock</a>';
} else {
woocommerce_get_template('loop/add-to-cart.php');
@BruceMcKinnon
BruceMcKinnon / functions.php
Last active September 9, 2022 03:54
Gravity Forms Australian phone number validation mask
add_filter( 'gform_phone_formats', 'au_phone_format' );
function au_phone_format( $phone_formats ) {
$phone_formats['au'] = array(
'label' => 'Australia',
'mask' => '99 9999 9999',
'regex' => '/^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/',
'instruction' => 'Australian phone numbers.',
);
return $phone_formats;
@BruceMcKinnon
BruceMcKinnon / gist:5fcd3139d8444c55b3c880a5ea05435e
Created November 14, 2018 22:13
Foundation Larger Table Breakpoints
//
//
// Custom breakpoint for larger tablets
//
//
$breakpoints: (
small: 0,
medium: 640px,
tablet: 860px,