Hide .JPG.files From Lazyest Gallery Plugin – WordPress

This has been updated to also remove .JPEG.files and .PNG.files from the Lazyest Gallery. Now it removes .JPG.files, .JPEG.files, and .PNG.files.

Here I am altering the core file of the “Lazyest Gallery” Plugin by Macbrink. I love the Lazyest Gallery plugin; it’s actually my favorite one. However, my problem with the plugin was this: most of my pictures have an attached directory (a folder) with a name that ends with ‘.JPG.files‘ and I did not want that folder displayed as a sub-gallery. I needed to hide my ‘.jpg.files‘ directories. These are directories, not simply files with a file extension.

My code below changes the core file of the plugin in order to exclude directories with a file name ending with ‘.JPG.files‘ from being displayed in the gallery as folders.

I only edit one file in the plugin. Look inside the plugin directory:

The file to edit is: /lazyest-gallery.php

Open the file and find the following chunk of code. It should begin at about Line 592:

function valid_dir( $adir ) {
    if ( ! is_dir( $adir ) ) 
      return false; 
    $forbidden = $this->get_option( 'excluded_folders' );
    $forbidden = ( false !== $forbidden ) ? $forbidden : array();
    $forbidden[] = '..';
    $forbidden[] = '.';
    return ! in_array( basename( $adir ), $forbidden );

Now, make room for 4 lines in the code above. Just put your cursor at the beginning of this line (should be Line 599):

    return ! in_array( basename( $adir ), $forbidden );

Then press ‘Enter’ six times to push that line of code down, while also making six empty lines. Now, directly on those empty lines, insert the following:

 $forbidden[] = (strpos($adir, '.JPG.files') == true);//isabel adds this line
 $forbidden[] = (strpos($adir, '.jpg.files') == true);//isabel adds this line
 $forbidden[] = (strpos($adir, '.JPEG.files') == true);//isabel add this line
 $forbidden[] = (strpos($adir, '.jpeg.files') == true);//isabel add this line
 $forbidden[] = (strpos($adir, '.PNG.files') == true);//isabel add this line
 $forbidden[] = (strpos($adir, '.png.files') == true);//isabel add this line

You may notice that each pair of lines above are basically the same, except that one has lowercase .jpg, .jpeg, and .png, while the other has uppercase .JPG, .JPEG, and .PNG. The strings are case sensitive, so both are needed.

If you did it correctly, you should have inserted the code below Line 598, so this pasted code should become the new Lines 599-604. You’re not replacing or deleting anything; only inserting 6 extra lines. Save and upload back to your server.

Now those “.jpg.files”, “.jpeg.files” and “.png.files” will be excluded or hidden from your gallery.

NOTE: This code modifies the plugin core. If you do this, keep a change log of your changes. You’ll have to make these changes again after upgrading the Lazyest Gallery plugin to a new version. As always, modifications made to the plugin core will be overridden when you upgrade the plugin. The extra work is worth it to me, for a plugin that does what I want it to do. I keep a simple changelog, and re-doing the changes after an upgrade takes me about 2 minutes.

See more: ,


Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: