• Resolved lynclark

    (@lynclark)


    Hi there – having a terrible time getting this plugin to work. We had to uninstall the plugin when our website was running extremely slow, and then when we went to reinstall we get this message when we try to activate it:

    Fatal error: Cannot redeclare get_option_tree() (previously declared in M:\web\2011.johnnyshalloffame.com\wordpress\wp-content\themes\mono\libraries\theme-options.php:23) in M:\web\2011.johnnyshalloffame.com\wordpress\wp-content\plugins\option-tree\functions\get-option-tree.php on line 52

    Ideally we need this solved ASAP, since this is for a business’ site that we’d like to implement next week. Any ideas would be greatly appreciated!!!

    Thanks!

    http://wordpress.org/extend/plugins/option-tree/

Viewing 15 replies - 1 through 15 (of 19 total)
  • Make the following, open /libraries/theme-options.php and remove this lines:

    // If get_option_tree function does not exist (plugin not installed)
    // Return false to suppress errors in the theme where the function is used
    if ( ! function_exists( ‘get_option_tree’) ) {
    function get_option_tree() {
    return false;
    }
    }

    Thanks temash. Worked perfectly. Many thanks.

    Thread Starter lynclark

    (@lynclark)

    Yes it worked great! Thanks very much for the quick response!

    I just tried to do as instructed above after having received the same error. Perhaps i just don’t know how to go about it. I opened the file in text edit, deleted the text mentioned above, closed text edit, then deleted Option Tree and tried to redownload and activate. I am getting the same fatal error. Am i missing something?

    sjacob—I did not delete and reinstall OptionTree, I just reactivated it after I made the change outlined by temash. Hope you manage to get it working.

    En comparación con el tipo de portero Benítez también debe tener la tecnología en la pelota, la pelota hacia adelante, la teoría de vacío, volar más. Gasperini también se utiliza el método de Conti C video, explica el Camisetas del Barcelona 2012 análisis con el equipo después. Tags : uniformes de futbol Categories : camiseras de futbol, uniformes de futbol \xBF De Beijing a las 05:00 23 de diciembre 2010 a 11

    idapostle, thanks for the reply. I am new, new, new to all this and I found the text in the folder on my computer. Once it occurred to me to go to the folder in my host website I deleted it, did as you instructed and now it works. Thanks so much!!

    Plugin Author Derek Herman

    (@valendesigns)

    The issue here is not with OptionTree it’s the way a particular theme is using it.

    Derek, can you comment on the viability of the solution that temash suggested? I’ve been using OptionTree for a while now, love it, and have never had any problems with it – until today when I updated to the newest version (1.1.8). Now I’m seeing that same “Fatal / Cannot redeclare” error. The 1.1.8 update also deactivated the plugin (thus changing the site interface considerably) and will not let me reactivate it. I just keep getting the same error.

    Plugin Author Derek Herman

    (@valendesigns)

    @gatorfantom What theme are you using? Nothing changed with the get_option_tree() function other than the fact it is being included in the admin area so other plugins can use it. OT hasn’t changed the function or how it’s called

    The issue here is that your theme is highjacking the function before it’s created, so when OT tries to activate, it fails because your theme creates the get_option_tree() function when it’s not supposed to.

    A quick and dirty solution would be to deactivate your theme, activate OT, then activate your theme. That way the function is properly created by OT and not your theme. I’ll push a patch ASAP but for now do the above.

    For theme authors, you shouldn’t try and redeclare a function that isn’t wrapped in a function_exists() statement, you’re just going to throw errors if the load order hit’s your theme first.

    Cheers!

    Hey Derek – thanks for the quick response and detailed explanation. That makes sense. I went ahead and did what temash suggested, and everything’s fine.

    I didn’t realize it until just now, but the OP is using the same theme as me (which explains why there aren’t too many people reporting the issue.) I think the theme author (Curt) uses OptionTree in a few of his themes, so I’ll shoot him an email and let him know what’s going on, give him a link to this thread, etc.

    Thanks again.

    -Tom

    I apologize Derek for the time this ate up on your end & for the folks who this affected.

    I wanted a way to use the function in a wrapper I created to extend it without having so many if-function-exists all through my theme, so I decided to declare the function and simply return false if it didn’t exist (eg – plugin not installed).

    The function causing trouble declares get_option_tree if not found so my wrapper below doesn’t need the if-function-exists, etc…

    if ( ! function_exists( 'get_option_tree') ) {
    	function get_option_tree() {
    		return false;
    	}
    }

    Simplified version of my wrapper fx, taking in get_option_tree as a first param

    $my_option = cudazi_get_option(
    get_option_tree( xxxxx ), // uses get_option_tree, false if not installed, or a value
    $fallback_value = "green",
    $custom_field_override_key = "color_override"
    ){
    // function code
    // returns the get_option_tree value if found, if not the fallback or custom field
    }

    I’ll implement a quick die() with instructions in the interm to be sure the plugin gets installed/activated before the theme.

    Plugin Author Derek Herman

    (@valendesigns)

    @cudazi No worries, but the better solution would be to not call a function in the parameter of a function unless your know that function exists. Wouldn’t it be better to take in the param and then check if get_option_tree is available after the fact? If it’s not then you could go as far as to re-create the get_option_tree() function but call it something else and use it as a backup.

    Yea, my thinking was that the if function_exists would catch that the plugin wasn’t there and I could simply declare that fx to cut down extra coding. Live and learn I guess. 🙂

    Is there a hook I should tie into where I could safely declare get_option_tree() after OptionTree is not found? (what I was trying to accomplish with if function exists.) It may be the best mix until I can do a more involved rewrite.

    Just an update, here’s a workaround that still allows for the site to be functional without the plugin installed and won’t throw an error on plugin install or update:

    Replace this on line 21 of libraries/theme-options.php:

    if ( ! function_exists( 'get_option_tree') ) {

    With this:

    if ( ! function_exists( 'get_option_tree') && ! is_admin() ) {

    It will then allow the function to be created by the plugin, and use the OptionTree created function instead down the road.

    I’ll be re-working how my code accesses OptionTree, please post additional theme-related questions/problems via my ThemeForest profile page or freebies via Cudazi.com so we don’t take up Derek’s time, his plugin is working fine. 🙂

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Plugin: OptionTree] Fatal Error with declaring this plugin’ is closed to new replies.