• Resolved deanhatescoffee

    (@deanhatescoffee)


    I’m designing a theme. I’d like to use if(function_exists to check if Ultimate Tag Warrior is installed. So, basically, I *think* that I want to do something like merge

    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>

    with

    <?php UTW_ShowWeightedTagSetAlphabetical("coloredsizedtagcloud","","") ?>

    so that it checks to see if UTW exists, and then displays that (rather than a sidebar), but I’m not sure which part of the PHP code is needed for if(function_exists to work. How can this be done? Thanks in advance. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Should be simple

    if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar(1) && function_exists(‘anyUTWfunction’) ) etc

    but probably best to leave a note for users that UTW is required, else no widgets…

    Thread Starter deanhatescoffee

    (@deanhatescoffee)

    Bad choice of words – I should clarify – I don’t want to actually “merge” the widgets sidebar and UTW; rather, I just want to use if(function_exists to say, “If UTW is installed then use it; otherwise, just display the regular WP categories.” I only mentioned the sidebar code above because that’s the only time I’ve seen if(function_exists in WP. Sorry about the confusion. ??

    From my example
    UTW_ShowWeightedTagSetAlphabetical("coloredsizedtagcloud","","")
    what is the proper function in this case? Is it UTW_ShowWeightedTagSetAlphabetical or is it something else altogether?

    Aside from knowing that if(function_exists is used for the widget sidebars, I know practically nothing about it, so any and all help is appreciated. My ultimate goal is to use if(function_exists for other popular plugins as well, just to make my theme more out-of-the-box friendly.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    The function you’re actually calling is the one you should be checking for. Like so:

    <?php
    if (function_exists('UTW_ShowWeightedTagSetAlphabetical')) {
    UTW_ShowWeightedTagSetAlphabetical("coloredsizedtagcloud","","");
    }
    ?>

    function_exists does more or less exactly what you’d expect it to do. If the function you pass to it exists, then it returns true. So if you’re wanting to call function aaa(), but don’t know if that function has been declared (or that the aaa plugin is active), then you can check for it first. Like so:

    if (function_exists('aaa')) {
    aaa(parameters);
    }
    else {
    // optional: no aaa, so do something else
    }

    More info:
    https://php.net/function_exists

    Thread Starter deanhatescoffee

    (@deanhatescoffee)

    Excellent – thanks Otto! It seems much easier than I anticipated. I’ll post back if I run into any issues. Thanks again. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘If Function Exists – “Pluginifying” my Theme’ is closed to new replies.