Skip to content

Instantly share code, notes, and snippets.

View MikeNGarrett's full-sized avatar
🤘
Rocking this project.

Mike Garrett MikeNGarrett

🤘
Rocking this project.
View GitHub Profile
@MikeNGarrett
MikeNGarrett / event-category-list.php
Created August 5, 2012 23:45 — forked from jo-snips/event-category-list.php
The Events Calendar: List Event Categories
<?php // If you'd rather have category drop downs ?>
<form action="#" method="get" id="event-change">
<?php
$current = get_query_var('tribe_events_cat');
$terms = get_terms($tribe_ecp->get_event_taxonomy());
$count = count($terms);
if ( $count > 0 ){
echo '<select class="events-cat-menu"><option value="-1">All Events</option>';
// print_r($terms);
$selected = '';
@MikeNGarrett
MikeNGarrett / regex-strip-non-utf-8
Created November 16, 2012 21:04
Strip unknown/non-utf-8 characters
$new_text = preg_replace('/[^(\x20-\x7F)]*/','', $text);
@MikeNGarrett
MikeNGarrett / .maintenance
Created February 20, 2013 21:56
Allow WordPress users to log in to wp-admin and wp-login.php while in maintenance mode. Stick this in your web root to put your site into maintenance mode.
<?php
function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
if ( stristr($cookie, 'wordpress_logged_in_') )
$loggedin = true;
}
return $loggedin;
}
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && ! is_user_logged_in() )
@MikeNGarrett
MikeNGarrett / wp-better-side-nav.php
Last active April 22, 2019 10:00
Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings of the current page (in menu order) and when it gets to the current page it lists out the children.
<?php /* Not as simple as it sounds */ ?>
<div class="side-nav">
<div class="holder">
<ul>
<?php
if (isset($post->post_parent) && $post->post_parent > 0) {
$permalink = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
print('<li class="page_item page-parent"><a href="'.$permalink.'">'.$parent_title.'</a></li>');
$parent = $post->post_parent;
/*
mobileNav.js by Matt Jordan.
*/
(function($) {
$.fn.mobileNav = function(mobileWidth) {
// Create the <select> element
var selectHTML = '<select name="mobileNav" class="mobileNav" style="display:none">',
currentHref = window.location.href,
checkSize = function() {
@MikeNGarrett
MikeNGarrett / wp-3-8-replace-open-sans
Last active January 10, 2018 14:39
WordPress 3.8 - replace admin Open Sans font with your own version
function replace_open_sans() {
// Kill the original style
wp_deregister_style('open-sans');
// Replace it with your own (just as an example, I included only the 300 weight)
wp_register_style( 'open-sans', 'http://fonts.googleapis.com/css?family=Open+Sans:300' );
wp_enqueue_style( 'open-sans');
}
add_action( 'wp_enqueue_scripts', 'replace_open_sans' );
// Thanks to @timkinnane
add_action( 'admin_enqueue_scripts', 'replace_open_sans' );
@MikeNGarrett
MikeNGarrett / zendesk-ticket-export.php
Last active February 1, 2018 10:01
Zendesk ticket export for an organization without a premium account in PHP
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Morning Ticket Export</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.ticket-util').click( function(e) {
e.preventDefault();
@MikeNGarrett
MikeNGarrett / wp_schedule_task
Created January 27, 2014 20:37
Simple WordPress Scheduled Task Structure
<?php
add_action( 'wp', 'schedule_task' );
/* Let's schedule some tasks! */
function schedule_task() {
if ( ! wp_next_scheduled( 'task_hook' ) ) {
// Add scheduled daily task
wp_schedule_event( time(), 'daily', 'task_hook');
}
}
add_action( 'task_hook', 'function_to_run' );
@MikeNGarrett
MikeNGarrett / wp_ajax_request
Created January 28, 2014 23:34
Simple WordPress ajax structure example
<?php
// in functions.php
add_action('wp_ajax_testing_axaj', 'ajax_function_to_execute', 1, 2);
add_action('wp_ajax_nopriv_testing_axaj', 'ajax_function_to_execute', 1, 2);
function ajax_function_to_execute() {
print_r($_REQUEST);
die();
@MikeNGarrett
MikeNGarrett / find-your-ip
Created February 18, 2014 15:03
Find your IP vis curl
//Find your IP vis curl
curl ipecho.net/plain