Skip to content

Instantly share code, notes, and snippets.

View devinsays's full-sized avatar

Devin Price devinsays

View GitHub Profile
@devinsays
devinsays / sanitize_hex_color.php
Last active September 10, 2015 18:14
sanitize_hex_color
/**
* Duplicate the sanitize_hex_color function, which is generally
* only available to the theme customizer.
*/
if ( !function_exists( 'sanitize_hex_color' ) ) {
function sanitize_hex_color( $color ) {
if ( '' === $color )
return '';
// 3 or 6 hex digits, or the empty string.
@devinsays
devinsays / zendesk-api.php
Created September 23, 2015 02:55
Command Line PHP script to fetch e-mail addresses for all tickets that containing a specific term.
<?php
/**
* Script Name: Zendesk API Command Line
* Description: Run directly from the command line using "php -f zendesk-api.php $query".
* Version: 1.0.0
* Author: Devin Price
*/
// Credentials not stored in version control, request in order to run script
$id = 'user@example.com';
@devinsays
devinsays / wc-tracking-products-example.php
Created June 29, 2015 17:49
Example of WooCommerce Conversion Tracking for Products
function prefix_service_conversion_tracking( $order_id ) {
// Lets grab the order
$order = new WC_Order( $order_id );
// Products
$products = $order->get_items();
?>
<script>
<?php
function prefix_enqueue_custom_script(){
wp_register_script( 'prefix_custom_script', plugin_dir_url( __FILE__ ) .'js/custom-script.js', array( 'jquery' ) );
wp_enqueue_script( 'prefix_custom_script' );
wp_localize_script( 'prefix_custom_script', 'optionsframework', array(
'hello' => __( 'Hello', 'textdomain' ),
'goodbye' => __( 'Good Bye', 'textdomain' )
) );
}
<?php
/* Add a checkbox to the featured image metabox */
add_filter( 'admin_post_thumbnail_html', 'theme_featured_image_meta');
function theme_featured_image_meta( $content ) {
global $post;
// Text for checkbox
$text = __( "Don't display image on post.", 'textdomain' );
@devinsays
devinsays / postLoadImages
Created March 18, 2013 04:50
jQuery Plugin for post loading images
// jQuery Plugin for post loading images
$.fn.postLoadImages = function(callback) {
var imgLen = this.length,
count = 0;
return this.each(function(count) {
count++;
if ($(this).attr('data-src')) {
var imgTag = this, imgSrc = $(this).attr('data-src');
i = new Image();
@devinsays
devinsays / gist:5210667
Created March 21, 2013 04:22
Adds a "has-children" class to menu items that have children. Posted by @chipbennet to the Theme Reviewers Mail List.
function oenology_add_menu_parent_class( $items ) {
$parents = array();
foreach ( $items as $item ) {
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
}
foreach ( $items as $item ) {
@devinsays
devinsays / authenticate-by-email.php
Last active January 4, 2016 01:14
Allows visitors to log in using e-mail address
<?php
/**
* Allows visitors to log in using e-mail address
*
* @param string username passed by reference
*/
function prefix_authenticate_by_email( &$username ) {
$user = get_user_by( 'email', $username );
@devinsays
devinsays / custom-logo-update-script.php
Last active April 17, 2016 12:49
Code snippet for update script to use new theme logo
<?php
/**
* Theme Update Script
*
* Runs if version number saved in theme_mod "version" doesn't match current theme version.
*/
function prefix_update_check() {
$ver = get_theme_mod( 'version', false );
@devinsays
devinsays / gist:705f9e9de5cd2a9cb16f
Created February 3, 2015 17:21
Display Page Selection in Template
<?php
// Get pages set in the customizer (if any)
$pages = array();
for ( $count = 1; $count <= 5; $count++ ) {
$mod = get_theme_mod( 'showcase-page-' . $count );
if ( 'page-none-selected' != $mod ) {
$pages[] = $mod;
}
}