Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
OctoberCMS 3 offers two classes to retrieve the version number of a plugin: **VersionManager** and **PluginVersion**. ## VersionManager The `getLatestVersion()` method of `\System\Classes\VersionManager` retrieves the current version of a plugin from the associated `version.yaml` file. This file is a fundamental requirement and should be included in every plugin since at least OctoberCMS v2. With this class, you can access the latest plugin version without the need for the plugin to be installed and regardless of whether it is activated or not. However, keep in mind that when using the `VersionManager`, the version specified in the `version.yaml` file may differ from the installed version stored in the database. **Example** The following code returns the version number of the "RainLab.User" plugin as a string or `0` if the plugin or the `version.yaml` file does not exist. ```php $versionManager = \System\Classes\VersionManager::instance(); echo $versionManager->getLatestVersion('RainLab.User'); ``` ## PluginVersion The class `\System\Models\PluginVersion` is, as the namespace suggests, an Eloquent model that maps to the native `system_plugin_versions` table, thus we can retrieve the latest installed version number from the respective column. This class therefore requires that the plugin is installed, but it also allows for a direct check to see if the plugin is currently activated as well. **Example** The following code demonstrates the use of the `PluginVersion` class in a typical Eloquent manner. With an additional `where` clause, like `where('is_disabled', 0)`, you can further restrict the selection to active plugins too. ```php $pluginVersion = `\System\Models\PluginVersion::where('code', 'RainLab.User')->first(); echo $pluginVersion ? $pluginVersion->version : 0; ``` ## Plugin Manager By the way, using the `\System\Classes\PluginManager` class, you can also quickly check whether a plugin exists or not. Similar to `VersionManager`, this class only verifies if the plugin directory (and necessary files) exists, without checking whether the plugin is installed or activated. **Example** The following code checks whether the `RainLab.User` plugin exists: ```php echo \System\Classes\PluginManager::instance()->hasPlugin('RainLab.User'); ```
References
Add additional online resources to your trick
×
Name
URL
×
Name
URL
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline