Skip to content

Instantly share code, notes, and snippets.

View kodie's full-sized avatar

Kodie Grantham kodie

View GitHub Profile
@kodie
kodie / uksort_year-dsc_day-asc.php
Last active November 25, 2015 18:57
Sort an array with dates for keys by year descending and day ascending.
function cmp($a, $b) {
$a = date('c', strtotime($a));
$b = date('c', strtotime($b));
$ay = date('Y', strtotime($a));
$by = date('Y', strtotime($b));
if ($a == $b) {
$r = 0;
} else {
if ($ay < $by) {
@kodie
kodie / show_current_template.php
Last active November 25, 2015 18:57
Find out what template file a page is using
function show_current_template($wp_admin_bar) {
global $template;
$args = array(
'id' => 'current_template',
'title' => 'Current Template: '.basename($template),
'meta' => array('title'=>$template)
);
$wp_admin_bar->add_node($args);
}
if (current_user_can('manage_options') && !is_admin()) { add_action('admin_bar_menu', 'show_current_template', 9999); }
@kodie
kodie / is_page.js
Created September 11, 2015 18:10
is_page function in jQuery for Wordpress
function is_page($pageid) {
if (jQuery('body').hasClass('page-id-'+$pageid)) { return true; } else { return false; }
}
@kodie
kodie / breakpoint.js
Last active November 25, 2015 18:56
Get current page breakpoint
function currentBreakpoint() {
var sm = 768;
var md = 992;
var lg = 1200;
var bp;
var win = window.innerWidth;
if (win < sm) { bp = 'xs'; }
if (win >= sm && win < md) { bp = 'sm'; }
if (win >= md && win < lg) { bp = 'md'; }
if (win >= lg) { bp = 'lg'; }
@kodie
kodie / functions.php
Created October 1, 2015 20:28
Allow additional file types to be uploaded to Wordpress
<?php
function add_mime_types($mime_types) {
$mime_types['qbb'] = 'application/octet-stream';
return $mime_types;
}
add_filter('upload_mimes', 'add_mime_types', 1, 1);
?>
@kodie
kodie / untitled
Last active December 15, 2016 18:39
Find PHP Short Tags
<\?(?!php)(?!xml)(?!=)
@kodie
kodie / fancyBox_pause_bootstrap_carousel.js
Created November 10, 2015 19:30
Pause Bootstrap's Carousel when fancyBox is opened and start again when fancyBox is closed.
@kodie
kodie / printImage.js
Last active June 6, 2016 21:43
Print just an image from a page.
function printImage(image, title) {
var winContent = "<html><head><title>" + title + "</title><script>function step1(){\n" +
"setTimeout('step2()', 10);}\n" +
"function step2(){window.print();window.close()}\n" +
"</scri" + "pt></head><body onload='step1()'>\n" +
"<img src='" + image + "' /></body></html>";
var win = window.open('about:blank', '_new');
win.document.open();
win.document.write(winContent);
@kodie
kodie / has_term_descendant.php
Last active June 6, 2016 21:44
Find out if post has a term that is the descendant of another term.
function has_term_descendant($parent_term, $taxonomy, $post_id = null) {
if (empty($post_id)) { $post_id = get_the_ID(); }
$terms = get_the_terms($post_id, $taxonomy);
if (!empty($terms)) {
foreach ($terms as $term) {
if (term_is_ancestor_of($parent_term, $term, $taxonomy)) {
return true;
}
@kodie
kodie / submit-form.php
Last active June 6, 2016 21:43
Use this if you want your form to be submitted to a third party but also want to verify reCAPTCHA before it gets sent. You need to make a hidden input called 'sendURL' and in the value put the URL that you would like the form to be submitted to.
<?php
ob_start();
session_start();
require_once('recaptchalib.php');
$key_public = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$key_private = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$captchaFailed = false;