Skip to content

Instantly share code, notes, and snippets.

View retgef's full-sized avatar

Brian Fegter retgef

View GitHub Profile
@retgef
retgef / create_deployment.sh
Created June 29, 2018 19:29 — forked from kgorskowski/create_deployment.sh
recreate latest successful codedeploy deployment. needs awscli, jq and corresponding iam permissions
#!/bin/bash
#your variables here, you can set AWS credentials here as well
AWS_REGION=$YourAWSRegion
DEP_GROUP=$NameOfYourCodeDeployDeploymentGroup
APP_NAME=$NameOfYourCDApplication
# list successfull deployments only
STATUS=Succeeded
@retgef
retgef / coderrr-s3-convert.php
Last active June 19, 2018 20:47
Converts existing attachment meta for use with https://wordpress.org/plugins/amazon-s3-and-cloudfront/
<?php
/*
Plugin Name: Coderrr S3 Conversion
Description: Converts previously uploaded attachments to work with amazon-s3-and-cloudfront plugin
Version: 0.1
Author: Brian Fegter
License: GPLv2+
*/
/**
<?php
function send_http_auth_headers(){
header('WWW-Authenticate: Basic realm="Your Website Name Restricted"');
header('HTTP/1.0 401 Unauthorized');
echo 'Please speak to an administrator for access to the this feature.';
exit;
}
add_action('template_redirect', 'maybe_add_http_auth_basic', 0);
function maybe_add_http_auth_basic(){
# Add your specific URI segment (i.e. http://example.com/segment-string/)
@retgef
retgef / psuedo-static-js.php
Last active April 7, 2017 22:00
Add a pseudo static JS file to WordPress
<?php
#Add a query var to sniff requests
add_filter( 'query_vars', 'my_query_var_callback', 10, 1 );
function my_query_var_callback( $vars ){
$vars[] = 'dynamic_js';
return $vars;
}
#Dynamic JavaScript
add_rewrite_rule( '^assets/js/dynamic\.js$', 'index.php?dynamic_js=1', 'top' ); //Note the hidden query variable
@retgef
retgef / regex-schtuff.txt
Created September 18, 2013 21:03
A basic, basic primer for regex and PHP.
_______ ______ __ _ ___ ___
|_ __ \ .' ____ \ [ | / |_ .' ..] .' ..]
| |__) | .---. .--./) .---. _ __ | (___ \_| .---. | |--. `| |-'__ _ _| |_ _| |_
| __ / / /__\\/ /'`\;/ /__\\[ \ [ ] _.____`. / /'`\] | .-. | | | [ | | |'-| |-''-| |-'
_| | \ \_| \__.,\ \._//| \__., > ' < | \____) || \__. | | | | | |, | \_/ |, | | | |
|____| |___|'.__.'.',__` '.__.'[__]`\_] \______.''.___.'[___]|__]\__/ '.__.'_/[___] [___]
( ( __))
---------------------------------------------------------------------------------------------------------------
@retgef
retgef / wp-config-switcher.php
Last active December 11, 2015 02:59
For use with multiple sub-folder WordPress installations. This allows you to store all wp-config.php in any folder on your server. WP config files are renamed to correspond with the server name. This approach helps you protect your wp-config files when you have multiple docroots in one folder.
<?php
# ------------------
# no shenanigans
# ------------------
if ( __FILE__ == $_SERVER['SCRIPT_FILENAME'] ) { die(); }
# ---------------
# server name
# ---------------
$server = $_SERVER['SERVER_NAME'];
@retgef
retgef / psuedo-buffer.php
Created December 31, 2012 13:26
Allows you to send the current user auth cookie along with a WP HTTP API remote request. This is useful for storing a page load for analysis in a psuedo-buffer if you are competing with cache plugins that use output buffering.
<?php
#Set your current WP install URL
$url = 'http://currentwpinstall.com';
#Create cookie string
$cookie_string = '';
foreach($_COOKIE as $k => $v)
#Assure we are setting the proper string if other cookies are set
if(preg_match('/(wordpress_test_cookie|wordpress_logged_in_|wp-settings-1|wp-settings-time-1)/', $k))
$cookie_string .= $k . '=' . urlencode($v) . '; ';
@retgef
retgef / wordpress-audit-attachments.php
Created October 20, 2012 04:51
WordPress Plugin - Audit Post Attachments
<?php
/*
Plugin Name: Audit Attachments
Description: Reports on a set of post types and their respective attachments
Version: 0.1
Author: Brian Fegter
Author URI: http://coderrr.com/
*/
/**
@retgef
retgef / wordpress-remove-404-attachments
Created October 20, 2012 03:09
Remove attachment rows where the associated file on the disk doesn't exist.
<?php
/**
* Usage when logged in: http://yourdomain.com/wp-admin/remove-404-attachments=secretpassword
*/
# Hook late into admin_init
add_action('admin_init', 'remove_404_attachments', 9999999);
function remove_404_attachments(){
@retgef
retgef / pug-bomb.php
Created June 24, 2012 07:46
Pug Bomb API Endpoint WordPress Plugin
<?php
/*
Plugin Name: Pug Bomb API Endpoint
Description: Adds an API endpoint at /api/pugs/$n_pugs
Version: 0.1
Author: Brian Fegter
Author URL: http://coderrr.com
*/
class Pugs_API_Endpoint{