NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Last modified : Oct 01 2022
Estimated reading time : 1 minute, 41 seconds - 152 words
Share the post "Display the Current Version Of Your WordPress Plugin"
Below is a tutorial that will show you how to validate and display the version of your plugin. Our function will need to validate the version of the WordPress plugin. This can also be beneficial in order to automate the plugin’s update by using a variable parameter.
As you know in our main plugin file we need the core parameters such as version for example.
This is an exemple :
Display the Current Version Of Your WordPress Plugin
/* Plugin Name: Le nom du Plugin Plugin URI: Url de l'auteur ou du site web Description: Description du plugin Version: 2.4 Author: Le nom de l'auteur Author URI: URI du plugin */
In the example below, we will create a function that will look the written version in the Version data (Fetching the 2.4) :
function ma_function_version_number() { // If get_plugins() isn't available, require it if ( ! function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Variable et donner get dans le folder $plugin_folder = get_plugins( '/' . 'nomdufichierplugin' ); // Le fichier ou se trouve la déclaration du plugin $plugin_file = 'mapageprincipaleduplugin.php'; // Afficher le numéro de la version ou retourner un résultat vide if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) { return $plugin_folder[$plugin_file]['Version']; } else { // Otherwise return null return NULL; } }
This funciton will net the data found under Version. It does an echo thus displaying the 2.4.
We then display the results somewhere in the plugin.
<?php $version = ma_function_version_number(); echo $version; ?>
And voilà! Once you’ll update the plugin and change the version number, it will be automatically updated in the plugin itself.