Forums

OptionTree
[resolved] Fatal Error with declaring this plugin (20 posts)

  1. lynclark
    Member
    Posted 1 year ago #

    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/

  2. temash
    Member
    Posted 1 year ago #

    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;
    }
    }

  3. idapostle
    Member
    Posted 1 year ago #

    Thanks temash. Worked perfectly. Many thanks.

  4. lynclark
    Member
    Posted 1 year ago #

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

  5. sjacob
    Member
    Posted 1 year ago #

    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?

  6. idapostle
    Member
    Posted 1 year ago #

    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.

  7. zyonuair
    Member
    Posted 1 year ago #

    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

  8. sjacob
    Member
    Posted 1 year ago #

    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!!

  9. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

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

  10. gatorfantom
    Member
    Posted 1 year ago #

    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.

  11. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

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

  12. gatorfantom
    Member
    Posted 1 year ago #

    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

  13. Cudazi
    Member
    Posted 1 year ago #

    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.

  14. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

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

  15. Cudazi
    Member
    Posted 1 year ago #

    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.

  16. Cudazi
    Member
    Posted 1 year ago #

    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. :)

  17. gatorfantom
    Member
    Posted 1 year ago #

    Thanks to both Derek and Curt (Cudazi) for responding so quickly and for talking through possible workarounds. It's nice to see developers/authors collaborating like this. Says a lot about the integrity of their work.

    Speaking of which... I don't throw praise around very often, but I thought everyone reading this thread should know that Derek and Curt are two of the best in the business. OptionTree is just one of Derek's amazing plugins, and he also does phenomenal custom themes and sites. His portfolio speaks for itself. (You'll probably recognize some of his work). And if you're looking for something pre-made, (IMO) Curt has the most beautiful, well-balanced themes on Themeforest, hands down. The next time you're shopping for a simple, elegant, user-friendly theme - I highly recommend checking out his stuff.

    (And no, those aren't affiliate links. Just a couple endorsements/testimonials.)

  18. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    @cudazi Nice workaround!

    Also, to clarify the only time this error will pop up is during activation if the get_option_tree() function is being created by a theme before the plugin is loaded. I could remove the include from the admin side but enough people have requested it that it seems worth finding a workaround that best suits everyone involved.

    Glad we could all come together and find a solution.

    Cheers,
    Dererk

  19. virtuosohaven
    Member
    Posted 1 year ago #

    My entire project is stalled — thanks to Option Tree... It just stopped registering changes in the fields — does not allow me to make any changes — upload images / add or remove slides... not even change colors of the links... I wrote to themeforest for a refund on the theme I purchased at their site — which included Option Tree by default — super skeleton — let alone the damage it has caused me for the delayed launch of my nonprofit website... None of the forums provide valid information on how to fix this — nor have I got any response for the messages I wrote to Themeforest and to the link I was led to for Option Tree... Good luck Option Tree users... T

  20. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    @virtuosohaven I'm sorry you're having trouble with the plugin, but I can't reproduce the issue no matter how hard I try. Can you give me more info about your setup and I'll try and figure out a solution.

    WP Version
    PHP Version
    MySQL Version
    Single or Multisite
    Hosting Provider
    Clean Install or existing data
    Installing from OT files etc.

    Also, if you would email me your login info to the site I can try and see if there is anything that may be causing this that's not obvious? derek[at]valendesigns[dot]com

    Cheers,
    Derek

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic