Skip to content

Instantly share code, notes, and snippets.

var getWPJRA = function( baseUrl, child , callback){
if (baseUrl !== undefined ){
switch( child ) {
case undefined:
return jQuery.getJSON( '/' + baseUrl + "/wp-json" , callback);
break;
default:
return jQuery.getJSON( '/' + baseUrl + "/wp-json/" + child, callback);
}
} else if (baseUrl === undefined || baseUrl.length == 0) {
function add_countries(){
$country_array = array(
"afg" => "Afghanistan",
"alb" => "Albania",
"dza" => "Algeria",
"and" => "Andorra",
"ago" => "Angola",
"atg" => "Antigua and Barbuda",
"arg" => "Argentina",
"arm" => "Armenia",
@viankakrisna
viankakrisna / ml_restrict_media_library.php
Created November 17, 2015 09:36
Restrict non admin to only show image that they upload
add_action( 'pre_get_posts', 'ml_restrict_media_library' );
function ml_restrict_media_library( $wp_query_obj ) {
global $current_user, $pagenow;
if (!in_array( 'administrator', $current_user->roles )){
if( !is_a( $current_user, 'WP_User') )
return;
if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
@viankakrisna
viankakrisna / mobiledesktop.js
Last active May 26, 2017 18:59
Mobile and Desktop Responsive Layout Handler
var mobileManager = function (mobile, desktop, breakpoint) {
//Defaults to 767, not much desktop running below that right now isn't it?
var _breakpoint = breakpoint || 767;
//Defaults to function, we need to invoke this later
var _desktop = desktop || function () {};
var _mobile = mobile || function () {};
//Counter to see where we are right now
@charset "UTF-8";
@import "https://fonts.googleapis.com/css?family=Oswald";
* {
animation: fadeIn 1s;
}
a {
transition: 250ms;
}
@viankakrisna
viankakrisna / jQuery Dump
Last active January 12, 2016 12:02
This is a jQuery plugin for dumping variable to a JSON string.
(function ($) {
$.fn.dump = function (variable) {
this.html($('<pre></pre>')
.text(JSON.stringify(variable, null, 4)));
return this;
};
})(jQuery);
//How to use:
/*
@viankakrisna
viankakrisna / sidebar_hook.php
Created January 14, 2016 08:46
Calibrefx Dynamic Sidebar (Create and display sidebar based on post type)
<?php
add_action( 'widgets_init', 'childfx_widgets_init' );
function childfx_widgets_init() {
//TODO: Create setting in admin area for this variable
$post_type = array(
'news',
'post'
);
@viankakrisna
viankakrisna / sidebar_hook.php
Last active January 19, 2016 15:45
Calibrefx Dynamic Sidebar (Create sidebar anywhere in calibrefx hooks)
<?php
class Calibrefx_Dynamic_Sidebars {
private $i;
private $sidebars;
function __construct(){
$this->i = 0;
@viankakrisna
viankakrisna / toggleclass.js
Last active August 26, 2021 16:49
toggle class without jQuery
document.getElementById('menu-button').onclick = function() {
document.getElementsByTagName('header')[0].classList.toggle('menu-open');
document.querySelector('div.content').classList.toggle('menu-open');
document.querySelector('nav').classList.toggle('menu-open');
return false;
};
@viankakrisna
viankakrisna / proxy.php
Created February 10, 2016 15:33
PHP Proxy, enabling live AJAX JSON endpoint to use for local
<?php
$request = http_build_query($_GET);
$server = 'HTTP://YOURSERVERAJAXENDPOINT';
function getCurrentUri(){
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
$uri = '/' . trim($uri, '/');