Skip to content

Instantly share code, notes, and snippets.

View JacobDB's full-sized avatar

Jacob Bearce JacobDB

View GitHub Profile
@JacobDB
JacobDB / install-acf.sh
Last active July 23, 2024 10:28
Download and install ACF Pro via a bash script – to be used with WP CLI. Set an environemnt variable ACF_KEY first!
#!/bin/sh
# Adapted from https://support.advancedcustomfields.com/forums/topic/download-acf-with-wp-cli-on-clean-install/#post-26191
# get plugin path
acf_zip_file="$(wp plugin path)/advanced-custom-fields-pro.zip"
# get acf zip file
wget -O ${acf_zip_file} "https://connect.advancedcustomfields.com/v2/plugins/download?p=pro&k=$ACF_KEY"
<?php
/**
* Read ACF fields from JSON
*/
function PREFIX_acf_register_json_fields() {
if (function_exists("acf_add_local_field_group")) {
$acf_json_data = locate_template("path/to/advanced-custom-fields.json");
$custom_fields = $acf_json_data ? json_decode(file_get_contents($acf_json_data), true) : array();
foreach ($custom_fields as $custom_field) {
@JacobDB
JacobDB / functions.php
Created August 30, 2023 14:34
Send preload headers for WordPress CSS files
<?php
/**
* Preload styles
*
* @return void
*/
function mytheme_preload_styles(): void {
global $wp_styles;
if ($wp_styles) {
@JacobDB
JacobDB / custom-nav-menus-options.php
Last active June 9, 2023 06:36
Add any custom option to the WordPress nav menus editor. I primarily use this for mega menus, but it can be used to add basically any additional data to menus.
<?php
// add custom options to the menu editor
if (is_admin() && $pagenow === "nav-menus.php") {
// include this so we can access Walker_Nav_Menu_Edit
require_once ABSPATH . "wp-admin/includes/nav-menu.php";
// Add the WordPress color picker styles & scripts
function new_site_nav_menu_color_picker() {
wp_enqueue_style("wp-color-picker");
wp_enqueue_script("wp-color-picker");
@JacobDB
JacobDB / inline-svg-function.scss
Created January 26, 2017 17:45 — forked from B-iggy/inline-svg-function.scss
Inline SVG function [SASS]
// Replace letters
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@JacobDB
JacobDB / focus-assist-toggle.ahk
Last active February 13, 2022 12:57
Focus assist toggle with WIN+SHIFT+F
active := false
+#F::
SendInput, {LWin down}b{LWinUp}{Left}
SendInput, {APPSKEY}{Down}{Down}{Enter}
if (active = false) {
SendInput, {Down}{Down}
active := true
} else {
@JacobDB
JacobDB / auto-nvm.sh
Created April 14, 2021 16:09
Automatically switch NVM versions when entering directories which contain `.nvmrc`
#!/bin/bash
# Run 'nvm use' automatically every time there's a .nvmrc file in the directory.
# Also, revert to default version when entering a directory without .nvmrc
enter_directory() {
if [[ $PWD == $PREV_PWD ]]; then
return
fi
PREV_PWD=$PWD
@JacobDB
JacobDB / twitch.sh
Created August 24, 2020 15:37
Download Twitch VODs
#!/bin/sh
# To find proper value for $1, open a developer tools on a Twitch stream and select "Network." Search for "m3u8," copy the longest URL you see, and it should work.
ffmpeg -i $1 -c copy -bsf:a aac_adtstoasc $2
@JacobDB
JacobDB / code.sh
Last active April 24, 2020 15:28
Small script to fix symlinked paths when opening VS Code from within WSL
# Modify VS Code CLI to expand symlinks before opening, to fix git status highlighting
code() {
# Set the path to VS Code
code_path="/mnt/c/Users/Jacob/AppData/Local/Programs/Microsoft VS Code/bin/code";
# Store converted arguments
converted=""
# Loop through all passed arguments
for arg in "$@"
@JacobDB
JacobDB / .gitlab-ci.yml
Last active March 10, 2020 13:38 — forked from RafalSladek/ .gitlab-ci.yml
gitlab ci file for gulp build pipeline with the latest nodejs
image: node:latest
cache:
paths:
- node_modules/
before_script:
- npm install -g gulp
- npm install