1. Go to this page and download the library: Download wp-forge/wp-upgrade-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wp-forge / wp-upgrade-handler example snippets
use WP_Forge\UpgradeHandler\UpgradeHandler;
// Define the current plugin version in the code
define( 'MY_PLUGIN_VERSION', '1.4.1' );
// Only handle upgrades in the admin
if ( is_admin() ) {
// Handle plugin upgrades
$upgrade_handler = new UpgradeHandler(
__DIR__ . '/upgrades', // Directory where upgrade routines live
get_option( 'my_plugin_version' ), // Old plugin version (from database)
MY_PLUGIN_VERSION // New plugin version (from code)
);
// Returns true if the old version doesn't match the new version
$did_upgrade = $upgrade_handler->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 );
}
}