Skip to content

Instantly share code, notes, and snippets.

Avatar
🤘
Rocking this project.

Mike Garrett MikeNGarrett

🤘
Rocking this project.
View GitHub Profile
@MikeNGarrett
MikeNGarrett / event-category-list.php
Created Aug 5, 2012 — forked from jo-snips/event-category-list.php
The Events Calendar: List Event Categories
View event-category-list.php
<?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 Nov 16, 2012
Strip unknown/non-utf-8 characters
View regex-strip-non-utf-8
$new_text = preg_replace('/[^(\x20-\x7F)]*/','', $text);
@MikeNGarrett
MikeNGarrett / .maintenance
Created Feb 20, 2013
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.
View .maintenance
<?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 Apr 22, 2019
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.
View wp-better-side-nav.php
<?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;
View mobileNav.js
/*
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 Jan 10, 2018
WordPress 3.8 - replace admin Open Sans font with your own version
View wp-3-8-replace-open-sans
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 Feb 1, 2018
Zendesk ticket export for an organization without a premium account in PHP
View zendesk-ticket-export.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 Jan 27, 2014
Simple WordPress Scheduled Task Structure
View wp_schedule_task
<?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 Jan 28, 2014
Simple WordPress ajax structure example
View wp_ajax_request
<?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 Feb 18, 2014
Find your IP vis curl
View find-your-ip
//Find your IP vis curl
curl ipecho.net/plain
You can’t perform that action at this time.