Skip to content

Instantly share code, notes, and snippets.

Avatar

Rheinard Korf rheinardkorf

View GitHub Profile
@rheinardkorf
rheinardkorf / theme.css
Last active March 15, 2023 02:57
Test Marp Markdown theme.
View theme.css
/* @theme rk */
@import 'default';
h1, h2, h3 {
color: #ffffff;
}
section {
background-image: linear-gradient(to bottom, #67b8e3, #0288d1);
@rheinardkorf
rheinardkorf / quick_image_to_base64.php
Last active February 2, 2022 01:17
Quick and dirty GDImage to Base64 URL.
View quick_image_to_base64.php
<?php
function image_to_base64( $image, $type = 'image/jpeg' ) {
// Use new buffer to grab the output.
ob_start();
switch ( $type ) {
case 'image/jpeg':
imagejpeg( $image );
break;
@rheinardkorf
rheinardkorf / acf-hooks-basic.php
Created May 26, 2021 14:26
acf-hooks-basic.php
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 October 1, 2021 16:02
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 December 7, 2020 12:01
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 December 7, 2020 11:32
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 September 22, 2020 06:04
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 August 13, 2020 00:40
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 July 27, 2020 06:35
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 June 3, 2020 03:30
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,