Skip to content

Instantly share code, notes, and snippets.

View BruceMcKinnon's full-sized avatar

BruceMcKinnon

View GitHub Profile
@BruceMcKinnon
BruceMcKinnon / functions.php
Created December 11, 2023 21:04
Ninja Forms Australian Phone number validation
//
// Hook the Ninja forms before submitting
//
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' );
//
// This function hooks the Ninja submission step
// Thanks to https://stackoverflow.com/questions/61440656/ninja-forms-server-side-validation-not-working
//
@BruceMcKinnon
BruceMcKinnon / functions.php
Created November 3, 2023 00:51
Add ACF CPT products on-the-fly to a Gravity Form
//
// Shop Order Form - Allow shop products to be added to the GF on the fly.
//
// Products are defined in an ACF CPT. These products may be purchased via a Gravity Form.
// The base form should have all fields required, except without products.
// The product fields will be added immediately above the Shipping field.
//
add_filter( 'gform_pre_render_7', 'populate_shop_products' );
add_filter( 'gform_pre_validation_7', 'populate_shop_products' );
@BruceMcKinnon
BruceMcKinnon / functions.php
Created November 3, 2023 00:00
Add menu order support to posts and pages
add_action( 'init', 'ingeni_add_posts_menuorder' );
function ingeni_add_posts_menuorder() {
add_post_type_support( 'post, page', 'page-attributes' );
add_post_type_support( 'page', 'excerpt' );
}
@BruceMcKinnon
BruceMcKinnon / functions.php
Last active October 19, 2023 00:50
Check if a file in the WP uploads folder actually does exist
// Take the URL of a local file in the WP Uploads folder and check that it does actually exist
function uploaded_file_exists( $url ) {
$local_exists = false;
if ( $url ) {
$uploads = wp_upload_dir();
$local_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
$local_exists = file_exists($local_path);
}
@BruceMcKinnon
BruceMcKinnon / functions.php
Created September 14, 2023 06:57
WP menu custom container
//
// Custom WP menu container - thanks to https://gist.github.com/nikolov-tmw/8698598
//
// Add a custom container to your
//
add_action( 'admin_head-nav-menus.php', 'custom_register_menu_metabox' );
function custom_register_menu_metabox() {
$custom_param = array( 0 => 'mega_col' );
@BruceMcKinnon
BruceMcKinnon / functions.php
Last active July 19, 2023 23:44
Create a custom Yoast SEO Variable
//
// Add a Custom Yoast Variable
//
add_action('wpseo_register_extra_replacements', 'add_yoast_supercharge_variables');
function add_yoast_supercharge_variables() {
if (function_exists ('wpseo_register_var_replacement')){
wpseo_register_var_replacement('%%BRAND%%', 'supercharge_yoast_brand', 'advanced', 'Supercharge Brand' );
}
}
@BruceMcKinnon
BruceMcKinnon / functions.php
Created July 7, 2023 00:20
Add GA to funnctions.php
add_action ( 'wp_head', 'rp_add_custom_js' );
function rp_add_custom_js() {
$ga_code = 'G-xxxxxxxx';
$script = "<!-- Google tag (gtag.js) -->
<script async src='https://www.googletagmanager.com/gtag/js?id=".$ga_code."'></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
@BruceMcKinnon
BruceMcKinnon / readme.txt
Created June 7, 2023 23:02
MacOS Office 365 - "Another account from your organisation is already signed in on this device"
URL:
https://answers.microsoft.com/en-us/officeinsider/forum/all/macos-another-account-from-your-organisation-is/53e99843-9069-4d54-a269-71d7112458a0?page=5
Answer:
Not sure if this has been listed here yet: https://learn.microsoft.com/en-us/office/troubleshoot/activation/another-account-already-signed-in
I had tried the Keychain steps as well as using office-reset tool. Completely uninstalling and restarting the machine etc. None of that worked.
@BruceMcKinnon
BruceMcKinnon / cal.js
Created May 26, 2023 00:42
FullCalendar change view responsively
/*
Uses https://fullcalendar.io/
calendar_events is a multidim array of event info. Eg:
[{
title: 'My Event 1',
url: 'https://myevent_1.booking.page',
start: '2023-05-28T21:30:00'
},
@BruceMcKinnon
BruceMcKinnon / file.js
Created May 25, 2023 01:30
JS - Convert multi-dim array that has been JSON.stringify to a string back to a JS multidim array
//
// Take a string like '{"title":"An event","start":"2023-05-01"},{"title":"Another event","start":"2023-05-15"},{"title":"Yet another event","start":"2023-05-24"}'
// and convert it back into a multidim array
var string_vers = JSON.stringify(original_array);
var reconstructed = reconstruct_multi_dim( string_vers );
console.log( JSON.stringify(reconstructed) );