Support » Alpha/Beta/RC » Before upgrading, wrap your plugins

  • Mark (podz)


    Support Maven

    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.

Viewing 15 replies - 1 through 15 (of 27 total)
  • 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!

    Mark (podz)


    Support Maven

    I just remembered what a very good idea this was 🙂

    Should we also make this in a plugin it self ?

    <?php if (!function_exists(‘wp_grins’)) wp_grins(); ?>

    // adding the negation !

    no, adding the negation is erroneous — if the function doesn’t exist, you can’t (and shouldn’t) call it… 😉

    sorry i meant 2 make definition if it dont exist …

    if (! function_exists(“my_function”))
    function my_function () { }

    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? 😉

    Mark (podz)


    Support Maven

    Yes – you just said it wasn’t in the woods 🙂

    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

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

    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.

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

    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(); ?>

    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”)) { ?>
    <?php wp_theme_switcher(‘dropdown’); ?>
    <?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?

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

    <?php } ?>

    did i just mess arround wordpress posts ?

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

    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 “!”?

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Before upgrading, wrap your plugins’ is closed to new replies.