humanmade / WPThumb

:warning: UNMAINTAINED :warning: On demand image resizing for WordPress
https://humanmade.co.uk/wpthumb/
170 stars 32 forks source link

Check before using wpthumb() #81

Open jgalea opened 11 years ago

jgalea commented 11 years ago

I think there should be a check before declaring wpthumb(), to check that it's not already been called by a plugin using the WP Thumb class.

In my plugin I am checking for existing of the class before including it:

/* Load WPThumb */
if ( ! class_exists( 'WP_Thumb' ) ) { 
    include ( WPRSS_ET_INC . 'libraries/WPThumb/wpthumb.php' );    
}

See error below:

Plugin could not be activated because it triggered a fatal error. Fatal error: Cannot redeclare wpthumb() (previously declared in /home/wprss/public_html/wp-content/plugins/wp-rss-excerpts-thumbnails/includes/libraries/WPThumb/wpthumb.php:569) in /home/wprss/public_html/wp-content/plugins/wp-thumb/wpthumb.php on line 566

joehoyle commented 11 years ago

@jgalea I am not sure if I understand - do you have the WP Thumb plugin in two places on your site?

If so, whatever is including it should do the check if it already exists, not WP Thumb. If you require a PHP file it's the caller's job to check if the file need not be included.

mecha commented 11 years ago

@joehoyle Hi, I am working with jgalea. The issue we are having is that our plugin, which comes bundled with WPThumb, makes a check if WPThumb is installed and active already on the WordPress site.

However, our plugin is being loaded prior to any potential WPThumb installations. Thus, we are unable to prevent the redeclare error.

Can WPThumb be adjusted to check if any other plugins might already have declared WPThumb ?

joehoyle commented 11 years ago

@mekku93 Ahh I see, is it possible to do this check/load on the plugins_loaded action instead of when your plugin is loaded?

mecha commented 11 years ago

@joehoyle Thanks for the quick reply. I actually tried that, but if ( !class_exists( 'WP_Thumb' ) ) in a function that runs on the plugins_loaded hook still produces the error. Edit: To elaborate further: the if statement evaluates to true when I activate WPThumb AFTER our plugin is already active. On plugins_loaded, our plugin is still including its own WPThumb.

joehoyle commented 11 years ago

@mekku93 that's very odd - as it looks like this is conflicting with the plugin WP Thumb. I don't want to add anything to WP Thumb without understanding the problem better - as this should work.

mecha commented 11 years ago

@joehoyle I know, right ? When I comment the include_once line of code, the error is not raised. So the problem is definitely our WPThumb detection if statement, which is falling through.

Although, the error is being raised on the wpthumb() function, rather than the WP_Thumb class. I looked at the code and they are both in the same file, but the class is declared before the function. Not sure if that helps you in diagnosing it.

joehoyle commented 11 years ago

@mekku93 can you check that the version of the plugin in plugins dir is the latest? It's possible it's a very old version of the plugin perhaps?

jgalea commented 11 years ago

@joehoyle It's the latest one, freshly downloaded from the WP repository.

joehoyle commented 11 years ago

Hi @jgalea ,

I can not do much more debugging here without seeing the reproducible code, so I am not sure what other help I can offer. I think we agree that this should not be happening, so I suspect an edge case. In might just be a case of you hammering at it to track down how this is happening.

Thanks

jgalea commented 11 years ago

Is this related? https://github.com/humanmade/WPThumb/pull/83