Skip to content

Instantly share code, notes, and snippets.

View mattmcgiv's full-sized avatar
😎

Matt McGivney mattmcgiv

😎
View GitHub Profile
@mattmcgiv
mattmcgiv / enqueue-javascript.php
Last active August 29, 2015 14:25
enqueue javascript in WordPress
<?php
wp_enqueue_script('whatev-handle', __FILE__ . '/js/script.js', 'jquery', true);
/*
* Usage:
* wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
*
* @param string $handle Name of the script.
* @param string|bool $src Path to the script from the root directory of WordPress. Example: '/js/myscript.js'.
* @param array $deps An array of registered handles this script depends on. Default empty array.
@mattmcgiv
mattmcgiv / category.php
Created August 17, 2015 19:27 — forked from wpsmith/category.php
Custom Genesis Category Template with Pagination
<?php
/**
* Custom Category Template
*
* @package my_child_theme
* @since 1.0.0
* @author Travis Smith <t@wpsmith.net>
* @copyright Copyright (c) 2013, Travis Smith
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @link https://gist.github.com/wpsmith/5062834
@mattmcgiv
mattmcgiv / gist:198b0e3980efe5a75922
Created September 11, 2015 17:40
Some markup for a mapping app (h2h)
<span id="main-feedback" class="inline-block mt2" style="width:100%;">
<span class="col col-4 h2 inline-block left-align">Charge:<br><span class="h2">$225<span></span></span></span>
<span class="col col-4 inline-block left-align">
<form action="">
<input class="mb2" type="radio" value="am" name="tod">Daytime<br>
<input type="radio" name="tod" value="pm">After-hours
</form>
</span>
<span class="col col-4 inline-block left-align">
<span class="h3 block">Region: North</span>
@mattmcgiv
mattmcgiv / gist:45cb0ab7a21e34f909ad
Last active September 22, 2015 17:29
Unit test template
/*
Ref: https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d
What are you testing?
What should it do?
What is the actual output?
What is the expected output?
How can the test be reproduced?
@mattmcgiv
mattmcgiv / gist:a060bf2a0909372aab5b
Created October 6, 2015 19:51
WordPress does post exist (by id)?
<?php
/**
* Determines if a post, identified by the specified ID, exist
* within the WordPress database.
*
* Note that this function uses the 'acme_' prefix to serve as an
* example for how to use the function within a theme. If this were
* to be within a class, then the prefix would not be necessary.
*
* @param int $id The ID of the post to check
@mattmcgiv
mattmcgiv / security_io.php
Created October 29, 2015 17:46
Some useful functions for sanitization, validation, and escaping output
<?php
function mm_sanitize($unsanitized_input) {
//calls a WordPress core function
//verifies UTF-8 encoding, strips tags
//removes whitespace/newlines & octets
//reference:
//https://codex.wordpress.org/Function_Reference/sanitize_text_field
return sanitize_text_field($unsanitized_input);
}
@mattmcgiv
mattmcgiv / gulpfile.js
Created November 4, 2015 19:37
Gulpfile.js with jshint, sass, concat, uglify, and rename setup for WordPress theme development
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
@mattmcgiv
mattmcgiv / CursorReader.java
Created January 3, 2016 01:39
Read a Cursor in Android
//Cursor named "result"
//if statement makes sure we actually got back some data from the db
if (result.moveToFirst() != false) {
//for each row (representing a row of db)
while (result.moveToNext() != false) {
//for each column, representing a value from the row
for (int i = 0; i < result.getColumnCount(); i++) {
Log.d("Name of db column: ", result.getColumnName(i));
String val = result.getString(i);
Log.d("Value for column: ", val);
@mattmcgiv
mattmcgiv / gulpfile.js
Created January 4, 2016 19:20
Sample gulpfile to get started
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
array(
'name' => __( 'My Number Field', 'theme-domain' ),
'desc' => __( 'Numbers only', 'msft-newscenter' ),
'id' => $prefix . 'number',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
),