Skip to content

Instantly share code, notes, and snippets.

View hellofromtonya's full-sized avatar

Tonya Mork hellofromtonya

View GitHub Profile
@hellofromtonya
hellofromtonya / hoisting-example.js
Created April 7, 2016 18:19
JavaScript Hoisting Example
(function ( document, $, undefined ) {
/*****
* SHOWING HOISTING WITH A VARIABLE
*/
// Let me show hoisting to you by demonstrating a variable and it's
// initialization with a value
// 1. You get "undefined" here - but NOT an error.
console.log( hoistingVariable );
var hoistingVariable = 'I am initializing it now.';
@hellofromtonya
hellofromtonya / user_helpers.php
Created June 11, 2015 16:43
Fetching User Meta by Role
<?php
/**
* Fetch user meta for the specified role and return user ID, first name, and last name
*
* @since 1.0.0
*
* @param string $role
* @return array
*/
@hellofromtonya
hellofromtonya / challenge_05182015.php
Created May 19, 2015 00:53
WordPress Challenge for May 18, 2015
<?php
/**
* As part of our weekly challenges, take a crack at this one.
* To play along,
* 1. Copy the code into a Gist,
* 2. Answer each of the questions by supplying the code;
* 3. Provide some notes as to your train of thought;
* 4. Then submit the gist's URL for us to review.
*
@hellofromtonya
hellofromtonya / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hellofromtonya
hellofromtonya / restrict-media-library.php
Created May 13, 2015 16:01
Restrict Media Library by User Role
<?php
/**
* Restrict Media Library by User Role
*
* @package Restrict_Media_Library
* @since 1.0.0
* @author hellofromTonya
*/
/**
@hellofromtonya
hellofromtonya / challenge.php
Created May 6, 2015 09:15
WordPress Developers Club Challenge - What is the SQL to get the count of all post meta where post ID = 1?
/**
* Get the number of meta for a specific Post ID
*
* @since 1.0.0
*
* @param integer $post_id Post ID to query for
* @return integer Returns the count number
*/
function tonya_get_meta_count_for_post_id( $post_id ) {
@hellofromtonya
hellofromtonya / class-meta.php
Created April 27, 2015 17:16
WordPress Developers' Club Tutorial - Variable Variables - Meta Class Demo
<?php namespace WPDevsClub_Lesson_Var_Vars;
class Meta implements I_Meta {
protected $post_id = 0;
protected $meta_key = '';
protected $defaults = array();
@hellofromtonya
hellofromtonya / variable-variables.php
Created April 27, 2015 16:57
Variable Variables Tutorial in WordPress
<?php
$variable_name = 'post_id';
$$variable_name = 10;
//* Or use curly braces to specify exactly which variable is being used
//* as the variable variable, i.e. variable name
${$variable_name} = 10;
/**
@hellofromtonya
hellofromtonya / math.php
Created April 21, 2015 08:49
Demo Calculator to illustrate Closure Dependency Injection
<?php namespace wpdevsclub_demo;
use Closure;
class Calculator {
public function solve( Closure $expression, $args ) {
if ( is_callable( $expression ) ) {
return $expression( $args );
@hellofromtonya
hellofromtonya / front-page.php
Last active August 29, 2015 14:19
PHP Closure used as a hook callback for WordPress
<?php
/**
* Add class to the HTML Body tag
*
* @since 1.0.0
*
* @param array $classes
* @return array
*/