Skip to content

Instantly share code, notes, and snippets.

View devonwaldon's full-sized avatar

Devon Waldon devonwaldon

  • Paper Leaf
  • Edmonton, AB
View GitHub Profile
/**
* Handle conditional field logic
*/
$('[data-conditional-switch]').css('display', 'none');
updateConditionalFields();
function updateConditionalFields() {
$('[data-conditional-control]').each(function () {
var conditional_value = '';
var conditional_switch = $(this).attr('name');
if ($(this).attr('type') == 'radio') {
@devonwaldon
devonwaldon / theme_functions.php
Created November 9, 2018 19:00
Generate NGINX 301s using 'old_url' and 'old_attachment_url' postmeta
/* =========================================================================
* GENERATE 301s
* =========================================================================
*/
function checkForMatch($old_url, $is_attachment=false) {
if (!$is_attachment) {
$meta_key = 'old_url';
$post_type = 'page';
} else {
@devonwaldon
devonwaldon / filterable-footable.js
Last active October 31, 2018 22:20
Extensible FooTable filtering setup
function setupFootable( footable ) {
footable.on('expand.ft.row', function(e, ft, row) {
row.$el.find('.toggle i').removeClass('ion-md-add').addClass('ion-md-remove');
});
footable.on('collapse.ft.row', function(e, ft, row) {
row.$el.find('.toggle i').removeClass('ion-md-remove').addClass('ion-md-add');
});
@devonwaldon
devonwaldon / forceTextNodeCase.js
Last active May 11, 2018 18:31
Fix the case of a string throughout the DOM to deal with CSS 'transform: uppercase'.
function getNodesThatContain(text) {
var textNodes = $('#page').find(':not(iframe, script)')
.contents().filter(
function () {
return (this.nodeType == 3 && this.textContent.indexOf(text) > -1);
});
return textNodes.parent();
}
function forceTextNodeCase(proper_text) {
var nodes = getNodesThatContain(proper_text).each(function () {
@devonwaldon
devonwaldon / generate_taxonomy_labels.php
Created March 6, 2018 17:44
Generate Taxonomy Labels
/**
* Generates the label array for use in creating WP taxonomies. Takes a singular
* root as well as an optional plural form; if the plural is not supplied, then
* a root+'s' will be used instead.
*/
function generate_taxonomy_labels($singular, $plural=false) {
if ( !$plural ) {
$plural = $singular . 's';
}
return array(
@devonwaldon
devonwaldon / social-share-function.php
Created November 22, 2016 19:26
PHP function to generate social share URLs
/**
* Generate Social Media Buttons
*/
function get_social_share_url( $network, $post_id_to_share, $username=NULL ) {
$url = '';
$url_to_share = get_permalink($post_id_to_share);
$title_to_share = pl_get_the_title($post_id_to_share);
$summary_to_share = pl_get_the_excerpt($post_id_to_share);