{"id":23387240,"url":"https://github.com/wp-forge/wp-upgrade-handler","last_synced_at":"2025-04-11T05:09:15.151Z","repository":{"id":57082021,"uuid":"265712512","full_name":"wp-forge/wp-upgrade-handler","owner":"wp-forge","description":"A drop-in library for handling upgrade routines in WordPress plugins and themes.","archived":false,"fork":false,"pushed_at":"2020-05-21T00:07:08.000Z","size":2,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T05:09:07.864Z","etag":null,"topics":["wordpress-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-forge.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-21T00:04:08.000Z","updated_at":"2024-06-16T14:46:07.000Z","dependencies_parsed_at":"2022-08-24T14:58:18.525Z","dependency_job_id":null,"html_url":"https://github.com/wp-forge/wp-upgrade-handler","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-upgrade-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-upgrade-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-upgrade-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-upgrade-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-forge","download_url":"https://codeload.github.com/wp-forge/wp-upgrade-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345266,"owners_count":21088244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress-library"],"created_at":"2024-12-22T01:15:22.332Z","updated_at":"2025-04-11T05:09:15.127Z","avatar_url":"https://github.com/wp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress Upgrade Handler\n\nA drop-in library for handling upgrade routines in WordPress plugins and themes.\n\n## Installation\n\n- Run `composer require wp-forge/wp-upgrade-handler`\n- Make sure you require the `vendor/autoload.php` file in your project.\n\n## Usage\n\nHere is an example of how to use this library in a WordPress plugin or theme:\n\n```php\n\u003c?php\n\nuse WP_Forge\\UpgradeHandler\\UpgradeHandler;\n\n// Define the current plugin version in the code\ndefine( 'MY_PLUGIN_VERSION', '1.4.1' );\n\n// Only handle upgrades in the admin\nif ( is_admin() ) {\n\n\t// Handle plugin upgrades\n\t$upgrade_handler = new UpgradeHandler(\n\t\t__DIR__ . '/upgrades',              // Directory where upgrade routines live\n\t\tget_option( 'my_plugin_version' ),  // Old plugin version (from database)\n\t\tMY_PLUGIN_VERSION                   // New plugin version (from code)\n\t);\n\n\t// Returns true if the old version doesn't match the new version\n\t$did_upgrade = $upgrade_handler-\u003emaybe_upgrade();\n\n\tif ( $did_upgrade ) {\n\t\t// If an upgrade occurred, update the new version in the database to prevent running the routine(s) again.\n\t\tupdate_option( 'my_plugin_version', MY_PLUGIN_VERSION, true );\n\t}\n}\n```\n\nIf 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.\n\n### Creating an Upgrade Routine\nAs 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.\n\nThe following would be the contents of that file:\n\n```php\n\u003c?php\n\n// Rename 'old_option' to 'new_option', if necessary.\n$old_option = get_option( 'old_option' );\nif( $old_option ) {\n    update_option( 'new_option', get_option( 'old_option' ) );\n    delete_option( 'old_option' );\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Fwp-upgrade-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-forge%2Fwp-upgrade-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Fwp-upgrade-handler/lists"}