Permalink
Browse files

Add support for Taxonomy Images plugin.

  • Loading branch information...
mfields committed Apr 27, 2011
1 parent 3e484a9 commit 6086f6cf2ae69cd98ea2fbc3e81e713d270a5b03
Showing with 71 additions and 8 deletions.
  1. +8 −7 taxonomy-wc_speaker.php
  2. +63 −1 wp-presentations.php
View
@@ -18,12 +18,14 @@
$speaker = $wp_query->get_queried_object();
- if ( isset( $speaker->name ) ) {
- print apply_filters( 'wcplugin_speaker_name_format', $speaker->name, array(
- 'before' => '<h1>',
- 'after' => '</h1>'
- ) );
- }
+ print apply_filters( 'wcplugin_speaker_name_format', $speaker->name, array(
+ 'before' => '<h1>',
+ 'after' => '</h1>'
+ ) );
+
+ print apply_filters( 'wcplugin_get_term_image', '', array(
+ 'term' => $speaker,
+ ) );
print term_description();
@@ -46,7 +48,6 @@
}
}
-
if ( ! empty( $links ) ) {
print "\n" . '<ul class="speaker-links">';
foreach ( $links as $link ) {
View
@@ -87,6 +87,8 @@ function init() {
add_filter( 'wcplugin_admin_term_list', array( 'WC_Plugin_Utility', 'admin_term_list' ) );
add_filter( 'wcplugin_sort_posts_by_terms', array( 'WC_Plugin_Utility', 'sort_posts_by_terms' ), 10, 2 );
add_filter( 'wcplugin_get_the_term_name_singular', array( 'WC_Plugin_Utility', 'get_the_term_name_singular' ), 10, 2 );
+ add_filter( 'wcplugin_get_term_image', array( 'WC_Plugin_Utility', 'get_term_image' ), 10, 2 );
+ add_filter( 'wcplugin_get_term_image_url', array( 'WC_Plugin_Utility', 'get_term_image_url' ), 10, 2 );
}
/**
* Activation.
@@ -528,7 +530,6 @@ function speaker_name_format( $name, $args = array() ) {
$parts = join( ' ', $parts );
return $args['before'] . esc_html( $parts ) . $args['after'];
}
-
function create_meta_table() {
global $wpdb;
@@ -868,4 +869,65 @@ function get_the_term_name_singular( $default, $args ) {
}
return $default;
}
+ function get_term_image( $default, $args ) {
+ $size = 'thumbnail';
+ if ( isset( $args['size'] ) ) {
+ $size = $args['size'];
+ }
+ $id = (int) self::get_term_image_id( $args['term'] );
+ if ( empty( $id ) ) {
+ return $default;
+ }
+ $attr = array(
+ 'class' => esc_attr( 'attachment-' . $size . ' ' . $args['term']->taxonomy . '-image' ),
+ );
+ if ( isset( $args['attr'] ) ) {
+ $attr = wp_parse_args( $args['attr'], $attr );
+ }
+ return wp_get_attachment_image( $id, $size, false, $attr );
+ }
+ /**
+ * Get Term Image URL
+ *
+ * This plugin does not directly support speaker images.
+ * If such functionality is desired, users can install the
+ * Taxonomy Images plugin and this function will recognize
+ * the data stored by it.
+ *
+ * @param string Default image url.
+ * @param stdClass Term object.
+ * @return string URL to the speaker's image if it exists, value of $default parameter otherwise.
+ *
+ * @since 2011-04-27
+ */
+ function get_term_image_url( $default, $args ) {
+ $defaults = array(
+ 'term' => false,
+ 'size' => 'thumbnail'
+ );
+ $args = wp_parse_args( $args, $defaults );
+ $id = self::get_term_image_id( $args['term'] );
+ $image = wp_get_attachment_image_src( $image_id, $args['size'] );
+ if ( isset( $image[0] ) ) {
+ return $image[0];
+ }
+ return $default;
+ }
+ /**
+ * @return int Attachment ID
+ */
+ function get_term_image_id( $term ) {
+ if ( ! function_exists( 'taxonomy_image_plugin_get_associations' ) ) {
+ return 0;
+ }
+ if ( ! isset( $term->term_taxonomy_id ) ) {
+ return 0;
+ }
+ $tt_id = $term->term_taxonomy_id;
+ $associations = taxonomy_image_plugin_get_associations();
+ if ( array_key_exists( $tt_id, $associations ) ) {
+ return (int) $associations[$tt_id];
+ }
+ return 0;
+ }
}

0 comments on commit 6086f6c

Please sign in to comment.