Skip to content

Instantly share code, notes, and snippets.

@joemcgill
joemcgill / better_wp_images.php
Last active October 14, 2016 08:11
A set of function to improve the markup of images inserted into the editor in Wordpress.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// remove alignment class from the image
$html = preg_replace( '/ class=".*"/', '', $html );
// return the normal html output you would expect
$figure = "<figure class='image-inline";
if ($align == 'left' | 'right') {
$figure .= " align".$align;
@joemcgill
joemcgill / show_img_vars.php
Last active October 14, 2016 08:11
A poor man's var_dump for the image_send_to_editor() filter in Wordpress. Throw this in your functions.php file and add an image to your post to see what get's passed. Filter it however you want to return the image however you want.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// round up all the variables that get passed so we can test them
$vars = "html = $html\n";
$vars .= "id = $id\n";
$vars .= "caption = $caption\n";
$vars .= "title = $title\n"; // this will end up blank no matter what
$vars .= "align = $align\n";
$vars .= "url = $url\n";
@joemcgill
joemcgill / .bash_prompt
Created December 13, 2013 19:21
Custom bash prompt, inspired by Paul Irish's dotfiles repo.
#!/bin/bash
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
default_username='joemcgill'
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
@joemcgill
joemcgill / form_validation_browser_plug
Created November 27, 2013 18:04
When using HTML5 forms elements and validation, interrupt a browser's default invalidation message and plug in your own validation code (e.g., append an invalid class to the input and style accordingly).
document.addEventListener('invalid', (function(){
return function(e){
//prevent the browser from showing default error bubble/ hint
e.preventDefault();
// optionally fire off some custom validation handler
myvalidationfunction(e);
};
})(), true);
@joemcgill
joemcgill / README.md
Created November 22, 2013 07:16 — forked from oodavid/README.md
Steps for deploying a site with Git

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@joemcgill
joemcgill / wp_kill_parent_post
Created November 17, 2013 05:51
Remove a custom post type from a parent theme in WordPress.
add_action('after_setup_theme', 'wp_kill_parent_post');
function wp_kill_parent_post() {
remove_action('init', '<% parent post name %>');
}
// Register your own version in place of the parent post type if you want
@joemcgill
joemcgill / Customize TinyMCE in WP
Last active October 14, 2016 08:11
Set of functions for easily customizing the tinyMCE editor in WordPress. More references: Wes Bos – http://wesbos.com/custom-wordpress-tinymce-wysiwyg-classes/ TinyMCE Reference – http://www.tinymce.com/wiki.php/TinyMCE3x:Buttons/controls
// add style selector drop down
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
// customize the MCE editor
function my_customize_mce( $init ) {
@joemcgill
joemcgill / location.attr reference
Created October 14, 2013 22:21
Nice reference of browswer location attributes cribbed from this Stack Overflow thread: http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-javascript
http://www.refulz.com:8082/index.php#tab2?foo=123
Property Result
-------------------------------------------
host www.refulz.com:8082
hostname www.refulz.com
port 8082
protocol http
pathname index.php
@joemcgill
joemcgill / Bootstrapped Contact Forms 7
Last active May 16, 2016 14:02
Boilerplate form code for the WP Contact Forms 7 plugin that makes use of Bootstrap styles
<div class="form-group">
<label for="your-name">My Name</label>[text your-name class:form-control]
</div>
<div class="form-group">
<label for="your-email">Email Address</label>[email your-email class:form-control]
</div>
<div class="form-group">
<label for="your-message">Your Message</label>[textarea your-message class:form-control]
@joemcgill
joemcgill / parse_youtube_url
Created September 16, 2013 20:30
A handy javascript function for parsing YouTube urls and returning just the video URI (adapted from: http://stackoverflow.com/posts/9102270/revisions).
function parse_youtube_url(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match&&match[2].length==11){
return match[2];
}else{
//error
}
}