Skip to content

Instantly share code, notes, and snippets.

View dtateii's full-sized avatar

Dave Tate dtateii

View GitHub Profile
@dtateii
dtateii / wp-config.php
Last active July 25, 2019 02:48
Pantheon HTTPS and www hostname redirects for WordPress config
<?php
// wp-config.php snippet. Put this just before the "Happing Pressing!" comment.
// HTTPS and www redirects.
// Edit constants below based on your needs.
define( 'HOSTNAME_PREFERRED', 'www.domain.com' );
define( 'HOSTNAME_PANTHEON_LIVE', 'live-domain.pantheonsite.io' );
define( 'FORCE_HTTPS', true );
@dtateii
dtateii / wp-cors.php
Created September 29, 2017 15:24
Q+D CORS headers for WP REST API
<?php
/**
* Plugin Name: CORS
* Description: Just adds headers to every response to enable cross-origin GET requests for API.
* Version: 0.0.1
* Author: NJI Media
* Author URI: https://www.njimedia.com
* License: GPLv2 or later
* Text Domain: cors
*
@dtateii
dtateii / composer.json
Created September 26, 2017 16:52
Composer-managed coexisting CodeSniffer Rulesets for WordPress and Drupal
{
"minimum-stability": "dev",
"require": {
"drupal/coder": "^8.2",
"squizlabs/php_codesniffer": "2.9.0",
"wp-coding-standards/wpcs": "0.12.0"
},
"scripts" : {
"post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths ../../wp-coding-standards/wpcs,../../drupal/coder/coder_sniffer",
"post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths ../../wp-coding-standards/wpcs,../../drupal/coder/coder_sniffer"
@dtateii
dtateii / tables_prefixer.sql
Created August 25, 2016 01:19
Prefix All Database Tables
SELECT Concat('ALTER TABLE ', TABLE_NAME, ' RENAME TO my_prefix_', TABLE_NAME, ';') FROM information_schema.tables WHERE table_schema = 'my_database_name'
@dtateii
dtateii / .htaccess
Last active August 23, 2016 13:55
Drupal Edit Domain Access Control
# BEGIN Access Control
<IfModule mod_setenvif.c>
# Check Host, set "edit" domain env
SetEnvIf Host "edit.domain.com" edit=1 # Prod
SetEnvIf Host "edit-stg.domain.com" edit=1 # Staging
SetEnvIf Host "edit.domain.loc|dev" edit=1 # Local Dev
# Build Edit-domain Whitelist
SetEnvIf REMOTE_ADDR ^nnn\.nnn\.nnn\.nnn$ whitelist=1 # Client HQ
@dtateii
dtateii / jstest.html
Created February 25, 2016 17:58
Example JS Number Properties
<!DOCTYPE html>
<html>
<head>
<title>JS Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
</head>
<body>
<header>
<h1>JS Test</h1>
<p>Use console.</p>
@dtateii
dtateii / Earthworm.tmTheme
Created January 9, 2016 19:46
SublimeText3 Color Scheme: Earthworm
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>author</key>
<string>dtateii</string>
@dtateii
dtateii / delete-all-except-last-n.sh
Created December 15, 2015 19:21
Delete all except last N files
ls -tr | head -n -3 | sudo xargs --no-run-if-empty rm
@dtateii
dtateii / security_watch.php
Last active August 23, 2016 13:57
Watch for suspicious requests and notify on Slack. For use on hosts lacking adequate logging capabilities. This file can be loaded on every request using .htaccess `php_value auto_prepend_file {/path/to/security_watch.php}`
<?php
/**
* @file
* Simple processing on requests with notification.
*/
_njisec_check_querystring();
_njisec_check_method();
_njisec_check_language();
@dtateii
dtateii / RewriteUgcImages.sh
Created July 30, 2015 21:03
Local Dev: Forward User-Generated Image Requests to Server
# APACHE RULE: DRUPAL (inside .htaccess)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule sites/default/files/(.*) \
http://{site.com}/sites/default/files/$1 [NC,L]
</IfModule>
# APACHE RULE: WORDPRESS (inside .htaccess)