Michael Fields
Forum Replies Created
-
2046,
This is an oversight on my part … Had no idea thatget_term_children()
even existed. It’s really rare that I will use term hierarchies though. Please provide the context that you will be using this function and I’ll see what I can do bout coming up with a filter for it.Yep. This is definitely a bug … got it fixed in the public git repo. Still have a few changes before the next version though. If you’re antsy, the master branch is stable:
Forum: Plugins
In reply to: [Taxonomy Images] combining logic of my function with tax imagesThis is one way of doing this. It should work without either plugin installed:
<?php while( have_posts() ) { the_post(); $src = 'https://full-path.to/default-image.jpg'; $post_tags = apply_filters( 'taxonomy-images-get-the-terms', array(), array( 'taxonomy' => 'post_tag' ) ); if ( isset( $post_tags[0]->image_id ) ) { $img = wp_get_attachment_image_src( $post_tags[0]->image_id, 'thumbnail' ); if ( isset( $img[0] ) ) { $src = $img[0]; } } if ( function_exists( 'get_the_image' ) ) { $src = get_the_image( array( 'return_url' => 'true', 'echo' => 'false', 'link_to_post' => 'false', 'default_image' => $src, 'image_scan' => 'true', 'meta_key' => 'feature_img', 'width' => '45', 'height' => '55', 'echo' => false ) ); } else if ( has_post_thumbnail() ) { $img = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'thumbnail' ); if ( isset( $img[0] ) ) { $src = $img[0]; } } } ?>
Hi, This is most likely a bug in the plugin … i thought I fixed all of these, but maybe I missed one. Please try the following code and let me know how it works for you:
<?php print apply_filters( 'taxonomy-images-list-the-terms', '', array() ); ?>
I’ll investigate and get this fixed in the next release.
Thanks!
-MikeForum: Plugins
In reply to: [Taxonomy Images] combining logic of my function with tax imagesBTW … There is a ton of documentation in the source of this project. But I am coming to realize that further documentation may be necessary. If you guys could help out with this that would be great!
I’m not really looking for you to write it, rather point out areas that could be improved. Just by reading this it seems like there should be a “How this plugin works” page that explains what we have talked about here. Any ideas for other such pages?
If so, please use the issue tracker:
https://github.com/mfields/Taxonomy-Images/issuesThanks!
Forum: Plugins
In reply to: [Taxonomy Images] combining logic of my function with tax imagesImages are not assigned directly to taxonomies.
Images are associated with terms.Data for terms associations are stored in the options table of the database. Here’s an easy way to see what the plugin has stored:
function dump_taxonomy_images_plugin_data() { $associations = get_option( 'taxonomy_image_plugin' ); print '<pre>' . print_r( $associations, true ) . '</pre>'; $settings = get_option( 'taxonomy_image_plugin_settings' ); print '<pre>' . print_r( $settings, true ) . '</pre>'; } add_action( 'wp_head', 'dump_taxonomy_images_plugin_data' );
The associations are stored in the “taxonomy_image_plugin” option as a numerically indexed array.
The keys represent the term_taxonomy_id of the term.
The value represents the image’s ID.Each value is intended to be an integer and should be escaped as such before feed into a low-level function. Most higher-lever functions (like template tags) should require no sanitation. I always cast as int in these cases anyway … it’s easy enough to do ??
Forum: Plugins
In reply to: [Taxonomy Images] combining logic of my function with tax imagesThe API currently does not support this. I’ll need to do some testing to see the best way to handle such an process. I think you are like the 3rd or so person to request this functionality so it’s definitely in my mind to do/ I just don’t have time at the moment to do all of the testing involved to get you the best possible solution. Feel free to hit me up in a few days if you are getting restless with this.
Forum: Plugins
In reply to: [Taxonomy Images] tax images plus wp_list_categoriesSomething like this works:
<?php $terms = apply_filters( 'taxonomy-images-get-terms', '', array( 'taxonomy' => 'category', ) ); if ( ! empty( $terms ) ) { print "\n" . '<ul>'; foreach( (array) $terms as $term ) { print "\n" . '<li>'; print "\n\t" . '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a>'; print "\n\t" . '<span class="category-name">' . esc_html( $term->name ) . '</span>'; print "\n" . '</li>'; } print "\n" . '</ul>'; } ?>
Forum: Fixing WordPress
In reply to: fopen() Cron Error@ocean90 Thanks for posting a link to that ticket. Very informative. I no longer develop on a Windows machine. And have not noticed the errors since I switched.
Forum: Plugins
In reply to: [Taxonomy Widget] Dropdown menu does not workGlad it worked! Marking this topic as resolved.
Forum: Plugins
In reply to: [Taxonomy Widget] Dropdown menu does not workPlease make sure that your theme has a call to
<?php wp_footer(); ?>
in footer.php.1. If you inspect that database these values will be the same until the same term exists in multiple taxonomies. Certain data is stored for the term itself (like term_id) and other data is stored for the term-taxonomy association (like term_taxonomy_id). I originally used term_id in an early version of the plugin and someone testing it reported this issue. I felt that users should explicitly assign images to terms and the plugin should not assume that two identical terms in different taxonomy meant the same thing.
2. How are you listing the categories? Which core function do you use to get them? This plugin provides wrapper for get_terms() which should give you the flexibility you need to query the terms you need. If you are performing a custom query, the plugin will not really help you out.
The function you are suggesting should not really be used in loops as it calls get
wp_get_attachment_image()
which callsget_post()
andget_post_meta()
. Both of these functions query the database if the data cannot be found in cache.taxonomy_images_plugin_get_terms()
makes one call toget_children()
which caches the images + their metadata. This cuts down on excessive queries.The reasons you gave for the “apply_filters approach” make sense, but I don’t know if *performance wise* it wouldn’t be better to stick to the classic “if function exists” approach. Once again I have no idea.
I’m not expert on this type of thing, but will definitely share my opinion. I think that the overhead generated by using apply_filters() is so small (in comparison) that it should not really be considered. apply_filters() is used many, many, many times throughout core – a couple thousand. It does not use
function_exists()
for performance reasons. Note: I remember reading about this in the past, but cannot find a reference to it at the moment. Please take this with a grain of salt.I would like to work with you on a potential get_terms() approach before adding the function to the plugin.
jfache,
I think this is a great idea thanks for the suggestion. There are a few things to consider though, so I was wondering if you could answer a few questions:
1. You show
term_id
in the code you proposed. This plugin stored association usingterm_taxonomy_id
. Would this be a problem for you?2. Could you describe the use case. While I would agree that it makes sense for a function like this to be in the plugin (and I will add it), helping me to understand how the already provided filters do not serve this purpose would be really beneficial to me as a developer. A few of the functions in public-filters.php needed to be optimized so that they cache the images that they return. You can read an in-depth explanation here:
I knew that not everyone would be stoked about the filters API that I put in place, but I really feel that it is for the best. It’s meant to help those that “need it the most” – users who are not that skilled in php, but can get by by copying and pasting code. In the event that someone like this copy’s and pastes code from the docs into the theme and then deactivate the plugin down the road, their site will not break. There’s also the reason that “in a perfect world” themes would not make direct calls to plugin functions. Using a core function such as
apply_filters()
allows the 2 different extensions to be independently as well as symbiotically with minimal code.Totally open to hearing you thoughts on this topic. FWIW, this was not a decision that was made lightly ??
Best,
-MikeForum: Fixing WordPress
In reply to: hide empty selectors with jquery in wordpressYou’re welcome ??
Forum: Fixing WordPress
In reply to: hide empty selectors with jquery in wordpressThis worked for me:
jQuery( document ).ready( function( $ ) { $( '.describe' ).each( function( i, e ) { var h = $( e ); if ( '' === h.html() ) { h.hide(); } } ); } );