Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
@davemac
davemac / nginx-redirect-uploads-to-production
Last active August 9, 2023 04:51 — forked from iansvo/nginx-redirect-uploads-to-production
Open the Nginx configuration for your site and look for a server block that listens for port 443. Look for something like Listen 127.0.0.1:443 ssl in the server { ... } block to find the right one. Add the following location rules near the top of the block, after any other definitions.
# Redirect requests to /wp-content/uploads/* to production
set $production themotoringnetwork.com.au;
location @prod_uploads {
rewrite "^(.*)/wp-content/uploads/(.*)$" "https://$production/wp-content/uploads/$2" break;
}
# Rule for handling local requests for images
location ~ "^/wp-content/uploads/(.*)$" {
try_files $uri @prod_uploads;
@davemac
davemac / enqueue Google fonts with preconnect
Last active August 28, 2023 17:38
WordPress enqueue google font with preconnect
wp_enqueue_style( 'dmc-google-font-fragment', 'https://fonts.googleapis.com/css2?family=Montserrat:wght@300&family=Roboto:ital,wght@0,500;1,400&display=swap', array(), null );
function dmc_google_font_loader_tag_filter( $html, $handle ) {
if ( $handle === 'dmc-google-font-fragment' ) {
$rel_preconnect = "rel='stylesheet preconnect'";
return str_replace(
"rel='stylesheet'",
$rel_preconnect,
$html
@davemac
davemac / getups()
Created May 20, 2019 02:13
rsyncs WordPress uploads directory from staging/prod to current site, excluding .pdf files
# rsync wp uploads directory from staging to current site, exclude .pdf files
# uses command line argument $1 for prod or staging ssh alias
getups() {
current=${PWD##*/}
cd ~/Sites/$current/wp-content/uploads || return
rsync -avzW --progress --exclude '*.pdf' --exclude '*.docx' $current-$1:~/www/wp-content/uploads/* .
cd ~/Sites/$current/wp-content/themes/$current
}
@davemac
davemac / pullstage()
Created May 17, 2019 00:47
pull a staging WP database to an existing local site
# pull a staging WP database to an existing local site
# uses current directory as theme path and ssh alias
pullstage() {
# set -x
START=$(date +%s)
# get current directory name, used for database and URL
# TODO: use echo get_template_directory() and get characters from right to first /
current=${PWD##*/}
cd ~/Sites/$current
# make a backup of the current local database
# pull a staging WP database to an existing local site
# uses current directory as theme path and ssh alias
pullstage() {
# set -x
START=$(date +%s)
# get current directory name, used for database and URL
# TODO: use echo get_template_directory() and get characters from right to first /
current=${PWD##*/}
cd ~/Sites/$current
# make a backup of the current local database
@davemac
davemac / firstdeploy()
Last active July 16, 2019 07:06
initial deploy of local site to staging server
# for initial site deployment to staging server, excludes dev tools and build files
# uses current directory as theme path and ssh alias
# 3 user inputs: dbname, dbuser, dbpass
firstdeploy() {
current=${PWD##*/}
cd ~/Sites/$current || return
echo "Staging database name:"
read dbname
echo "Staging database user:"
@davemac
davemac / pushstage()
Last active March 3, 2022 13:51
push a local WP database to an existing staging site
# push a local WP database to an existing staging site
# uses current directory as theme path and ssh alias
pushstage() {
START=$(date +%s)
# make a backup of the current local database
# get current directory name, used for database and URL
current=${PWD##*/}
cd ~/Sites/$current || return
# rsync the local database to staging site
@davemac
davemac / pullprod()
Last active April 4, 2019 02:19
pull a production WP database to an existing local site
# pull a production WP database to an existing local site
# uses current directory as theme path and ssh alias
pullprod() {
START=$(date +%s)
# get current directory name, used for database and URL
# TODO: use echo get_template_directory() and get characters from right to first /
current=${PWD##*/}
cd ~/Sites/$current
# make a backup of the current local database
wp db export _db.sql
@davemac
davemac / cloudflare ips for jetpack
Last active March 8, 2019 09:08
cloudflare ips for jetpack
103.21.244.0-103.21.244.22
103.22.200.0-103.22.200.22
103.31.4.0-103.31.4.22
104.16.0.0-104.16.0.12
108.162.192.0-108.162.192.18
131.0.72.0-131.0.72.22
141.101.64.0-141.101.64.18
162.158.0.0-162.158.0.15
172.64.0.0-172.64.0.13
173.245.48.0-173.245.48.20
@davemac
davemac / getuploads
Created November 30, 2018 00:29
getuploads
# rsync wp uploads directory from staging to current site, exclude .pdf files
# uses command line argument $1 for prod or staging ssh alias
getups() {
current=${PWD##*/}
cd ~/Sites/$current/wp-content/uploads || return
rsync -avzW --progress --exclude '*.pdf' --exclude '*.docx' $current-$1:~/www/wp-content/uploads/* .
}