Skip to content

Instantly share code, notes, and snippets.

Avatar

Rheinard Korf rheinardkorf

View GitHub Profile
View acf-hooks-basic.php
<?php
/**
* Hook before acf_get_value() queries the DB.
*/
add_filter(
'acf/pre_load_value',
function( $meta, $object_id, $field ) {
// Initiate the ACF 'values' store.
@rheinardkorf
rheinardkorf / acf-hooks.php
Last active Oct 1, 2021
Out of the box ACF is taxing on your site performance, but also CPU load if you have large sites (think 10k+ posts). There are ways to improve ACF by doing things like batch writes or pre-fetching values into the ACF Store. As I create some of these techniques I will add them to this Gist. This will work okay'ish without an object cache, but its…
View acf-hooks.php
<?php
/**
* This file contains some hooks to improve ACF performance.
*
* @package rheinardkorf
*/
add_filter(
'acf/pre_load_value',
function( $meta, $post_id, $field ) {
@rheinardkorf
rheinardkorf / queries.mysql
Created Dec 7, 2020
Useful SQL queries for dealing with WordPress optimizations.
View queries.mysql
# Get a particular option entry.
SELECT * FROM wp_options WHERE option_name="<OPTION_NAME>" LIMIT 1000;
# Make sure an option to not autoloaded.
UPDATE wp_options SET autoload = 'no' WHERE option_name="<OPTION_NAME>";
# Get the size of total autoladed values.
SELECT SUM(LENGTH(option_value)) as autoload_size FROM wp_options WHERE autoload='yes';
# Get the top 10 most "expensive" autoloaded values.
@rheinardkorf
rheinardkorf / cache-example.php
Last active Dec 7, 2020
Example using WP caching.
View cache-example.php
<?php
// This example assumes an object cache is available. If its not, transients WITHOUT EXPIRATION will be used.
$cache_key = 'unique_prefix_' . md5( $variables );
$results = wp_cache_get( $cache_key );
if ( false === $results ) {
$results = $wpdb->get_var( $wpdb->prepare("SQL STATEMENT HERE", $variables['here'], $variables['etc'] ));
wp_cache_set( $cache_key, $results );
}
@rheinardkorf
rheinardkorf / .mermaidrc
Last active Sep 22, 2020
Alternate Remark-Mermaid Plugin
View .mermaidrc
{
"sequence":{
"diagramMarginY" :10,
"diagramMarginX" :50,
"actorMargin" :50,
"width" :150,
"height" :65,
"boxMargin" :10,
"boxTextMargin" :5,
"noteMargin" :10,
@rheinardkorf
rheinardkorf / .gitignore
Created Aug 13, 2020
A .gitignore for use on WP Engine. Slight tweaks to the official one: https://wpengine.com/wp-content/uploads/2020/02/recommended-gitignore-no-wp.txt
View .gitignore
*~
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
# wordpress specific
wp-config.php
@rheinardkorf
rheinardkorf / .gitignore
Last active Jul 27, 2020
Some GatsbyJS workspace stuff.
View .gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
@rheinardkorf
rheinardkorf / mode-switch-plugin.js
Created Jun 3, 2020
Gutenberg manipulate Editor Mode state. (Experimental)
View mode-switch-plugin.js
(function (wp) {
var registerPlugin = wp.plugins.registerPlugin;
var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem;
// var image = wp.icons.image;
var el = wp.element.createElement;
var withDispatch = wp.data.withDispatch;
var MoreItem = function (props) {
return el(PluginMoreMenuItem,
@rheinardkorf
rheinardkorf / gatsby-node.js
Last active Aug 27, 2019
Use parent's resolver using custom field extension. FTW!!
View gatsby-node.js
exports.createSchemaCustomization = ({ actions }) => {
const { createFieldExtension, createTypes } = actions;
createFieldExtension({
name: `parent`,
description: `Proxy resolver from a parent's field.`,
args: {
from: `String!`
},
View amplify_auth_gatsby_config.md

First attempt...

Inside gatsby-browser.js

import Amplify, { Auth } from 'aws-amplify';
import awsconfig from './src/aws-exports'
Amplify.configure(awsconfig);