https://github.com/wp-forge/wp-upgrade-handler
A drop-in library for handling upgrade routines in WordPress plugins and themes.
https://github.com/wp-forge/wp-upgrade-handler
wordpress-library
Last synced: about 1 year ago
JSON representation
A drop-in library for handling upgrade routines in WordPress plugins and themes.
- Host: GitHub
- URL: https://github.com/wp-forge/wp-upgrade-handler
- Owner: wp-forge
- Created: 2020-05-21T00:04:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-21T00:07:08.000Z (about 6 years ago)
- Last Synced: 2025-04-11T05:09:07.864Z (about 1 year ago)
- Topics: wordpress-library
- Language: PHP
- Homepage:
- Size: 1.95 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# WordPress Upgrade Handler
A drop-in library for handling upgrade routines in WordPress plugins and themes.
## Installation
- Run `composer require wp-forge/wp-upgrade-handler`
- Make sure you require the `vendor/autoload.php` file in your project.
## Usage
Here is an example of how to use this library in a WordPress plugin or theme:
```php
maybe_upgrade();
if ( $did_upgrade ) {
// If an upgrade occurred, update the new version in the database to prevent running the routine(s) again.
update_option( 'my_plugin_version', MY_PLUGIN_VERSION, true );
}
}
```
If you just released version `1.4.1` of your plugin, but created upgrade routines for `1.4.1` and `1.3.9`, anyone upgrading from version `1.3.8` or earlier would have both of those upgrade routines run automatically. If someone is upgrading from version `1.3.9` or greater, then only the `1.4.1` upgrade routine would be run.
### Creating an Upgrade Routine
As an example, let's assume I just released version `1.4.1` of my plugin. The upgrade routine needs to change an option name in the database. All I need to do after adding the previous code from above is to create a file named `1.4.1.php` in my `upgrades` directory.
The following would be the contents of that file:
```php