Skip to content

Instantly share code, notes, and snippets.

@robhadfield
robhadfield / gist:2185612
Created March 24, 2012 17:54
JS: hash substring
eg: URL: yayhooray.net/#foo!bar
var $str = window.location.hash;
var $substr = $str.split('!');
alert($str); // #foo!bar
alert($substr[0]); // #foo
alert($substr[1]); // bar
@robhadfield
robhadfield / wp_insert_post_front_end_form.php
Created August 23, 2012 07:48 — forked from clarklab/wp_insert_post_front_end_form.php
This is a sample front-end form using wp_insert_post(). It's quickly stripped out of my production code from Android and Me, and hasn't been tested alone, so please take it with a grain of salt.
<?
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['insert_post'] )) { //check that our form was submitted
$title = $_POST['thread_title']; //set our title
if ($_POST['thread_description']=="") { // check if a description was entered
$description = "See thread title..."; // if not, use placeholder
} else {
$description = $_POST['thread_description']; //if so, use it
[
{
"meta_id":6,
"post_id":10,
"meta_key":"_wp_page_template",
"meta_value":"default"
},
{
"meta_id":512,
"post_id":10,
{
size: 'desktop',
widgets:
[
{
"w": 14,
"h": 24,
"x": 0,
"y": 0,
"i": "are_dashboard",
{
lg: [
{ i: 'are_dashboard',
x: 0,
y: 0,
w: 14,
h: 24
},
{ i: 'combined_are',
Mobile Settings Array:
[{"i":"are_dashboard","x":0,"y":0,"w":12,"h":20},{"i":"combined_are","x":0,"y":20,"w":6,"h":16},{"i":"combined_tt","x":6,"y":20,"w":6,"h":16},{"i":"reset","x":0,"y":36,"w":6,"h":3,"isResizable":false},{"i":"time","x":0,"y":56,"w":6,"h":10},{"i":"news","x":6,"y":46,"w":6,"h":20},{"i":"school_switch","x":12,"y":36,"w":6,"h":10},{"i":"bookmarks","x":0,"y":39,"w":6,"h":17}]
Tablet Settings Array:
[{"i":"are_dashboard","x":0,"y":0,"w":6,"h":20},{"i":"combined_are","x":6,"y":0,"w":3,"h":20},{"i":"combined_tt","x":9,"y":0,"w":3,"h":20},{"i":"reset","x":0,"y":20,"w":6,"h":3,"isResizable":false},{"i":"time","x":0,"y":40,"w":6,"h":10},{"i":"news","x":6,"y":30,"w":6,"h":20},{"i":"school_switch","x":6,"y":20,"w":6,"h":10},{"i":"bookmarks","x":0,"y":23,"w":6,"h":17}]
Desktop Settings Array:
import React, {Component} from 'react';
import {reduxForm, change} from 'redux-form';
var { connect } = require('react-redux');
var { fetchSchoolByID, saveSchool } = require('../../../reducers/school');
export const fields = [ 'TrustID', 'LEAID', 'SchoolTypeId', 'Name', 'HeadTeacher', 'Email', 'Telephone', 'ImagePath', 'Notes' ];
var form = reduxForm({
form: 'schoolDetails',
@robhadfield
robhadfield / has_class.js
Created April 15, 2016 12:32 — forked from jjmu15/has_class.js
has class function - vanilla JS. Check if element has specified class
// hasClass, takes two params: element and classname
function hasClass(el, cls) {
return el.className && new RegExp("(\\s|^)" + cls + "(\\s|$)").test(el.className);
}
/* use like below */
// Check if an element has class "foo"
if (hasClass(element, "foo")) {
@robhadfield
robhadfield / meta_data_query.php
Created February 4, 2016 17:09
WP SQL for pulling meta_data as "Key" -> "Value" pairs
// Example ID
$id = '1';
// DB connection and query
global $wpdb;
$rows = $wpdb->get_results(
"
SELECT $wpdb->postmeta.meta_key, $wpdb->postmeta.meta_value
FROM $wpdb->postmeta
WHERE
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/normalize.min.css">