Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@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 / 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 / remove_posts_page_admin_notice.php
Created November 17, 2015 16:20
Remove WordPress Posts Page Admin Notice
<?php
/**
* Remove Posts Page Admin Notice
*
* Since WordPress 4.2, if you edit the page used as the Posts page
* and there was no content saved for that page, the editor functionality
* is removed and a message displayed instead.
*
* The following function re-enables the editor on this page.
@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 / gist:3635796
Created September 5, 2012 12:18
Add wpml-{ICL_LANGUAGE_CODE} class to body tag #WordPress #WPML
/**
* Add wpml-{ICL_LANGUAGE_CODE} class to body tag
*/
function wpml_body_class( $classes ) {
if ( defined( 'ICL_LANGUAGE_CODE' ) )
$classes[] = 'wpml-' . strtolower( ICL_LANGUAGE_CODE );
return $classes;
}
add_filter( 'body_class', 'wpml_body_class' );
@benhuson
benhuson / gist:3090587
Created July 11, 2012 14:09
Term Taxonomy meta example
/**
* Add extra category fields
* Requires the Term_Taxonomymeta plugin
*/
function add_category_excerpt_fields( $category ) {
if ( ! class_exists( 'Term_Taxonomymeta' ) )
return;
$category_metadata = get_metadata( 'term_taxonomy', $category->term_id, 'excerpt', true );
?>
<tr class="form-field">
@benhuson
benhuson / sitepress.class.patch.php
Created July 6, 2012 11:16
WPML Serialised Custom Fields Patch
diff --git a/sitepress.class.php b/sitepress.class.php
index d5b2802be9a9de8b64244e889328b3e2ad776c9b..ecd861877107f00a7b111c3477bd65df12e86e6f 100644
--- a/sitepress.class.php
+++ b/sitepress.class.php
@@ -2775,7 +2775,7 @@ class SitePress{
// if the list of values has 1 element run update
// this will either ADD or UPDATE the value on the translated document
if(count($meta_values) == 1){
@benhuson
benhuson / gist:2576414
Created May 2, 2012 13:06
Fix scale on rotate issue on iPad/iPhone
/**
* Fix scale on rotate issue
*/
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
document.body.addEventListener('gesturestart', function () {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
@benhuson
benhuson / gist:2576426
Created May 2, 2012 13:09
Useful CSS
/* Prevent text scaling on rotate for iPad/iPhone */
html { -webkit-text-size-adjust: none; }
@benhuson
benhuson / jquery.touchcarousel-1.0.patch.js
Created March 28, 2012 18:00
TouchCarousel - Detach
/* Detach carousel - same as destroy but content is not removed */
detach: function() {
this.stopAutoplay();
this._itemsWrapper.unbind(this._downEvent);
$(document).unbind(this._moveEvent).unbind(this._upEvent);
$(window).unbind(this._resizeEvent);
if(this.settings.keyboardNav) {
$(document).unbind("keydown.touchcarousel");
}
if (this._dragContainer.parent().hasClass('touchcarousel-wrapper')) {