Skip to content

Instantly share code, notes, and snippets.

View codearachnid's full-sized avatar
🎯
Focusing

Timothy Wood codearachnid

🎯
Focusing
View GitHub Profile
// 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 / 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'];
@codearachnid
codearachnid / filter_widget_taxonomy_terms.php
Last active August 29, 2015 13:57
Filter widgets in sidebar to filter taxonomy terms by author when on the author template - the request: http://wordpress.stackexchange.com/questions/138097/author-template-filter-sidebar-widgets-by-author
<?php
/*
* For updates to this code please use the latest here:
*
* @link https://github.com/codearachnid/WPSE/blob/master/filter-by-author-widget-taxonomy-terms.php
*/
add_filter( 'widget_tag_cloud_args', 'filter_categories_by_author' );
add_filter( 'widget_categories_dropdown_args', 'filter_categories_by_author' );
@codearachnid
codearachnid / theme-unit-test-data.xml
Created March 21, 2014 01:50
WordPress theme unit test data with visual variations
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is a WordPress eXtended RSS file generated by WordPress as an export of your site.
It contains information about your site's posts, pages, comments, categories, and other content.
You may use this file to transfer that content from one site to another.
This file is not intended to serve as a complete backup of your site.
To import this information into a WordPress site follow these steps:
1. Log in to that site as an administrator.
2. Go to Tools: Import in the WordPress admin panel.
@codearachnid
codearachnid / custom_limit_gform_is_duplicate.php
Created March 26, 2014 10:28
Allow a certain amount of duplicates in a Gravity From by field before kicking back a failure check.
<?php
add_filter( 'gform_is_duplicate', 'custom_gform_is_duplicate', 10, 4 );
function custom_gform_is_duplicate( $count, $form_id, $field, $value ){
global $wpdb;
$lead_detail_table_name = GFFormsModel::get_lead_details_table_name();
$lead_table_name = GFFormsModel::get_lead_table_name();
$sql_comparison = "ld.value=%s";
switch(RGFormsModel::get_input_type($field)){
@codearachnid
codearachnid / posts.xml
Created March 27, 2014 05:29
Export your Expression Engine 1.x content into WordPress compatible importable XML.
{assign_variable:my_weblog="default_site"}
{assign_variable:my_template_group="site"}
<?xml version="1.0" encoding="UTF-8" ?>
<!-- generator="WordPress/3.3.2" created="2012-06-25 23:09" -->
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.1/"
@codearachnid
codearachnid / gf_notification_debug.php
Created April 2, 2014 11:37
Debug Gravity Forms: Notification Attachments
<?php
/*
Plugin Name: Gravity Forms: Notification Attachments Debug
Plugin URI: http://codearachnid.github.io/gf-notification-attachment/
Description: Debug the addon for Gravity Forms to add attachments to notification emails
Version: 1.0
Author: Timothy Wood (@codearachnid)
Author URI: http://codearachnid.com
@codearachnid
codearachnid / deviceBaseURL.js
Created April 24, 2014 18:03
A quick way to get the local file's url (used on phonegap)
var tempElement = document.createElement("a");
tempElement.setAttribute("href", ".");
var deviceBaseURL = tempElement.href;
@codearachnid
codearachnid / remove-co-authors-plus-column.php
Last active August 29, 2015 14:02
Remove the "Authors" column from Co Authors Plus for a post type list in the admin
<?php
add_action( 'admin_init', 'coauthors_cleanup_admin_init', 100 );
function coauthors_cleanup_admin_init(){
global $coauthors_plus, $pagenow;
if( 'edit.php' == $pagenow && 'post' == $_GET['post_type']){
remove_filter( 'manage_posts_columns', array( $coauthors_plus, '_filter_manage_posts_columns' ) );
}
}
@codearachnid
codearachnid / toRadians.js
Last active August 29, 2015 14:05
Convert degrees to radians
/**
* Convert degrees to radians
* @author Timothy Wood @codearachnid
* @link http://www.movable-type.co.uk/scripts/latlong.html
* @example
var latitude = 38.68551;
var longitude = -96.503906;
var latitude_radian = latitude.toRadians();
var longitude_radian = longitude.toRadians();