Skip to content

Instantly share code, notes, and snippets.

View adamcrampton's full-sized avatar
💪
Crushing it

Adam Crampton adamcrampton

💪
Crushing it
  • Sydney, Australia
View GitHub Profile
@adamcrampton
adamcrampton / acf_fields_post_table.md
Last active July 2, 2019 22:49 — forked from PurpleBooth/README-Template.md
ACF field values for WordPress wp_posts table

Manual Insertion of ACF Fields Into The WordPress Database

To add ACF fields to the WordPress database (e.g. when using a seeder), you need to add each ACF field as a row into the wp_posts table using the post_type value of acf-field.

This guide assumes that you have defined the fields with PHP and are seeding posts directly into the WordPress database.

Note: You can also create ACF Groups in a similar way using acf-field-group post_type. I will cover this in a separate gist.

Getting Started

Note: The only practical use case for this is a database seeder (e.g. for demo data) - any other interaction with ACF and the WordPress database should really be done via the plugin itself.

@adamcrampton
adamcrampton / wpAdminWidgetImageUploader.js
Last active May 3, 2019 01:10
WordPress - JS for uploading images to widget
/**
* Steps:
* 1. Pop this into your theme's assets/js directory, set the filename as widgets.js (or add JS to existing widgets.js)
* 2. See the other gist for widget PHP instructions if you haven't already
* 3. Profit++
*/
// ============================================
// Custom JavaScript used in Widgets (WP Admin)
// ============================================
// Image uploader
@adamcrampton
adamcrampton / sidebarBanner.php
Created May 3, 2019 00:55
WordPress widget - linked image for sidebar
<?php
/**
* Steps:
* 1. Pop this in your theme's functions.php file
* 2. See the other gist for JS instructions
* 3. Profit
*/
// Register widget area.
function sidebar_widgets_init() {
@adamcrampton
adamcrampton / lambdaApiBoilerplate.js
Created April 23, 2019 04:37
Boilerplate for Lambda function envoked from AWS API Gatewat
'use strict';
console.log('Getting JSON...');
exports.handler = async (event) => {
let templateId = 1;
let responseCode = 200;
console.log('request:' + JSON.stringify(event));
if (event.queryStringParameters && event.queryStringParameters.templateId) {
@adamcrampton
adamcrampton / laravel
Created April 9, 2019 23:56
Nginx - sites-available Laravel 5.x vhost example file - Ubuntu 18.04 + PHP 7.2
server {
listen 80;
listen [::]:80 ipv6only=on;
# Log files for Debugging
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;
# Webroot Directory for Laravel project
root /var/www/laravel/public;
@adamcrampton
adamcrampton / default
Created April 9, 2019 23:54
Nginx - sites-available default file - Ubuntu 18.04 + PHP 7.2
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
@adamcrampton
adamcrampton / trimArrayKeys.php
Created April 9, 2019 01:24
Trims array keys specified in another array
function trimArrayKeys($originalArray) {
$strip_keys = ['banned_key'];
return array_diff_key($originalArray, array_flip($strip_keys));
}
@adamcrampton
adamcrampton / dd.php
Created April 9, 2019 01:20 — forked from james2doyle/dd.php
A implementation of "dump and die" (dd) for WordPress
<?php
if (!function_exists('dd')) {
function dd($data)
{
ini_set("highlight.comment", "#969896; font-style: italic");
ini_set("highlight.default", "#FFFFFF");
ini_set("highlight.html", "#D16568");
ini_set("highlight.keyword", "#7FA3BC; font-weight: bold");
ini_set("highlight.string", "#F2C47E");
@adamcrampton
adamcrampton / getAllPostMeta.php
Created April 8, 2019 06:21
WordPress - Return all post meta values in flat array
<?php
// Return all meta for a single post in a flat array.
function get_all_post_meta($post_id) {
// Get all the meta values.
$meta = get_post_meta($post_id, '');
// We only need the first item - return a flat array.
return array_map(function($item) {
return $item[0];
}, $meta);
@adamcrampton
adamcrampton / cookieMatch.js
Created April 1, 2019 05:15
For use with GTM variable - checks for existence and value of cookie - returns null if not found
// Return either the value of the Adobe Audience Manage cookie or null
// Note the AAM cookie is set by a Cloudflare worker at the edge
function() {
return (document.cookie.match(/^(?:.*;)?\s*aam\s*=\s*([^;]+)(?:.*)?$/)||[,null])[1]
}