• I am developing a plugin and I need to check which version of WP is installed to know whether or not to display a dashboard widget. I attempted to use a if(function_exists('wp_add_dashboard_widget')) but that did not work. So now I am thinking that I should check the version and if it is below version 2.7, then the function will not be called.

    Anybody know how or have alternate suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    function_exists is best for a function check (especially if you’re going to call that function), but make sure you have the name right. Also, remember that not all functions get loaded immediately. Your plugin might come before that part of the dashboard gets run. Try putting your checks into an init function then waiting for admin_init or init by using an action hook. If function_exists returns false, then that function hasn’t loaded yet and you cannot use it.

    If you really need to check the WP version (this almost never happens):

    global $wp_version;
    if (version_compare($wp_version, '2.7', '>=')) {
    // version is 2.7 or higher
    }

    Thread Starter bandicootmarketing

    (@tinkerpriest)

    Thanks Otto42. Let do some more fiddling around and see if I can get the function_exists() to work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can I check which version of WP is installed using PHP?’ is closed to new replies.