WordPress.org

Ready to get started?Download WordPress

Forums

Before upgrading, wrap your plugins (28 posts)

  1. Mark (podz)
    Support Maven
    Posted 8 years ago #

    If you have plugin functions in your theme, there is the risk that when you upgrade and something goes wrong, that plugin code will throw you an error.

    So if the plugin says to use this:
    <?php wp_grins(); ?>

    Then you need to alter that to be like this:
    <?php if (function_exists('wp_grins')) wp_grins(); ?>

    That way, if no plugin, no error from the theme.

  2. vkaryl
    Member
    Posted 8 years ago #

    Good advice.... and in fact I started doing that on all themes I was using or developing about 3 months back. It's a little bit of extra code, but worth it!

  3. Mark (podz)
    Support Maven
    Posted 8 years ago #

    I just remembered what a very good idea this was :)

  4. chaaban
    Member
    Posted 8 years ago #

    Should we also make this in a plugin it self ?

    <?php if (!function_exists('wp_grins')) wp_grins(); ?>

    // adding the negation !

  5. davidchait
    Member
    Posted 8 years ago #

    no, adding the negation is erroneous -- if the function doesn't exist, you can't (and shouldn't) call it... ;)

  6. chaaban
    Member
    Posted 8 years ago #

    sorry i meant 2 make definition if it dont exist ...

    if (! function_exists("my_function"))
    {
    function my_function () { }
    }

  7. Beel
    Member
    Posted 8 years ago #

    I was waiting for someone to say something. If there isn't a tree in the woods, does it make a sound when it falls? ;-)

  8. Mark (podz)
    Support Maven
    Posted 8 years ago #

    Yes - you just said it wasn't in the woods :)

  9. Beel
    Member
    Posted 8 years ago #

    Yep and the function still works in other programs, but it doesn't make a sound in WP if it doesn't exist there ;-). The analogy I was going for (and guess didn't get):
    Tree = function
    woods = WP
    make a sound = work
    falls = is called

  10. vkaryl
    Member
    Posted 8 years ago #

    Um.... so what am I supposed to wrap my plugins with now? I am NOT the brightest light in the universe upon many occasions, this being the current one....

  11. Beel
    Member
    Posted 8 years ago #

    Don't wrap the plugins, just wrap the function calls in case the plugin is not activated. If the plugin is not activated the function will not exist and you will get a fatal error and bring down your site unless the call is wrapped with the test for its existence.

  12. vkaryl
    Member
    Posted 8 years ago #

    Beel.... pretend I'm an idiot (well, okay, you don't HAVE to pretend....)

    If we are talking about themeswitcher for instance, exactly what is the "new" version of the call I should be using in the sidebar - the whole thing, please and thank you....

  13. Beel
    Member
    Posted 8 years ago #

    I was just copying something from my index page...

    I have plugins which replace regular WP tags. Instead of replacing the tags. I do something like:
    <p id="prev_next_links">
    <?php if (!function_exists('wp_pagenavi')) posts_nav_link(' | ', __('« Previous Page'), __('Next Page »')); echo "
    "; ?>

    <?php if (function_exists('wp_pagenavi')) wp_pagenavi(); ?>
    </p>

    That way, if my plugin is not activated, WP's regular tag will be used.

    And here is what I have for theme-switcher...
    <?php if (function_exists("wp_theme_switcher")) { ?>
    <li>Themes
    <?php wp_theme_switcher('dropdown'); ?>
    </li>
    <?php } ?>

    It is a little different from many because I also wrap the li's - no since in having an empty line in my list if theme-switcher is deactivated. Get it?

  14. chaaban
    Member
    Posted 8 years ago #

    <?php if (function_exists('wp_theme_switcher')) { ?>
    <h2><?php _e('Themes:'); ?></h2>
    <?php wp_theme_switcher(); ?>

    <?php } ?>

  15. chaaban
    Member
    Posted 8 years ago #

    did i just mess arround wordpress posts ?

    this is what i tought there is something wrong in wordpress strip tag issue

  16. vkaryl
    Member
    Posted 8 years ago #

    So now it needs both the "normal" (as posted by podz in the first post above, and as I'm currently using) and the one with the "!"?

    Okay, I get what you mean about wrapping the li tags - makes sense, I'll redo some stuff.... but what is it with the "!"?

  17. Beel
    Member
    Posted 8 years ago #

    No, you wrap not with code tag but backticks.

  18. chaaban
    Member
    Posted 8 years ago #

    no you dont need the one with ! ,

    the one with ! is for plugin programmer , its just in case the programmer gave a function name that allready exist .

  19. vkaryl
    Member
    Posted 8 years ago #

    Ah. Okay.... that makes more sense. Couldn't see what it could be needed for.

    Thanks to both of you....

  20. Beel
    Member
    Posted 8 years ago #

    Just says this: If my plugin is deactivated and this function is not available, use this other one that comes with WP. But if it is activated use it instead of the WP function.

    Edit: Oops, I misunderstood what you were asking. Thought you were referring to my post.

  21. chaaban
    Member
    Posted 8 years ago #

    is the post disorted or i'm the only one who see the posts disorted now ?

  22. Beel
    Member
    Posted 8 years ago #

    You are using IE. Fix your post with li's so they look like this:

    backtick<backtickli>
    backtick<backtick/li>

  23. chaaban
    Member
    Posted 8 years ago #

    is this a bug issue ? because i was testing on some wordpress blog to post long words (just tests issues), it messed all there blog apparence and it became disorted .

    here is what i mean : see this blog :

    blog.meebo.com/?p=65 (see how the page look and my last post)

    how can we prevent such thing to happen ?

  24. Mark (podz)
    Support Maven
    Posted 8 years ago #

    chaaban, doyouknowanyreallylongwordsthatwouldbesolongtobreakthecommentsbox ?
    Orwouldmostpeople use spaces ?

    Not a bug :)

  25. chaaban
    Member
    Posted 8 years ago #

    i mean just if someone would like to act in a bad way :) and mess your blog (o'.'o) like i did for the poor guy but it was just tests issues :p

    Automatic wraping like in your post :)

  26. Mark (podz)
    Support Maven
    Posted 8 years ago #

    Put spaces in :)

  27. chrisfiddes
    Member
    Posted 8 years ago #

    It would be nifty if someone could write some kind of generator app which could take input in the form of a plugin function call and output it as wrapped code automatically. Just a thought... :)

  28. electrolund
    Member
    Posted 8 years ago #

    Sorry for resurrecting old threads, but I have a question about this. I've got the function_exists PHP command working nicely for the Gravatar plugin in my comments.php file.

    But when trying to use it with Viper's Plugins Used plugin, it seems to kill the plugin output:

    <?php if (function_exists('viperspluginsused')) { ?>
    <?php $viperspluginsused = new viperspluginsused(); ?>
    <?php $viperspluginsused->output_table('id="pluginstable"', TRUE, TRUE); ?>
    <?php } ?>

    What am I doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags