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;
<?php
/* Thanks to http://steindom.com/articles/shortest-php-code-convert-csv-associative-array */
ini_set('auto_detect_line_endings', TRUE);
$rows = array_map('str_getcsv', file('myfile.csv'));
$header = array_shift($rows);
$csv = array();
foreach ($rows as $row) {
@davemac
davemac / acf_slick.php
Created May 8, 2017 11:48 — forked from mattradford/acf_slick.php
ACF slick slider
<?php if( have_rows('billboard') ): ?>
<div class="billboard">
<?php while( have_rows('billboard') ): the_row();
$imageArray = get_sub_field('image');
$imageURL = $imageArray['url'];
?>
<div class="slide-item" style="background-image: url('<?php echo $imageURL;?>');" >
<h1><?php the_sub_field('title'); ?></h1>
</div>
@davemac
davemac / acf-first-row.php
Created March 21, 2017 04:46 — forked from neilgee/acf-first-row.php
ACF Repeater - Grab First/LAst or Random Single Data Row
<?php
//My ACF Fields for reference
//testimonials - field group
//testimonial - sub-field
//testimonial_header - sub-field
//First Repeater Row in Array
$rows = get_field( 'testimonials', 348 );// grab all rows from page ID
@davemac
davemac / acf-js.js
Created March 21, 2017 04:43 — forked from neilgee/acf-js.js
ACF Google Map - Get Directions Link
(function($) {
/*
* new_map
*
* This function will render a Google Map onto the selected jQuery element
*
* @type function
* @date 8/11/2013
* @since 4.3.0
@davemac
davemac / sync-prod.sh
Created January 16, 2017 10:55 — forked from retlehs/sync-prod.sh
WP-CLI aliases sync example
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
wp @development db reset --yes
wp @production db export - > sql-dump-production.sql
wp @development db import sql-dump-production.sql
wp @development search-replace https://example.com https://example.dev
else
exit 0
fi
@davemac
davemac / functions.php
Created January 3, 2017 06:04 — forked from kontikidigital/functions.php
WooCommerce: Change Select Options Button Text for variable products
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
/**
* custom_woocommerce_template_loop_add_to_cart
*/
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->product_type;
switch ( $product_type ) {
@davemac
davemac / quotes.sh
Created October 19, 2016 08:09 — forked from SahilC/quotes.sh
A bash script to give you a random quote everytime you open your terminal. Add the following lines to your bashrc.
# font color : green
color='\e[0;32m'
# font color : white
NC='\e[0m'
getquote(){
num_online_quotes=9999
rand_online=$[ ( $RANDOM % $num_online_quotes ) + 1 ]
quote=$(wget -q -O - "http://www.quotationspage.com/quote/$rand_online.html" |
@davemac
davemac / dnsmasq_setup_osx.md
Created October 3, 2016 10:47 — forked from eloypnd/dnsmasq_setup_osx.md
wildcard DNS record on OS X in localhost development with dnsmasq

wildcard DNS in localhost development

$ brew install dnsmasq
   ...
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • edit /usr/local/etc/dnsmasq.conf
address=/local/127.0.0.1