Skip to content

Instantly share code, notes, and snippets.

@ethicka
ethicka / remote-uploads.php
Created February 26, 2021 17:45
Load wp-content/uploads from the remote site
<?php
/**
* Loads media from a remote site when on a local dev environment.
* Eliminates the need to download the uploads directory from the remote site for testing purposes.
* Replace WEBSITE with you domain name.
*/
if ('WEBSITE.local' === $_SERVER['HTTP_HOST']) :
add_filter('upload_dir', function ($uploads) {
$uploads['baseurl'] = 'https:/WEBSITE.com/wp-content/uploads';
@ethicka
ethicka / pdf-to-jpg.sh
Last active October 9, 2020 14:33
Convert a folder of PDFs to JPGs
#!/bin/bash
# Dependencies: vips
# Homebrew: brew install vips
for file in *.pdf
do
# Run vips pdfload for options
# You could add --page=1 to get the second page (from 0) or --dpi=300, etc. to get different quality images
# The variable gets the filename without the extension
vips pdfload ${file%.*}.pdf ${file%.*}.jpg
done
@ethicka
ethicka / build-comma-separated-string.php
Created April 29, 2020 21:38
Build a comma separated string of one or more strings
<?php
/**
* Build Comma-Separated String
* Won't add a hanging comma if there's only passed value
*/
function comma_separated($array) {
$string = implode(', ', $array);
if (preg_match("/, $/", $string)) { // if it ends in a comma, remove the comma
$string = substr($string, 0, -2);
}
@ethicka
ethicka / build-a-name.php
Created April 29, 2020 21:37
Build a name from a prefix and suffix
<?php
/**
* Build a name
*/
function build_name($prefix, $fname, $lname, $suffix) {
$name = $fname . ' ' . $lname;
if($prefix) $name = $prefix . ' ' . $name;
if($suffix) $name = $name .= $suffix;
return $name;
}
@ethicka
ethicka / facetwp_pager_html.php
Last active May 20, 2021 11:01 — forked from MWDelaney/facetwp.php
FacetWP Bootstrap 4 Pagination (facetwp_pager_html)
<?php
/**
* FacetWP Pager Bootstrap 4 Pagination
* @source https://gist.github.com/MWDelaney/ce9e523b3f1bdf57b3180c9b24b73170
* @source https://fellowtuts.com/bootstrap/wordpress-pagination-bootstrap-4-style/
*/
add_filter('facetwp_pager_html', function ($output, $params) {
$range = 2; // +/- pages from the current page
$showitems = ($range * 2) + 1;
$page = $params['page'];
@ethicka
ethicka / remove-facet-count.php
Created February 3, 2020 20:27
FacetWP: Remove Facet Count
<?php
add_filter('facetwp_facet_html', function ($output, $params) {
if ('dropdown' == $params['facet']['type']) {
$output = preg_replace("/( \([0-9]+\))/m", '', $output);
}
return $output;
}, 10, 2);
@ethicka
ethicka / abbreviations.txt
Created September 20, 2019 17:42
WP ACF States Abbreviations Values
AL : Alabama
AK : Alaska
AS : American Samoa
AZ : Arizona
AR : Arkansas
CA : California
CO : Colorado
CT : Connecticut
DE : Delaware
DC : District of Columbia
@ethicka
ethicka / restore-trash.md
Created July 31, 2018 14:39
Restoring Trash functionality if Trash forces you to immediately delete files in Mac OS High Sierra.

Restore Trash

Run the following commands in shell:

rm -rf ~/.Trash/
mkdir ~/.Trash/

Then relaunch the Finder to apply permissions: Command + Option + Esc and Relaunch Finder.

@ethicka
ethicka / sage9-deploybot.md
Last active May 4, 2020 07:24
How to build and deploy a Roots / Sage 9 WordPress theme on Deploybot

Deploying Roots Sage 9 via Deploybot

Sage 9 is the latest and greatest from Roots, but the build process is much more complicated than Sage 8 (i.e. gulp --production and profit). The following took me quite a bit of time to figure out, but is probably not comprehensive. Please comment if you need clarity. I hope it saves you some time!

Build the Container

Deploybot allows you to create your own containers. Go to Settings > Containers > Create a container. Based off the Ubuntu 16.04 container add the following build commands and save as Sage 9:

@ethicka
ethicka / localhost-ssl-certificate.md
Last active December 24, 2024 06:56
Localhost SSL Certificate on Mac OS

🚨 2020 Update: I recommend using mkcert to generate local certificates. You can do everything below by just running the commands brew install mkcert and mkcert -install. Keep it simple!


This gives you that beautiful green lock in Chrome. I'm assuming you're putting your SSL documents in /etc/ssl, but you can put them anywhere and replace the references in the following commands. Tested successfully on Mac OS Sierra and High Sierra.

Set up localhost.conf

sudo nano /etc/ssl/localhost/localhost.conf