Skip to content

Instantly share code, notes, and snippets.

View chriskoelle's full-sized avatar

Chris Koelle chriskoelle

View GitHub Profile
@chriskoelle
chriskoelle / nh-oembed.php
Last active December 15, 2015 19:43
Wordpress oEmbed Customizations
<?php
/**
* Clear oEmbed Cache on save
* this is necessary in order to update the oembed output
*/
function nh_clear_oembed_caches($post_id) {
if ( wp_is_post_revision( $post_id ) ) return;
global $wp_embed;
$wp_embed->delete_oembed_caches($post_id);
}
@chriskoelle
chriskoelle / functions.php
Last active August 29, 2015 14:00
Wordpress trim "Private:" and "Protected:" from post titles
function nh_trim_post_titles($format) {
return '%s';
}
add_filter('protected_title_format', 'nh_trim_post_titles' );
add_filter('private_title_format', 'nh_trim_post_titles' );
;(function($) {
$.fn.extend({
stickyWidget: function(options) {
// Exit if there are no elements to avoid errors:
if (this.length === 0) {
return this;
}
var settings = $.extend({
<?php
class FB_Like_Widget extends WP_Widget {
private static $scripts_added;
public function __construct() {
parent::__construct(
'fb-like-box-widget', // ID
'Facebook Widget ', // Name
array(
@chriskoelle
chriskoelle / custom_page_templates.php
Last active August 29, 2015 14:02
Creates a submenu page for tools that lists out all custom page templates and which pages are using them. #wordpress
<?php
// Debug Custom Page Templates
function custom_page_templates_page() {
$templates = wp_get_theme()->get_page_templates();
$done = array();
$row = '<tr><td><a href="%s">%s</a></td><td width="60"><em>%s</em></td><td width="20"><a href="%s">edit</a></td></tr>';
$not_found = '<tr><td colspan="3"><em>No pages found using this template.</em></td></tr>';
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
echo '<h2>Custom Page Templates</h2>';
foreach ( $templates as $template_name => $template_filename ):
@chriskoelle
chriskoelle / gallery-extract.php
Last active August 29, 2015 14:04
Extract First Gallery from a post
@chriskoelle
chriskoelle / class-nh-post-type-pages.php
Last active August 29, 2015 14:05
Allows you to use a page as a custom post type archive (similar to the "posts page" within reading settings)
<?php
class NH_Post_Type_Pages {
private $pfpt, $post_types;
function __construct() {
$this->get_post_type_pages();
add_action( 'admin_init', array(&$this, 'reading_settings_section') );
if(!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)):
add_filter( 'pre_option_show_on_front', array(&$this, 'filter_show_on_front'));
@chriskoelle
chriskoelle / mailchimp-archive.php
Last active August 29, 2015 14:07
Display a list of past MailChimp campaigns
<?php
class NH_MailChimp_Archive {
private $_args, $max_page,
public function __construct($args = array()) {
global $paged;
$defaults = array(
'apikey' => false,
'start' => 0,
'limit' => 12,
@chriskoelle
chriskoelle / class-nh-shortcode-generator.php
Last active August 29, 2015 14:11
Add a button above TinyMCE to generate a shortcode
<?php
/**
* Create a button that generates a shortcode to be added to TinyMCE.
*
* @todo Add an option to change the template file path.
* Add the ability to specify what admin pages the button is displayed on.
*/
class NH_Shortcode_Generator {
private $form_id = null;
@chriskoelle
chriskoelle / max-image-size.js
Created December 16, 2014 20:06
Use javascript and canvas to resize images from file input before upload
jQuery(function($) {
// Test for file API support.
var fileApiSuport = !!(window.File && window.FileReader );
/**
* Resize images that exceed the maximum size (in pixels)
* @param {object} input The file input.
* @param {Function} callback Callback function run after the image has been resized.
* @return {null}
*/