Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@benhuson
benhuson / wordpress-pdf-attachments
Created November 12, 2012 10:24
WordPress: Display PDF and Word attachments
<?php
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'application/pdf,application/msword',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC'
);
@benhuson
benhuson / hide-plugin-update-messages.php
Created January 11, 2013 10:52
Hide plugin update messages for a WordPress plugin
<?php
/**
* Hide Plugin Update Messages for this plugin
*/
add_filter( 'http_request_args', 'hide_plugin_update_messages', 10, 2 );
function hide_plugin_update_messages( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
@benhuson
benhuson / wp-gettext-filter.php
Created January 17, 2013 15:04
How to filter translated text in WordPress This example shows how to filter the 'This product has sold out.' text in the WP e-Commerce plugin. If the translation domain is 'wpsc' it will replace the text with 'This product is no longer available.'.
<?php
/**
* This example shows how to filter the 'This product has sold out.' text.
* If the translation domain is 'wpsc' it will replace the text with 'This product is no longer available.'.
*/
add_filter( 'gettext', 'my_gettext_filter' );
function my_gettext_filter( $translated_text, $text, $domain ) {
if ( 'wpsc' == $domain ) {
switch ( $text ) {
@benhuson
benhuson / gist:4659950
Created January 28, 2013 22:35
Setup canonical links for WPEC products in multiple categories.
<?php
/**
* Fix canonical for posts in multiple categories
*/
class CanonicalCategoryFix {
function CanonicalCategoryFix() {
add_filter( 'wpseo_canonical', array( $this, 'canonical_permalink' ) );
add_filter( 'wpsc_change_canonical_url', array( $this, 'canonical_permalink' ) );
@benhuson
benhuson / hide-tiff-thumbnails
Created March 11, 2013 13:22
Hide Tiff thumbnails in WordPress admin. Useful for when dealing with large TIFF files, thumbnail aren't created so it tries to load tiff image into media library.
/**
* Don't try to show TIFF thumbnails in admin
*/
function my_wp_prepare_attachment_for_js( $response, $attachment, $meta ) {
if ( is_admin() && $response['type'] == 'image' && in_array( $response['subtype'], array( 'tiff', 'tif' ) ) ) {
$response['type'] = 'application';
}
return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'my_wp_prepare_attachment_for_js', 10, 3 );
@benhuson
benhuson / users2csv.php.patch
Created April 4, 2013 21:47
Patch for the Users 2 CSV WordPress plugin. Change the first column heading to UID rather than duplicate URL title. Fixes some PHP warnings for variables.
Index: users2csv.php
===================================================================
--- users2csv.php (revision 277117)
+++ users2csv.php (working copy)
@@ -26,7 +26,7 @@
if ( is_admin() ) {
- if ($_GET['page'] == "users2csv.php") {
+ if ( isset( $_GET['page'] ) && $_GET['page'] == 'users2csv.php' ) {
@benhuson
benhuson / multiple-post-thumbnails.php
Created May 13, 2013 10:29
WordPress Multiple Post Thumbnails plugin setup. Example of setting up a background image option.
/**
* Multiple Post Thumbnails (plugin compatibility)
* http://wordpress.org/extend/plugins/multiple-post-thumbnails/
*/
if ( class_exists( 'MultiPostThumbnails' ) ) {
$types = array( 'page' );
foreach ( $types as $type ) {
new MultiPostThumbnails( array(
'label' => _x( 'Background Image', 'admin', 'mytheme' ),
'id' => 'background-image',
@benhuson
benhuson / js-clickable-block.js
Created May 29, 2013 08:35
JS Clickable Block
jQuery(".clickable-block").click(function(){
window.location = jQuery(this).find('a').attr('href');
return false;
});
@benhuson
benhuson / custom-posts-order
Last active December 25, 2015 21:09
WordPress custom order for main query
<?php
/**
* Post Order
*/
function product_orderby( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive( 'custom_post_type_name' ) ) ) {
$query->set( 'order', 'ASC' );
$query->set( 'orderby','menu_order' );
}
var ipad_version = 0;
window.ondevicemotion = function(event) {
if (navigator.platform.indexOf("iPad") != -1) {
ipad_version = 1;
if (event.acceleration) ipad_version += window.devicePixelRatio;
}
window.ondevicemotion = null;
get_ipad_version();
}