Skip to content

Instantly share code, notes, and snippets.

View macariojames's full-sized avatar
💭
Making things. All the things. Ahh!

Macario James macariojames

💭
Making things. All the things. Ahh!
View GitHub Profile
@macariojames
macariojames / nginx.conf
Last active August 20, 2018 19:08 — forked from jaxbot/gist:5748513
Block nginx from serving .git directories; Block apache from serving .gif directories
# For nginx -- goes in the /sites-available/domainnamehere.com file
location ~ /\.git {
return 404;
#deny all;
}
# or, all . directories/files in general (including .htaccess, etc)
# i like to use 'deny all' for all . files ~mj
location ~ /\. {
@macariojames
macariojames / gzip-compression-nginx.conf
Created August 16, 2018 19:09
gzip compression with nginx
via Jack Wallen @jlwallen
-- This goes in /etc/ngnix/ngnix.conf
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
@macariojames
macariojames / hide-php-file-extension
Created August 14, 2018 20:17
Nginx hide .php file extension but make sure the home page -- index.php -- page works
# This is in the server {} section of the /sites-available domain
location / {
#notice the $uri space $uri/ space before the @ function for the re-writes
try_files $uri $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
@macariojames
macariojames / test-sendmail.php
Created August 10, 2018 19:07
Testing php sendmail is working correctly
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "emailtest@currentdomain.com";
$to = "myemail@currentdomain.com";
$subject = "PHP Mail Test script via currentdomain";
$message = "This is a test to check the PHP sendmail functionality.";
$headers = "From:" . $from;
if(mail($to,$subject,$message, $headers))
echo "Test email sent from currentdomain.";
@macariojames
macariojames / mailchimp-custom.js
Last active March 25, 2022 13:16
MailChimp hide form on successful submit and thank you message; jQuery
// Add a surrounding <div> for all the ish don't want to keep once submission is successful
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script>
<script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[1]='FNAME';ftypes[1]='text';fnames[0]='EMAIL';ftypes[0]='email';}(jQuery));
//var $mcj = jQuery.noConflict(true);
</script>
<script>
$(function(){
//$("#mcm_hide_on_submit").hide();
$(".button").on("click", function(){
@macariojames
macariojames / anchorScrollTop.js
Created August 1, 2018 19:04
Anchor link with fixed header scroll with padding
// For FAQ page nav scrolling
function anchorScrollTo() {
$('.anchor li a').on('click', function(e){
e.preventDefault();
var scrollTo = $($(this).attr('href'));
var headerHeight = $('.page_header').height();
console.log(scrollTo, headerHeight);
$('html,body').animate({
scrollTop: scrollTo.offset().top - headerHeight},
'slow');
@macariojames
macariojames / get_real_host.php
Last active September 1, 2019 15:04
WordPress: Use different MySQL login credentials depending on your host (localhost, sandbox, production, etc.)
<?php
/* I use this in a separate config-properties.php or otherwise named file
* which is then included by wp-config.php ~mj */
function getRealHost() {
list($realHost,) = explode(':',$_SERVER['HTTP_HOST']);
return $realHost;
}
@macariojames
macariojames / core-emails.php
Last active September 1, 2019 15:06
ACF Advanced Forms - Custom Reply-to
<?php
// add this to `core-emails.php` file in the ACF Advanced Forms plugin ~mj
// From header
$from = af_resolve_field_includes( $email['from'], $fields );
$replyto = af_get_field( 'email');
$headers[] = 'From:' . $from;
// only have reply-to to Customer if it's admin
@macariojames
macariojames / display-field-name-acf-admin.php
Last active September 1, 2019 15:05
Display field_name for ACF field names back-end in development if Administrator
<?php
// Display ACF field names for development for Administrator only
function display_acf_field_names( $field ) {
echo $field['_name'];
}
if(is_admin() && !current_user_can('manage_options')) {
add_action( 'acf/render_field', 'display_acf_field_names', 10, 1 );
@macariojames
macariojames / add-img-responsive-class-images-wordpress.php
Last active September 1, 2019 15:07
Add .img-responsive class to all images uploaded/added in WordPress
<?php
/**
* @desc Add .img-responsive to all post images ~mj
*/
function add_post_img_responsive_class($attr) {
$attr['class'] .= ' img-responsive'; // note the leading space
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'add_post_img_responsive_class');