WordPress.org

Ready to get started?Download WordPress

Forums

How can I check which version of WP is installed using PHP? (3 posts)

  1. c.bavota
    Member
    Posted 5 years ago #

    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?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    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
    }
  3. c.bavota
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic