Skip to content

Instantly share code, notes, and snippets.

@hattmarris
hattmarris / gist:728aac5dcb0f2f7f4db8
Last active August 29, 2015 14:11
Create WP dashicon for Custom Post Type within a class
<?php
class CLASSNAME {
public function __construct() {
add_action( 'admin_head', array($this, 'classname_add_menu_icons_styles') );
}
public static function classname_add_menu_icons_styles() {
?>
<style>
#adminmenu .menu-icon-post_type div.wp-menu-image:before {
content: "\f323";
@hattmarris
hattmarris / gist:dadcb72ff0b9fd8858e1
Last active August 29, 2015 14:13
Simple WordPress Contact Form
<?php
if($_POST['submit'] == 'Submit') {
//prevent injection
if (!isset( $_POST['contact_form_nonce'] ) || ! wp_verify_nonce( $_POST['contact_form_nonce'], 'submit_contact_form' ) ) {
print 'Sorry, your nonce did not verify.';
exit;
}
//prevent spam
if(isset($_POST['foo']) && trim($_POST['foo']) != '') {
print 'Sorry, your submission has failed.';
<?php
// Pretty print an array to browser for
// debug / examination purposes
echo '<pre>'; print_r($array); echo '</pre>';
?>
@hattmarris
hattmarris / hour-select.js
Last active August 29, 2015 14:21
Creates options as 24 hour increments for an HTML select element
/**
* Creates options as 24 hour increments for an HTML select element
*
* @param {string} id: the element id of the select node
* @param {string} defaultTime: the default time at hh:mm:ss resolution for the select to display when loaded
*/
function createHourSelect(id, defaultTime) {
var select = document.getElementById(id);
var hours = 24;
for(i=0; i < hours; i++) {
@hattmarris
hattmarris / git.sh
Last active September 1, 2015 18:26
Git Commands
# Create new branch
git checkout -b <branchname>
# Push branch to remote
git push -u origin <branchname>
# Merge branch back in
git checkout master
git merge <branchname>
@hattmarris
hattmarris / strip-text.php
Created June 14, 2015 05:53
Strip plain text (leave HTML tags) from all posts in WordPress loop
<?php
$args = array(
'post_type' => 'post' // just query for all posts
);
$query = new WP_Query($args); // create new WP_Query object
if($query->have_posts()) {
while($query->have_posts()) {
$query->the_post();
@hattmarris
hattmarris / addCallToArray.js
Created July 30, 2015 22:55
addCallToArray
var i = 0;
var calls = {};
function addCallToArray(termId) {
var k = 'call-' + i;
calls[k] = termId;
i++;
}
console.log(calls);
@hattmarris
hattmarris / jquery-equivalents.js
Created August 7, 2015 20:46
JQuery with Native JS
// Assuming we have a jQuery ui autcomplete loaded...
// jQuery listener
$(domain).on('autocompleteclose', callback);
// Native listeners functionally equivalent to 'autocompleteclose' listener
domain.addEventListener('blur', callback);
domain.addEventListener('focusout', callback);
var ul = document.querySelector('.ui-autocomplete');
ul.addEventListener('click', callback);
@hattmarris
hattmarris / localStorage.js
Last active August 29, 2015 14:27
Local Storage example
// example data
var calls = {
matt: {
number: "8587645224",
id: "call-id-hash",
timestamp: "08-10-2015"
},
mark: {
number: "8587645232",
id: "call-id-hash",
// define example vars
var dataList = document.getElementById('suggestions'),
letters = 'abcdefghijklmnopqrstuvwxyz',
choices = letters.split(''),
doubled = [];
// doubled letters
for(var i in choices) {
var s = choices[i] + choices[i];
doubled.push(s);