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:
wp-content/plugins/lazyest-gallery/
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.
Questions and Comments are Welcome