Title: Some necessary code improvement
Last modified: May 22, 2025

---

# Some necessary code improvement

 *  [Alexander Guskov](https://wordpress.org/support/users/forcesail/)
 * (@forcesail)
 * [1 year ago](https://wordpress.org/support/topic/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.
    1. **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
    2. **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.
    3. **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
    4. **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.
    5. **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’];
    6. **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)

 *  Plugin Author [A. Jones](https://wordpress.org/support/users/nomadcoder/)
 * (@nomadcoder)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479622)
 * Hi there. Thank you so much. As you may know, this plugin is more than 10 years
   old. I am sure there are many potential improvements. Please feel free to send
   me your updated code and please consider becoming an additional plugin author.
   [Shooflysolutions@gmail.com](https://wordpress.org/support/topic/some-necessary-code-improvement/Shooflysolutions@gmail.com?output_format=md)
 *  Thread Starter [Alexander Guskov](https://wordpress.org/support/users/forcesail/)
 * (@forcesail)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479627)
 * Thank you I will send.
 * Some errors more:
   1) Since php 8.3 all class property should be declared. You
   use a lot a properties created dynamicaly and PHP generate messages like:**Creation
   of dynamic property thumbnailgrid::$postid is deprecated**
 * 2) Are you sure that this code make sense?
 *     ```wp-block-code
               if (isset($atts['category']) && $atts['category'] && !$atts['cat'])            $atts['cat'] = $atts['category'];        //**********************PARSE OUT THE POST CATEGORY        $tax_query = array();        if (isset($atts['category']) && !isset($atts['cat'])) //check for category instead of cat            $this->$atts['cat'] = $this->atts['category'];
       ```
   
 *  Plugin Author [A. Jones](https://wordpress.org/support/users/nomadcoder/)
 * (@nomadcoder)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479634)
 * looks like duplicate code to me. I use visual code and it (The AI) does things
   like that sometimes.
 *  Thread Starter [Alexander Guskov](https://wordpress.org/support/users/forcesail/)
 * (@forcesail)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479644)
 * Text editor for code writing is the best! 🙂
   AI is a rubbish all around
 * I’ll send you my code tomorrow after check it with the 6.9 version of the plugin
 *  Plugin Author [A. Jones](https://wordpress.org/support/users/nomadcoder/)
 * (@nomadcoder)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479646)
 * great! Please add your wp user name so you can directly update the plugin in 
   the future.
 *  Thread Starter [Alexander Guskov](https://wordpress.org/support/users/forcesail/)
 * (@forcesail)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479699)
 * I’m sorry Adrian, but it seems that I examined version 6.8 (I downloaded v.6.9
   but it was v.6.8)
   Version 6.9 has too many errors: literals and sanitize functions
   doesn’t need and at least they works incorrectly. So the plugin almost doesn’t
   work at all. I found a quite good amount of errors and give up to force to work
   it. So I roll back to v.6.6.1 + my corrections.
 *  Plugin Author [A. Jones](https://wordpress.org/support/users/nomadcoder/)
 * (@nomadcoder)
 * [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479708)
 * Fair enough. I had to update the plugin because it was pulled from the repository.
   If you feel like letting me know what the errors were I will fix them if I have
   time. Take care!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Some necessary code improvement’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/thumbnail-grid.svg)
 * [Featured Image Thumbnail Grid](https://wordpress.org/plugins/thumbnail-grid/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/thumbnail-grid/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/thumbnail-grid/)
 * [Active Topics](https://wordpress.org/support/plugin/thumbnail-grid/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/thumbnail-grid/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/thumbnail-grid/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [A. Jones](https://wordpress.org/support/users/nomadcoder/)
 * Last activity: [1 year ago](https://wordpress.org/support/topic/some-necessary-code-improvement/#post-18479708)
 * Status: not a support question