Skip to content

Instantly share code, notes, and snippets.

View michael-cannon's full-sized avatar

Michael Cannon michael-cannon

View GitHub Profile
@michael-cannon
michael-cannon / gist:3028827
Created July 1, 2012 16:06
Scriblio plugin/class-facet-taxonomy.php - No matching_post_ids fix
Index: plugin/class-facet-taxonomy.php
===================================================================
--- plugin/class-facet-taxonomy.php (revision 566010)
+++ plugin/class-facet-taxonomy.php (working copy)
@@ -89,7 +89,7 @@
$cache_key = md5( serialize( $matching_post_ids ));
- if( ! $this->facets->_matching_tax_facets = wp_cache_get( $cache_key , 'scrib-facet-taxonomy' ))
+ if( ! empty( $matching_post_ids ) && ! $this->facets->_matching_tax_facets = wp_cache_get( $cache_key , 'scrib-facet-taxonomy' ))
@michael-cannon
michael-cannon / gist:3090584
Created July 11, 2012 14:09
Prevent doubly encoding UTF-8 content when incoming data could be UTF-8, ASCII or another character set
$recTitle = $record['title'];
$encoding = mb_detect_encoding( $recTitle, 'UTF-8', true );
if ( empty( $encoding ) ) {
$recTitle = mb_convert_encoding( $recTitle, 'UTF-8' );
}
@michael-cannon
michael-cannon / realurl.php
Created July 20, 2012 13:22
Default realurl configuration
<?php
$TYPO3_CONF_VARS['FE']['addRootLineFields'] .= ',tx_realurl_pathsegment,tx_realurl_exclude,tx_realurl_pathoverride,alias,nav_title,title';
// @ref http://www.slideshare.net/jweiland/why-realurl-sucks-and-how-to-fix-it
$realurlConfig = array(
'init' => array(
'adminJumpToBackend' => true,
'appendMissingSlash' => 'ifNotFile,redirect[301]',
'emptyUrlReturnValue' => '/',
@michael-cannon
michael-cannon / constants.txt
Created August 28, 2012 08:42
For in2master, I wanted the ability to autoset config.absRefPrefix, specifically set it, or unset it without a lot of hassle. The following code does such.
config {
# cat=basic/links; type=string; label=Absolute Reference Prefix: Used to convert relative paths to absolute paths. Use absolute URL like "http://www.example.com" to set. If empty, config.baseURL is used. If 0, config.absRefPrefix is unset.
absRefPrefix =
}
@michael-cannon
michael-cannon / gist:4025107
Created November 6, 2012 14:43
Correctly import image caption as caption than description in WordPress
<?php
function add_attachment_caption( $meta, $attachment_id ) {
if ( ! empty( $meta['image_meta']['caption'] ) ) {
$data = array(
'ID' => $attachment_id,
// remove wrongly imported caption as description field
'post_content' => '',
'post_excerpt' => $meta['image_meta']['caption'],
);
@michael-cannon
michael-cannon / gist:4025132
Created November 6, 2012 14:48
Import image keywords as alternate text and tags in WordPress - makes tags available in attachments
function register_attachment_taxonomy() {
add_post_type_support('attachment', 'post_tag');
register_taxonomy_for_object_type('post_tag', 'attachment');
}
add_action('admin_init', 'register_attachment_taxonomy');
// add_filter('wp_read_image_metadata', 'read_all_image_metadata', '', 3);
function add_attachment_post_tags( $meta, $attachment_id ) {
@michael-cannon
michael-cannon / debug.php
Created December 13, 2012 03:35
A quick and dirty "what the fudge am i" helper for WordPress. I use this to help me determine what type of view is being presented when theming. In turn, this also helps me check that my display condition assumptions are correct.
<?php
/**
* WordPress debug helpers
*
* @author Michael Cannon <mc@aihr.us>
*/
function wtfami( $uk = null ) {
if ( ! is_null( $uk ) ) echo $uk . " is…\n<br />";
@michael-cannon
michael-cannon / filter.php
Last active December 9, 2015 21:58
Example of using the Testimonials Widget plugin for WordPress `testimonials_widget_testimonial_html` filter.
<?php
add_filter( 'testimonials_widget_testimonial_html', 'my_testimonials_widget_testimonial_html', 10, 6 );
// this function is a copy of Testimonials_Widget::get_testimonial_html and completely ignores what's in $content
function my_testimonials_widget_testimonial_html( $content, $testimonial, $atts, $is_list = true, $is_first = false, $widget_number = null ) {
$atts = wp_parse_args( $atts, Testimonials_Widget::get_defaults( true ) );
$atts = Testimonials_Widget_Settings::validate_settings( $atts );
// display attributes
<?php
/*
Plugin Name: Purge Transients
Description: Purge old transients
Version: 0.1
Author: Seebz
*/
.testimonialswidget_testimonials {
/* testimonials wrapper */
}
.testimonialswidget_testimonials .testimonialswidget_active {
/* active testimonials */
display: block;
}
.testimonialswidget_testimonials .testimonialswidget_display_none {