Skip to content

Instantly share code, notes, and snippets.

View ScottPhillips's full-sized avatar

Scott Phillips ScottPhillips

  • Los Angeles, CA
View GitHub Profile
@ScottPhillips
ScottPhillips / custom_wordpress_columns.php
Created July 29, 2012 15:12
Add Custom Columns to WordPress Post List Page
<?php
add_filter( 'manage_posts_columns', 'your_custom_cols' ); //Filter out Post Columns with 2 custom columns
function your_custom_cols($defaults) {
$defaults['language'] = __('Language'); //Language and Films is name of column
$defaults['film'] = __('Films');
return $defaults;
}
@ScottPhillips
ScottPhillips / modify-wp-comments.php
Created July 29, 2012 08:48
Modify Comment Fields in WordPress
<?php
//We can add a field as follows:
function add_comment_fields($fields) {
$fields['age'] = '<p class="comment-form-age"><label for="age">' . __( 'Age' ) . '</label>' .
'<input id="age" name="age" type="text" size="30" /></p>';
return $fields;
@ScottPhillips
ScottPhillips / wpse-remote-auth.php
Created July 25, 2012 20:23 — forked from chrisguitarguy/wpse-remote-auth.php
Check WordPress usernames/passwords remote.
<?php
/*
Plugin Name: Authenticate Users Remotely
Author: Christopher Davis
Author URI: http://www.christopherguitar.net/
License: GPL2
*/
add_filter('xmlrpc_methods', 'wpse39662_add_login_method' );
/**
@ScottPhillips
ScottPhillips / update-wordpress-posts.php
Created July 23, 2012 06:21
Update WordPress Posts
function wpa47153_run_once(){
$posts = get_posts(array('numberposts' => -1) );
foreach($posts as $p) :
$meta = get_post_meta($p->ID, 'meta_key',true);
if($meta) :
@ScottPhillips
ScottPhillips / seo-friendly-url.php
Created July 23, 2012 06:12
Create SEO URL from String
<?php
function generateSlug($phrase, $maxLength) {
$result = strtolower($phrase);
$result = preg_replace("/[^a-z0-9\s-]/", "", $result);
$result = trim(preg_replace("/[\s-]+/", " ", $result));
$result = trim(substr($result, 0, $maxLength));
$result = preg_replace("/\s/", "-", $result);
return $result;
}
@ScottPhillips
ScottPhillips / cache-json.php
Created July 18, 2012 23:52
Cache Remote JSON Feed
<?php
/**
* API Request Caching
*
* Use server-side caching to store API request's as JSON at a set
* interval, rather than each pageload.
*
* @arg Argument description and usage info
*/
@ScottPhillips
ScottPhillips / outer-html.js
Created July 11, 2012 21:06
jQuery OuterHTML plugin
jQuery.fn.extend( {
outerHtml: function( replacement ) {
// We just want to replace the entire node and contents with
// some new html value
if (replacement) {
return this.each(function (){ $(this).replaceWith(replacement); });
}
/*
* Now, clone the node, we want a duplicate so we don't remove
@ScottPhillips
ScottPhillips / update-post-page-data.php
Created July 11, 2012 21:01
Update Wordpress Post/Page Data...
<?php
function wpa47153_run_once(){
$posts = get_posts(array('numberposts' => -1) );
foreach($posts as $p) :
$meta = get_post_meta($p->ID, 'meta_key',true);
@ScottPhillips
ScottPhillips / remote-image-cache.php
Created July 7, 2012 07:16
Cache remote image using PHP
<?php
function cache_image($image_url){
//replace with your cache directory
$image_path = 'path/to/cache/dir/';
//get the name of the file
$exploded_image_url = explode("/",$image_url);
$image_filename = end($exploded_image_url);
$exploded_image_filename = explode(".",$image_filename);
$extension = end($exploded_image_filename);
//make sure its an image
@ScottPhillips
ScottPhillips / simple-php-crawler.php
Created June 30, 2012 23:41
Simple PHP Crawleer
<?php
function crawl_page($url, $depth = 5)
{
static $seen = array();
if (isset($seen[$url]) || $depth === 0) {
return;
}
$seen[$url] = true;