How can I get current version of custom plugin in wordpress

I want to compare the current version of my custom plug-in with update version of plug-in.

I get updated version of plug-in in response from server.

Read More

How can I get current version of my plug-in?

Related posts

4 comments

  1. You can use get_file_data() function which is available on frontend and backend. For example:

    get_file_data('/some/real/path/to/your/plugin', array('Version'), 'plugin');
    
  2. if you use get_plugin_data() on the frontend it will throw an error Call to undefined function get_plugin_data(). Here is the correct way to get plugin header data.

    if ( is_admin() ) {
        if( ! function_exists( 'get_plugin_data' ) ) {
            require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
        }
        $plugin_data = get_plugin_data( __FILE__ );
    
        echo "<pre>";
        print_r( $plugin_data );
        echo "</pre>";
    }
    
  3. You could save you version in the options table for easy retrieval. But you can also use get_plugin_data for more details about a given plugin.

    <?php
    
        $data = get_plugin_data( "akismet/akismet.php", false, false );
    
    ?>
    

    Please note that get_plugin_data is only available in the WordPress admin, it’s not a front-end available function.

  4. For users who land on this question to find out the current version of WordPress itself use this function.

    // it will show only numeric value i.e 5.8.2
    echo get_bloginfo( 'version' );
    

Comments are closed.