Skip to content

Instantly share code, notes, and snippets.

View carmichaelize's full-sized avatar

Scott Carmichael carmichaelize

View GitHub Profile
@carmichaelize
carmichaelize / shortcode.php
Last active August 29, 2015 14:00
Wordpress Shortcode Wrapper
<?php
class shortcode {
//Shortcode name
public $name = 'shortcode_name'
//Default attributes
public $args = array();
@carmichaelize
carmichaelize / custom_post_type.php
Last active August 29, 2015 14:00
Wordpress Custom Post Type Wrapper
<?php
class custom_post_type {
//Custom post type name
public $post_type_name = 'name';
//Custom metabox key
public $key = $this->post_type_name = 'key';
@carmichaelize
carmichaelize / custom_metabox.php
Last active August 29, 2015 14:00
Wordpress Metabox Wrapper
<?php
class custom_metabox {
//Custom metabox key
public $key = 'meta_box_key';
//Custom metabox options
public $options = array(
'post_types' => get_post_types(),
@carmichaelize
carmichaelize / twitter_regex.php
Last active September 17, 2017 08:54
Twitter Links, Mentions and Hashtag Regex
<?php
//Urls
$tweet = preg_replace('/(http[^\s]+)/', '<a target="_blank" class="tweet-link" href="$1">$1</a>', $tweet->text);
//Mentions
$tweet = preg_replace('/\@([a-zA-Z1-9]+)/', '<a title="@$1" target="_blank" href="https://twitter.com/$1" class="tweet-user">@$1</a>', $string);
//Hashtags
$tweet = preg_replace('/#([a-zA-Z1-9]+)/', '<a title="#$1" target="_blank" href="https://twitter.com/search?q=%23$1&src=hash" class="tweet-hashtag">#$1</a>', $string);
@carmichaelize
carmichaelize / wp_api_query.php
Last active August 29, 2015 14:00
Wordpress Transients & API Calls
<?php
//Get transient data
$data = get_transient( 'data_key' );
//Check transient data exists
if(!$data){
//Query API
angular.module('myApp.services', [])
.service('$_http', function($http, $q, $compile) {
//Serialize Parameters
var $param = function(obj){
var query = '',
name, value, fullSubName, subName, subValue, innerObj, i;
for(name in obj){
@carmichaelize
carmichaelize / map_ui.js
Created July 10, 2014 14:26
Google Maps API Framework
var ui = {
buildMarkers: function( data, first ){
var results = [];
$.each( data, function(i, marker){
var html = ui.buildHTML( marker.title, marker.address, marker.telephone );
@carmichaelize
carmichaelize / wp_pagination.php
Last active August 29, 2015 14:04
Wordpress Query Pagination Function
<?php
function sc_pagination( $query ){
$string = "";
if( !$query ){
global $wp_query;
@carmichaelize
carmichaelize / base64_encode_decode.js
Last active August 29, 2015 14:07
JavaScript Base64 Encode/Decode
//Encode
function encodeBase64( string ){
try{
if( typeof string == 'object'){
throw 'error';
}
return window.btoa(unescape(encodeURIComponent( string )));
} catch(e){
return false;
@carmichaelize
carmichaelize / scroll-button.js
Last active August 29, 2015 14:07
jQuery Scroll Button
//Scroll Button
function windowScroll(event){
$('html, body').animate({scrollTop: event.data}, 1000);
return false;
}
//Scroll top top
$('#too-top').on('click', 0, windowScroll);
//Scroll to footer