Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Cannon michael-cannon

View GitHub Profile
@michael-cannon
michael-cannon / gist:3028827
Created Jul 1, 2012
Scriblio plugin/class-facet-taxonomy.php - No matching_post_ids fix
View gist:3028827
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 Jul 11, 2012
Prevent doubly encoding UTF-8 content when incoming data could be UTF-8, ASCII or another character set
View gist:3090584
$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 Jul 20, 2012
Default realurl configuration
View realurl.php
<?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 Aug 28, 2012
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.
View constants.txt
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 Nov 6, 2012
Correctly import image caption as caption than description in WordPress
View gist:4025107
<?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 Nov 6, 2012
Import image keywords as alternate text and tags in WordPress - makes tags available in attachments
View gist:4025132
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 Dec 13, 2012
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.
View debug.php
<?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 Dec 9, 2015
Example of using the Testimonials Widget plugin for WordPress `testimonials_widget_testimonial_html` filter.
View filter.php
<?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
View purge-wp-transients.php
<?php
/*
Plugin Name: Purge Transients
Description: Purge old transients
Version: 0.1
Author: Seebz
*/
View testimonials-widget.css
.testimonialswidget_testimonials {
/* testimonials wrapper */
}
.testimonialswidget_testimonials .testimonialswidget_active {
/* active testimonials */
display: block;
}
.testimonialswidget_testimonials .testimonialswidget_display_none {