Skip to content

Instantly share code, notes, and snippets.

View codearachnid's full-sized avatar
:octocat:
curiouser and curiouser

Timothy Wood codearachnid

:octocat:
curiouser and curiouser
View GitHub Profile
@codearachnid
codearachnid / gist:9537604
Last active August 29, 2015 13:57
It seems that with WordPress 3.8.1 or greater has an issue with wp_get_attachment_metadata() it now throws an error (or on some servers no result) when trying to get the details of an attachment which is not an image.
<?php
$attachment_ids = (array) $attachment_ids;
$wp_upload_dir = wp_upload_dir();
$attachments = array();
// THIS WILL NOT WORK > WPv3.8.1
foreach( $attachment_ids as $attachment_id ){
$attachment = wp_get_attachment_metadata( $attachment_id );
if( !empty( $attachment['file'] ) ){
$attachments[] = trailingslashit( $wp_upload_dir['basedir'] ) . $attachment['file'];
// This is now managed officially here: https://github.com/codearachnid/knockout.extend
// custom binding attrIf which will check the value of a specific observable boolean before add or not the attributes
ko.bindingHandlers.attrIf = {
update: function (element, valueAccessor, allBindingsAccessor) {
var h = ko.utils.unwrapObservable(valueAccessor());
var ifShow = ko.utils.unwrapObservable(h._if);
if (ifShow) {
ko.bindingHandlers.attr.update(element, valueAccessor, allBindingsAccessor);
} else {
for (var k in h) {
@codearachnid
codearachnid / wc_customer_bought_product.php
Created February 27, 2014 21:07
WooCommerce check if user has already bought product.
<?php
// if product is already in global space
global $product;
// or fetch product attributes by ID
if( empty( $product->id ) ){
$wc_pf = new WC_Product_Factory();
$product = $wc_pf->get_product($id);
}
@codearachnid
codearachnid / wp20140226_reset_slugs.php
Last active October 11, 2020 23:58
Reset the slugs on a particular post type to use the default sanitized slugs. To use, add the following code into your theme's functions.php file, ensure that the desired post type is set when calling `wp20140226_reset_slugs('post');` Then navigate to `wp-admin/options-permalink.php` to activate query to reset slugs. Depending on how many posts …
<?php
/**
* Reset the slugs on a particular post type to use the default sanitized slugs
* @param string $post_type filter by post type
* @param int $offset set the paginated post to start
* @param boolean $force_guid_update * WARNING * never enable this
*
* @example add the following code into your theme's functions.php file, ensure
@codearachnid
codearachnid / jquery-highlightWord.js
Created November 22, 2013 22:02
I needed a way to highlight words after the fact based on an array of catch words. Johann's original method was fantastic but was too slow to map through so finding https://github.com/tankchintan/highlight-js I then modified to be more aggressive in not allowing partial word matches. Currently tested this will scan a reasonable page within 1000 …
/*
* jQuery Highlight Word
*
* hat tip to Johann Burkard's highlighting plugin
* @link <http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
* @link <https://github.com/tankchintan/highlight-js>
*/
!function($) {
$.fn.highlightWord = function(pat, className) {
function innerHighlightWord(node, pat, className) {
@codearachnid
codearachnid / getDateRange.js
Created November 19, 2013 19:04
A highly performant way to add days or date range (array) in JavaScript
/**
* Date.prototype.addDays
*
*/
Date.prototype.addDays = function( days ) {
var element = new Date( this.valueOf() );
element.setDate( element.getDate() + days );
return element;
}
@codearachnid
codearachnid / tribe-admin-events-list.class.php
Created November 19, 2013 01:03
The Events Calendar: Fixed bug with improper column name when in admin main event list. Applies to TEC Pro 3.2. Notes: recently, while updating a client's website to the 3.2 plugin suite for Tribe's The Events Calendar I found that in the admin event list all the disappeared. After the normal, deactivating plugins, default theme etc I took the s…
<?php
/**
* update ~line 26 to include 2 argument params as such:
*/
add_filter( 'posts_orderby', array( __CLASS__, 'events_search_orderby' ), 10, 2 );
/**
* update static function `events_search_orderby` (replace with the following method starting at ~line 159)
*/
@codearachnid
codearachnid / acf_repeater_dynamic_where.php
Last active December 25, 2015 02:59
Fix Advanced Custom Field dynamic key filter for repeater entries automagically. See example 5 http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/
<?php
/*
* Fix Advanced Custom Field dynamic key filter for repeater entries
* @link http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/
*/
add_filter( 'posts_where', 'acf_repeater_dynamic_where', 10, 2 );
function acf_repeater_dynamic_where( $where, &$wp_query ){
if( !empty( $wp_query->meta_query->queries ) ){
$keys = wp_list_pluck( $wp_query->meta_query->queries, "key" );
@codearachnid
codearachnid / first-login.php
Created September 17, 2013 23:28
Create a folder in your plugins folder "first-login", add the following files inside. Then activate and customize.
<?php
/*
Plugin Name: First Login Popup
Plugin URI:
Description: Anytime a user logs in popup a message
Version: 1.0
Author: Timothy Wood @codearachnid
Author URI: http://www.codearachnid.com
License: GPLv2
*/
@codearachnid
codearachnid / custom_label.php
Last active December 20, 2015 10:49
customize your event categogy labels. Make sure that 'tribe_event_category' has the label set to null so the default title of "Event Category" is shown
<?php
/**
* customize your event categogy labels. Make sure that 'tribe_event_category' has the
* label set to null so the default title of "Event Category" is shown
*/
add_action('tribe_events_before_view','custom_label');
function custom_label(){
tribe_set_meta_label( 'tribe_event_category', 'New Category Label' );
}