Skip to content

Instantly share code, notes, and snippets.

View hlashbrooke's full-sized avatar
🎲

Hugh Lashbrooke hlashbrooke

🎲
View GitHub Profile
@hlashbrooke
hlashbrooke / query.sql
Created July 12, 2013 11:14
Find duplicate field values in MySQL
SELECT email_address, COUNT(email_address) AS occurrences
FROM users
GROUP BY email_address
HAVING occurrences > 1
@hlashbrooke
hlashbrooke / markup.html
Last active December 19, 2015 16:28
Two methods for vertical centering in CSS
<div id="outer">
<div id="inner">Element to be aligned</div>
</div>
@hlashbrooke
hlashbrooke / function.php
Created July 12, 2013 11:16
WordPress: Add featured image to RSS feed
<?php
add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
$content = $output . $content;
}
}
@hlashbrooke
hlashbrooke / filter.php
Created July 12, 2013 11:17
Make your WordPress content editor use HTML by default
<?php
add_filter( 'wp_default_editor', 'set_html_content_editor' );
function set_html_content_editor( $tab ) {
$tab = 'html';
return $tab;
}
?>
@hlashbrooke
hlashbrooke / function.php
Created July 12, 2013 11:18
Simple way to generate a random string/password in PHP
<?php
function random_password( $length = 8 ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
$password = substr( str_shuffle( $chars ), 0, $length );
return $password;
}
?>
@hlashbrooke
hlashbrooke / markup.html
Last active December 19, 2015 16:29
CSS: Semi-transparent background behind opaque text
<div class="container">Lorem ipsum dolor</div>
@hlashbrooke
hlashbrooke / class1.php
Last active May 26, 2020 01:03
WordPress: Use checkbox term selection for non-hierarchical taxonomies - http://www.hughlashbrooke.com/wordpress-use-checkbox-term-selection-for-non-hierarchical-taxonomies/
<?php
class Tag_Checklist {
private $taxonomy;
private $post_type;
function __construct( $taxonomy, $post_type ) {
$this->taxonomy = $taxonomy;
$this->post_type = $post_type;
@hlashbrooke
hlashbrooke / style.css
Created August 7, 2013 06:15
WooCommerce Email Validation: Fix field layout when field appears on the right
#billing_email-2_field { float: right; }
@hlashbrooke
hlashbrooke / analytics-wordpress.php
Created August 9, 2013 16:26
Segment.io WordPress plugin: Adding filter to identification traits
<?php
$identify = array(
'user_id' => $user->user_email,
'traits' => apply_filters( 'segment_identify_traits', array(
'username' => $user->user_login,
'email' => $user->user_email,
'name' => $user->display_name,
'firstName' => $user->user_firstname,
'lastName' => $user->user_lastname,
'url' => $user->user_url
@hlashbrooke
hlashbrooke / function.php
Created August 21, 2013 11:01
WooCommerce: Get all order statuses as an array
<?php
function woocommerce_get_order_statuses() {
$order_statuses = get_terms( 'shop_order_status', array( 'hide_empty' => false ) );
$statuses = array();
foreach ( $order_statuses as $status ) {
$statuses[ $status->slug ] = $status->name;
}
return $statuses;
}
?>