Skip to content

Instantly share code, notes, and snippets.

View thefrosty's full-sized avatar
🏖️
Santa Monica WordPress Developer

Austin Passy thefrosty

🏖️
Santa Monica WordPress Developer
View GitHub Profile
Why is this returning an empty array()?
$order-items->name = empty array()
$order->items =
[items] => Array
(
[0] => Array
(
[id] => 88
@thefrosty
thefrosty / php array
Created February 23, 2012 22:01
Trying to get array settings
function get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters( 'editable_roles', $all_roles );
$options = array();
foreach ( $editable_roles as $roles ) {
foreach( $roles as $role ) {
$options[] = array( $role => $role );
@thefrosty
thefrosty / gist:2604443
Created May 5, 2012 18:07
Custom query to grab posts from the same day..
global $post;
$args = array(
'post__not_in' => array( $post->ID ),
'posts_per_page'=> -1,
'day' => get_the_time( 'd', $post->ID ),
'month' => get_the_time( 'm', $post->ID ),
'year' => get_the_time( 'Y', $post->ID ),
);
$the_query = new WP_Query( $args );
@thefrosty
thefrosty / array_rand
Created May 21, 2012 18:56
Random array
$ads = array('<a href="#">Sponsored link 1</a>', '<a href="#">Sponsored link 2</a>', '<a href="#">Sponsored link 3</a>');
echo $ads[array_rand($ads, 1)];
OR
$numb = rand( 1, 3 );
if ( $numb == 1 )
echo '<a href="#">Sponsored link 1</a>';
@thefrosty
thefrosty / WordPress md5 shortcode
Created August 6, 2012 21:27
Get the md5 hash of an email for gravatar or other purposes.
add_shortcode( 'md5', 'md5_email_hash' );
function md5_email_hash( $atts ) {
extract( shortcode_atts( array(
'hash' => '',
), $atts ) );
$hash = ( isset( $_GET['email'] ) && !empty( $_GET['email'] ) ) ? $_GET['email'] : $hash;
$hash = is_email( $hash ) ? sanitize_email( strtolower( $hash ) ) : trim( $hash );
@thefrosty
thefrosty / gist:3417988
Created August 21, 2012 18:09
Autoset Featured Image
function autoset_featured() {
global $post;
if ( empty( $post ) ) return;
$already_has_thumb = has_post_thumbnail( $post->ID );
if ( !$already_has_thumb ) {
$attached_image = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => '1' ) );
if ( $attached_image ) {
@thefrosty
thefrosty / avery74459
Created September 11, 2012 19:34
Set badge location.
<?php
// http://www.avery.com/avery/en_us/Products/Name-Badges/Name-Badges/Insertable-Name-Badges_74459.htm (3" X 4")
// Add a page, but only on a multiple of 6
if ( $counter == 1 || ( $counter % 7 == 0 ) ) {
$pdf->AddPage('P', 'Letter');
$counter = 1;
}
// Set the co-ordinates for all items in each of the badges
switch ( $counter ) {
@thefrosty
thefrosty / gist:3835942
Created October 4, 2012 19:47
Returns Undefined index
$defaults = array(
'company' => 'client_company',
'address_1' => 'client_address_1',
'address_2' => 'client_address_2',
'city' => 'client_city',
'state' => 'client_state',
'postcode' => 'client_postcode',
'country' => 'client_country'
);
@thefrosty
thefrosty / activate edd download
Created December 1, 2012 23:22
Activation of plugin through EDD
function validate_license() {
//print '<pre>' . print_r( $_POST, true ) . '</pre>';
//print '<pre>' . print_r( $this->settings_sections, true ) . '</pre>';
//exit;
$data = array();
foreach ( $this->settings_sections as $section ) {
@thefrosty
thefrosty / get my account pages
Last active December 10, 2015 16:08
The function works fine, but the $my_account and $my_account_pages are not merging. Getting an empty array in $my_account after merge. Not before though. Thoughts?
function get_extendd_my_account_pages() {
$all_wp_pages = wp_cache_get( 'extendd_my_account_pages' );
if ( false === $all_wp_pages ) {
// Set up the objects needed
$the_query = new WP_Query();
$all_wp_pages = $the_query->query( array( 'post_type' => 'page' ) );
wp_cache_set( 'extendd_my_account_pages', $all_wp_pages );
}