Example #1
0
/**
 * Cache Images
 *
 * Sets the WordPress object cache for all term images
 * associated to the posts in the provided array. This
 * function has been created to minimize queries when
 * using this plugins get_the_terms() style function.
 *
 * @param     array          Post objects.
 *
 * @access    private
 * @since     1.1
 */
function taxonomy_image_plugin_cache_images($posts)
{
    $assoc = taxonomy_image_plugin_get_associations();
    if (empty($assoc)) {
        return;
    }
    $tt_ids = array();
    foreach ((array) $posts as $post) {
        if (!isset($post->ID) || !isset($post->post_type)) {
            continue;
        }
        $taxonomies = get_object_taxonomies($post->post_type);
        if (empty($taxonomies)) {
            continue;
        }
        foreach ($taxonomies as $taxonomy) {
            $the_terms = get_the_terms($post->ID, $taxonomy);
            foreach ((array) $the_terms as $term) {
                if (!isset($term->term_taxonomy_id)) {
                    continue;
                }
                $tt_ids[] = $term->term_taxonomy_id;
            }
        }
    }
    $tt_ids = array_filter(array_unique($tt_ids));
    $image_ids = array();
    foreach ($tt_ids as $tt_id) {
        if (!isset($assoc[$tt_id])) {
            continue;
        }
        if (in_array($assoc[$tt_id], $image_ids)) {
            continue;
        }
        $image_ids[] = $assoc[$tt_id];
    }
    if (empty($image_ids)) {
        return;
    }
    $images = get_posts(array('include' => $image_ids, 'post_type' => 'attachment'));
}
Example #2
0
 public function __construct()
 {
     $this->settings = taxonomy_image_plugin_get_associations();
     add_action('taxonomy_image_plugin_print_image_html', array(&$this, 'print_image_html'), 1, 3);
 }
/**
 * Queried Term Image ID.
 *
 * Designed to be used in archive templates including
 * (but not limited to) archive.php, category.php, tag.php,
 * taxonomy.php as well as derivatives of these templates.
 *
 * Returns an integer representing the image attachment's ID.
 * In the event that an image has been associated zero will
 * be returned.
 *
 * This function should never be called directly in any file
 * however it may be access in any template file via the
 * 'taxonomy-images-queried-term-image-id' filter.
 *
 * @param     mixed     Default value for apply_filters() to return. Unused.
 * @return    int       Image attachment's ID.
 *
 * @access    private   Use the 'taxonomy-images-queried-term-image-id' filter.
 * @since     0.7
 */
function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
	$filter = 'taxonomy-images-queried-term-image-id';
	if ( current_filter() !== $filter ) {
		taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
	}

	$obj = get_queried_object();

	/* Return early is we are not in a term archive. */
	if ( ! isset( $obj->term_taxonomy_id ) ) {
		trigger_error( sprintf( esc_html__( '%1$s is not a property of the current queried object. This usually happens when the %2$s filter is used in an unsupported template file. This filter has been designed to work in taxonomy archives which are traditionally served by one of the following template files: category.php, tag.php or taxonomy.php. Learn more about %3$s.', 'taxonomy-images' ),
			'<code>' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '</code>',
			'<code>' . esc_html( $filter ) . '</code>',
			'<a href="http://codex.wordpress.org/Template_Hierarchy">' . esc_html( 'template hierarchy', 'taxonomy-images' ) . '</a>'
		) );
		return 0;
	}

	if ( ! taxonomy_image_plugin_check_taxonomy( $obj->taxonomy, $filter ) ) {
		return 0;
	}

	$associations = taxonomy_image_plugin_get_associations();
	$tt_id = absint( $obj->term_taxonomy_id );

	$ID = 0;
	if ( array_key_exists( $tt_id, $associations ) ) {
		$ID = absint( $associations[$tt_id] );
	}

	return $ID;
}
Example #4
0
function tip_plugin_get_terms($term_id)
{
    $associations = taxonomy_image_plugin_get_associations();
    $tt_id = absint($term_id);
    $img_id = false;
    if (array_key_exists($tt_id, $associations)) {
        $img_id = absint($associations[$tt_id]);
    }
    return $img_id;
}