Skip to content

Instantly share code, notes, and snippets.

View petenelson's full-sized avatar

Pete Nelson petenelson

View GitHub Profile
@petenelson
petenelson / timeline-express-filter-test.php
Created April 24, 2015 18:51
WordPress: Test the new Timeline Express filter
<?php
/*
Plugin Name: Timeline Express Custom Icon Filter Test
*/
add_filter( 'timeline-express-custom-icon-html', 'pn_timeline_express_custom_icon_html_test', 10, 3 );
function pn_timeline_express_custom_icon_html_test( $html, $post, $timeline_express_options ) {
$custom_png_icon = get_post_meta( $post->ID, '_custom_png_icon', true );
@petenelson
petenelson / pn-revisions-in-list-table.php
Last active August 29, 2015 14:18
WordPress: Display a list of post/page/custom post type revisions in the dashboard list tables
<?php
/*
Plugin Name: Revisions in List Table
Description: Allows a list of revisions to display in the dashboard list tables
Author: Pete Nelson
Version: 1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit( 'restricted access');
@petenelson
petenelson / gga-api-helper.php
Created March 20, 2015 00:09
WordPress: Prevent specific plugins from loading during /api/ requests
<?php
/**
* Plugin Name: GGA API Helper
* Description: Prevents certain plugins from being loaded during API requests to reduce overhead.
* Author: Pete Nelson (@GunGeekATX)
* Version: 1.0.0
*/
/*
@petenelson
petenelson / gga-ssh2-wordpress-sample.php
Created February 27, 2015 21:53
WordPress: Upload a file to a remote server via SSH2
<?php
/*
Plugin Name: GGA SSH2 Sample
Description: Sample SSH2 upload
Author: Pete Nelson (@GunGeekATX)
Version: 1.0
*/
if (!defined( 'ABSPATH' )) exit('restricted access');
@petenelson
petenelson / add_shortcake.php
Created February 3, 2015 15:39
WordPress: add_shortcake alias for add_shortcode
<?php
if ( function_exists( 'add_shortcode' ) && ! function_exists( 'add_shortcake' ) ) {
// tasty WordPress add_shortcode alias, for @technosailor
function add_shortcake( $tag, $func ) {
add_shortcode( $tag, $func );
}
}
@petenelson
petenelson / filter_large_image_dimensions.php
Created December 2, 2014 16:13
WordPress: Prevent large image uploads by dimension
<?php
add_filter( 'wp_handle_upload_prefilter', 'gga_filter_large_image_dimensions' );
function gga_filter_large_image_dimensions( $file ) {
$maxsize = 2000;
if ( false !== strpos($file['type'], 'image/') ) {
$size = getimagesize( $file['tmp_name'] );
<?php
/*
Plugin Name: GGA - git branches
Description: Dashboard Widget
Author: Pete Nelson
Version: 1.0
*/
if (!defined( 'ABSPATH' )) exit('restricted access');
@petenelson
petenelson / custom-post-type-columns-array-insert.php
Last active August 29, 2015 13:58
WordPress: Custom post type columns with array insert
function array_insert($array, $values, $offset) {
// http://stackoverflow.com/questions/1783089/array-splice-for-associative-arrays/11114956#11114956
return array_slice($array, 0, $offset, true) + $values + array_slice($array, $offset, NULL, true);
}
function admin_columns($columns) {
// this is the 'manage_edit-{post-type}_columns' filter
// add_filter( 'manage_edit-' . self::$post_type . '_columns', array($this, 'admin_columns'), 10, 1 ) ;
$columns = array_insert($columns, array('sales-channel' => 'Sales Channel'), 2);
return $columns;
@petenelson
petenelson / get-term-by-value.php
Created February 28, 2014 21:22
WordPress: Advanced Custom Fields, find taxonomy term by custom value
function get_term_by_value($taxonomy, $field, $value) {
// probably a better way to do this, but this works for now
// get_field is part of Advanced Custom Fields
if (function_exists('get_field')) {
foreach (get_terms( $taxonomy ) as $term) {
$field = get_field($field, $term);
if ($value == $field)
return $field;
}
@petenelson
petenelson / login-cookie-timeout.php
Last active August 29, 2015 13:56
WordPress: change login cookie timeout