Skip to content

Instantly share code, notes, and snippets.

View BruceMcKinnon's full-sized avatar

BruceMcKinnon

View GitHub Profile
@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) );
@BruceMcKinnon
BruceMcKinnon / functions.php
Last active May 8, 2023 02:56
Filter the Wordpress srcset to ensure the browser isn't given an image it needs to upscale.
//
// Filter the WP srcset to ensure the browser isn't given a file it needs to upscale.
//
add_filter( 'wp_calculate_image_srcset_meta','ingeni_srcset_filter', 4, 10);
function ingeni_srcset_filter($image_meta, $size_array, string $image_src, int $attachment_id ) {
// We'll allow images within 2% of the required width or height.
$min_width = ($size_array[0] * 0.98);
$min_height = ($size_array[1] * 0.98);
@BruceMcKinnon
BruceMcKinnon / functions.php
Created March 8, 2023 22:03
Force WP auto-updating UI for plugins and themes
// Add these settings to force WP to display the 'Enable auto-update' options for plugins and themes.
// Thanks to https://wordpress.org/support/topic/automatic-updates-not-visible-in-plugins-screen-options-or-dashboard/
//
// Enable plugins auto-update UI elements.
add_filter( 'plugins_auto_update_enabled', '__return_true' );
//
// Enable themes auto-update UI elements.
add_filter( 'themes_auto_update_enabled', '__return_true' );
@BruceMcKinnon
BruceMcKinnon / functions.php
Created January 31, 2023 22:33
SJB Attach resumes to Admin & HR emails
// Get the uploaded resume and return it's path to the email handler
function ingeni_sjb_get_attachment( $resume_path, $post_id ) {
// Get the resume_path assigned to that postID
// https://www.presstigers.com/how-can-simple-job-board-settings-help-you/
global $wpdb;
$resume_path = '';
$fileAttachment = get_post_meta($post_id, 'resume', TRUE);
$path_start = stripos( $fileAttachment, '/uploads/' );
if ($path_start) {
@BruceMcKinnon
BruceMcKinnon / cmd
Created October 25, 2022 21:43
GIT hangs at the end of a PUSH
Your git push command is stalling at the end of the process:
Delta compression using up to 8 threads
Compressing objects: 100% (1312/1312), done.
POST git-receive-pack (chunked))
Writing objects: 100% (1320/1320), 352.71 MiB | 3.71 MiB/s, done.
Total 1320 (delta 550), reused 1 (delta 0), pack-reused 0
After the 'Total' line, the push command seems to stall.
@BruceMcKinnon
BruceMcKinnon / functions.php
Created October 24, 2022 23:43
Block high-resolution JPGs being uploaded to the Wordpress Media Library
//
// Block high-res JPGs (e.g., direct photos direct from the camera) being uploaded to the Wordpress Media Library
//
// Add this to the themes functions.php file - If an image is a JPG larger than 500kb then we block it but also alert the
// user if the image is higher than 96dpi.
// The file may be uploaded regardless if the file size is smaller than 500kb.
//
function ingeni_media_library_upload_filter( $file ) {
$is_allowed = true;
@BruceMcKinnon
BruceMcKinnon / style.css
Created August 19, 2022 01:28
Fixed attachment background images on iOS
/* Detect touch devices and disable fixed attchment for background images */
@media (hover: none) {
background-attachment: scroll;
}