Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Check before using wpthumb() #81

Open
jgalea opened this issue Sep 17, 2013 · 10 comments
Open

Check before using wpthumb() #81

jgalea opened this issue Sep 17, 2013 · 10 comments

Comments

@jgalea
Copy link

jgalea commented Sep 17, 2013

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
Copy link
Member

@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.

@ghost ghost assigned joehoyle Sep 18, 2013
@mecha
Copy link

mecha commented Sep 18, 2013

@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
Copy link
Member

@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
Copy link

mecha commented Sep 18, 2013

@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
Copy link
Member

@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
Copy link

mecha commented Sep 18, 2013

@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
Copy link
Member

@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
Copy link
Author

jgalea commented Sep 18, 2013

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

@joehoyle
Copy link
Member

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
Copy link
Author

jgalea commented Oct 24, 2013

Is this related? #83

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants