samtiria / nextgen-gallery

Automatically exported from code.google.com/p/nextgen-gallery
0 stars 0 forks source link

Filter 'ngg_pre_add_new_image' applied twice #446

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Write a plugin that defines a 'ngg_pre_add_new_image' filter
2. Add new images in NextGEN bt importing a folder on the server file system
3. See that your filter is applied twice

What version of the product are you using? On what operating system?

NGG 1.9.0 on WP 3.2.1

Please provide any additional information below.

In admin/functions.php is code to import galleries from file system folders. 
When this is run, a filter named 'ngg_pre_add_new_image' is applied twice, 
which seems wrong to me.

First, in function import_gallery, this line can be found:

$picture = apply_filters('ngg_pre_add_new_image', $picture, $gallery_id);

just before the images are added to the database with

nggAdmin::add_Images($gallery_id, $new_images);

However, in function add_Images, the first thing that is done for each image, 
is apply the filter again:

if ( is_array($imageslist) ) {
foreach($imageslist as $picture) {

// filter function to rename/change/modify image before
$picture = apply_filters('ngg_pre_add_new_image', $picture, $galleryID);

Since add_Images is called in multiple places, it seems to me that that would 
be the correct place to apply the filter. The explicit filter application in 
function import_gallery should be removed.

Original issue reported on code.google.com by martijng...@gmail.com on 9 Dec 2011 at 8:28

GoogleCodeExporter commented 8 years ago
I need this filter for a custom plugin where I check before the import if the 
file is a WMF image. For this case I introduced this two filter position. Agree 
that it's better to rename that, but I think it's possible to handle this on 
your side

Original comment by alex.cologne on 10 Dec 2011 at 1:22

GoogleCodeExporter commented 8 years ago
Too bad, but I'll fix it on my side. Thanks.

Original comment by martijng...@gmail.com on 12 Dec 2011 at 10:24