Skip to content

Instantly share code, notes, and snippets.

@scottlee
scottlee / GetWP
Created July 28, 2011 20:16
Here's my little local development only script I use to download and install WordPress. mac, osx, mamp
#!/bin/bash
##########
## Setup: hardcode your mysql user/pass. Yeah, yeah, I know...it's frowned upon.
## but for local development, I have no problem with it.
## Find and replace: MYSQLUSER / MYSQLPASS
##
## Usage: This script accepts only one variable, the site name.
##
#########
@scottlee
scottlee / Get external IP, write to file
Created August 12, 2011 20:31
Get external IP address and write to file if it has changed
#!/bin/bash
# Where should this file be stored?
ipfile=~/Desktop/external-ip.txt
# Go ahead now, go ahead and get that IP
IP=$(curl -s http://icanhazip.com)
# Has the address changed? If it has go ahead and write that bad boy down. If not, no worries.
OLDIP=""
@scottlee
scottlee / bug-hunt-one.php
Created January 9, 2012 17:04 — forked from EnvatoWP/bug-hunt-one.php
Bug Hunt One
<?php
/*
* Plugin Name: EnvatoWP Bug Hunt One
* Plugin URI: https://gist.github.com/
* Description: Bug Hunt One - Find all the bugs in this basic plugin
* Version: 0.1
* Author: EnvatoWP
* Author URI: http://envatowp.github.com/
* License: GPL2
*/
@scottlee
scottlee / gist:1764206
Created February 8, 2012 01:43
Check current environment, set appropriate variables
/*
* Check for the current environment
*/
//define('WP_CACHE', true); //Added by WP-Cache Manager
if ($_SERVER["HTTP_HOST"] === 'domain.com') {
$db_name = 'dbname';
$db_user = 'dbuser';
$password = 'dbass';
} else if ($_SERVER["HTTP_HOST"] === 'local') {
@scottlee
scottlee / gist:3841430
Created October 5, 2012 18:13
Display if excerpt exist
<?php if(!empty($post->post_excerpt)) {
//This post have an excerpt, let's display it
the_excerpt();
} else {
// This post have no excerpt
} ?>
@scottlee
scottlee / gist:3841816
Created October 5, 2012 19:22
Trim "protected" from the title
function degweb_protected_title_trim($title) {
$title = attribute_escape($title);
$findthese = array(
'#Protected:#',
'#Private:#'
);
$replacewith = array(
'', // What to replace "Protected:" with
'' // What to replace "Private:" with
);
@scottlee
scottlee / functions.php
Created November 1, 2012 15:30
Create a widgetized area for every top level page in WordPress.
/**
* Create widgetized sidebars for each page
*/
function xxx_custom_page_sidebars() {
$pages = get_pages( array(
'parent' => 0
)
);
foreach ( $pages as $page ) {
@scottlee
scottlee / gist:5584524
Created May 15, 2013 14:46
All external links in new window.
<script>
$(document).ready(function() {
$('a[href]')
.filter(function(){
return ($(this).attr('href').match(new RegExp('^https?|ftp')));
})
.filter(function(){
return (! $(this).attr('href').match(new RegExp('^(https?|ftp):\/\/'+location.hostname)));
})
.attr('target', '_blank');
@scottlee
scottlee / header.php
Created May 15, 2013 19:52
Add favicon to WordPress
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
@scottlee
scottlee / menus.php
Created June 4, 2013 18:56
If the current page has child menu items, display them. Hazzah!
<?php
/**
* Returns the submenu items of the parent menu item.
* @param $sorted_menu_items
* @param $args
* @return mixed
*/
function theme_wp_nav_menu_sub_menu_objects( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;