Skip to content

Instantly share code, notes, and snippets.

View ethanclevenger91's full-sized avatar

Ethan Clevenger ethanclevenger91

View GitHub Profile
@ethanclevenger91
ethanclevenger91 / replace-short-open.php
Created January 29, 2019 16:07
Recursively and safely swap out PHP short open and short echo tags in a directory
<?php
/*
* Run like so: `php -d short_open_tag=On replace-short-open.php
*
* Shamelessly cobbled together from:
* https://stackoverflow.com/a/17161106/2233690
* https://stackoverflow.com/questions/684587/batch-script-to-replace-php-short-open-tags-with-php/1647429#1647429
* https://stackoverflow.com/a/684752/2233690
*
@ethanclevenger91
ethanclevenger91 / wp-private-pages-in-menu-builder.php
Last active October 24, 2023 21:30
Add private pages to WordPress menu builder
add_filter('nav_menu_items_page_recent', 'nav_menu_items_page_recent_with_private', 10, 3);
// Update post_status arg to include private pages
function nav_menu_items_page_recent_with_private($most_recent, $args, $box) {
$args['post_status'] = [
'publish',
'private',
];
// Unsure why these aren't passed into the filter already since it's specifically for the Most Recent tab.
@ethanclevenger91
ethanclevenger91 / jquery.animate.css.js
Created June 20, 2016 13:37
animate.css jQuery extension using waypoints.js
window.jQuery.fn.extend({
animateCss: function (animationName, delay, offset) {
var offset = typeof offset !== 'undefined' ? offset : '70%';
var delay = typeof delay !== 'undefined' ? delay : 0;
var $this = $(this);
$this.css('visibility', 'hidden');
new Waypoint({
element:this[0],
handler:function(direction) {
setTimeout(function() {
@ethanclevenger91
ethanclevenger91 / functions.php
Last active January 17, 2018 14:37
Use a comparison operator for your WordPress `meta_query` key - inspired by http://wordpress.stackexchange.com/questions/193791/use-regexp-in-wp-query-meta-query-key
add_action('pre_get_posts', 'meta_query_key_compare');
function meta_query_key_compare($query) {
$meta_query = $query->get('meta_query');
if(empty($meta_query)) {
return;
}
$marker = '__tmp_marker__';
$rx = [];
@ethanclevenger91
ethanclevenger91 / oneChecked.js
Last active August 29, 2015 14:21
Check if at least one of a group of checkboxes has been checked.
(function ( $ ) {
$.fn.oneChecked = function() {
var checked = false;
this.each(function() {
if($(this).is(':checked')) {
checked = true;
}
});
return checked;
};
@ethanclevenger91
ethanclevenger91 / atom.snippets
Last active December 8, 2015 15:05
Text editor snippets for Wordpress's loop and a new WP_Query
'.source.php':
'The Loop':
'prefix': 'theloop'
'body': "if($1->have_posts()): while($1->have_posts()): $1->the_post();"
'New WP_Query':
'prefix': 'wpquery'
'body': """
$1 = new WP_Query(['post_type'=>$2, 'posts_per_page'=>-1, 'orderby'=>'menu_order', 'order'=>'ASC']);
if($1->have_posts()): while($1->have_posts()): $1->the_post();
@ethanclevenger91
ethanclevenger91 / functions.php
Created January 19, 2015 19:16
omit some post types from shareaholic. I hate this plugin.
add_action('the_post', 'remove_share_buttons');
function remove_share_buttons() {
if(get_post_type() == 'staff_members') {
remove_action('the_content', array('ShareaholicPublic', 'draw_canvases'));
}
}
@ethanclevenger91
ethanclevenger91 / svgclass.js
Created January 8, 2015 17:53
SVG class manipulation - no IE9 support
$('svg.foo').click(function() {
this.classList.toggle('selected');
});
//classList supports add(), remove(), toggle() and contains()
//No IE9 support - shim here - https://developer.mozilla.org/en-US/docs/Web/API/Element.classList
@ethanclevenger91
ethanclevenger91 / archive.php
Last active August 29, 2015 14:10
Post type descriptions - puts a wysiwyg editor for CPTs in an intuitive location on the CPT index. Useful for things like lead-in paragraphs on a CPT archive. Wrapped conveniently in a plugin
<?php //https://bitbucket.org/webspec/webspec-post-type-descriptions
//As of WP 4.1
echo get_the_archive_description();
//Pre WP 4.1
$obj = get_queried_object();
echo stripslashes(html_entity_decode($obj->description));
@ethanclevenger91
ethanclevenger91 / automated-cache-busting.php
Created November 20, 2014 15:50
Automated Cache Busting. This works by adding the file's change time to the end of the url (last argument of the call)
<?php
wp_enqueue_style('slug', get_template_directory_uri().'/css/slug.css', array(), filemtime(get_template_directory().'/css/slug.css'));
wp_enqueue_script('slug', get_template_directory_uri().'/js/slug.js', array(), filemtime(get_template_directory().'/js/slug.js'));
//Note the second argument is URL based while the last argument is a file path.