Some necessary code improvement
-
Hello, Thank you for your great plugin that I have been using for ages and it’s absolutely great that you have returned to support it.
- ERROR: There is a small issue with your plugin: id=thumbnailgridcontainer brings a lot of divs with the same id on a page that goes against html standard and when the page is processing by some code (AMP for example) it brings errors. As you use class=thumbnailgridcontainer in the same div element you can just to remove id=thumbnailgridcontainer at all, but correct .css file, please
- ERROR: wp_reset_query() is not necessary for the plugin because you create a new WP_Query object and don’t use query_posts() but it destroys the outer loop including the main loop. So if you just remove wp_reset_query(); just before $the_query = new WP_Query($atts); it’s perfect.
- ERROR: Opposite, after your Query (in the very end of the thumbnailgrid_function it would be nice to return globals to the outer loop values (return the outer loop like you did nothing with a Query), so wp_reset_postdata() is advisable by WP.
In some cases plugin can be called out of any loop (from AJAX call, for example) but global $post was in use before plugin destroyed it. So, code like:
global $post, $wp_query;
if( ! empty( $wp_query->post) ) wp_reset_postdata();
elseif( ! empty( $this->postid ) ) $post = get_post( $this->postid );
resolves all cases - IMPROVEMENT: your great plugin gives an amazing ability to choose where to insert scripts and styles: in the beginning of the page or in the end, but since quite a long versions ago WP allows to enqueue anywhere and it will be inserted immediately and once. So, if you enqueue scripts and styles as soon as the shortcode called, say in thumbnailgrid_function() it will be great for both: performance and rendering.
- IMPROVEMENT: There is a mess with ‘name’ and ‘postname’ WP_Query object artts especially when post_type=’any’. Actually they acts like aliases. I would duplicated them if one is omitted in the beginning of plugin’s function defaults(), like:
if( ! isset( $atts[‘name’] ) && isset( $atts[‘pagename’] ) ) $atts[‘name’] = $atts[‘pagename’];
if( ! isset( $atts[‘pagename’] ) && isset( $atts[‘name’] ) ) $atts[‘pagename’] = $atts[‘name’]; - IMPROVEMENT: $atts[‘post_type’] === ” looks like ‘any’ more than ‘post’ that follows from WP_Query. I would change it to ‘any’ in the beginning of plugin’s function defaults():
‘post_type’ => ‘any’,
…..
if( ” == $atts[‘post_type’] ) $atts[‘post_type’] = ‘any’;
I have tested all these changes for many years and them work well.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
The topic ‘Some necessary code improvement’ is closed to new replies.