Skip to content

Instantly share code, notes, and snippets.

View petenelson's full-sized avatar

Pete Nelson petenelson

View GitHub Profile
@petenelson
petenelson / rest-api-modify-request-parameters.php
Created August 26, 2015 18:46
WordPress REST API: Modify Request Parameters
<?php
add_filter( 'rest_dispatch_request', 'map_legacy_parameters', 10, 2 );
function map_legacy_parameters( $response, $request ) {
$request->set_param( 'per_page' , $request->get_param( 'limit' ) );
return $response;
}
@petenelson
petenelson / gga-set-featured-image-from-url.php
Created February 5, 2014 16:01
WordPress: Download and set featured image for a post from a URL
@petenelson
petenelson / state-list.php
Created February 6, 2014 16:08
PHP: Return list of states as an array
function state_list() {
return array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
@petenelson
petenelson / set-a-cookie.php
Created February 17, 2014 18:24
PHP: Set a cookie
@petenelson
petenelson / admin-hook-on-plugin-load.php
Created February 19, 2014 19:59
WordPress: Admin hook for plugin loading
// can be run inside of an admin_init hook
global $pagenow;
global $plugin_page;
add_action('load-' . get_plugin_page_hook($plugin_page, $pagenow), 'my_function' );
@petenelson
petenelson / login-cookie-timeout.php
Last active August 29, 2015 13:56
WordPress: change login cookie timeout
@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;
<?php
/*
Plugin Name: GGA - git branches
Description: Dashboard Widget
Author: Pete Nelson
Version: 1.0
*/
if (!defined( 'ABSPATH' )) exit('restricted access');
@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'] );
@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 );
}
}