PHPackages                             awesome9/updates - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. awesome9/updates

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

awesome9/updates
================

WordPress update manager.

2.0.0(1y ago)0107↓93.3%GPL-3.0-or-laterShellPHP &gt;=5.6

Since May 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AwesomeNine/Updates)[ Packagist](https://packagist.org/packages/awesome9/updates)[ RSS](/packages/awesome9-updates/feed)WikiDiscussions master Synced today

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Updates
=======

[](#updates)

[![Awesome9](https://camo.githubusercontent.com/3c0c2d9b4a52297ff7faaf49e147ee8e6e96e0f435b798a6215c2e50ebc6bde3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417765736f6d652d392d627269676874677265656e)](https://awesome9.co)[![Latest Stable Version](https://camo.githubusercontent.com/2d93ea6ed652cc915f6518fc87602d089ddec5849178e96c27d5d0a2a9b045b5/68747470733a2f2f706f7365722e707567782e6f72672f617765736f6d65392f757064617465732f762f737461626c65)](https://packagist.org/packages/awesome9/updates)[![PHP from Packagist](https://camo.githubusercontent.com/d55c5d76f3dfa491284339d771e0cfe6348124c45f726eaad8438fbe476acca9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617765736f6d65392f757064617465732e737667)](https://packagist.org/packages/awesome9/updates)[![Total Downloads](https://camo.githubusercontent.com/b30ea7c3d595904ed0f495463528b62e3126e578e59b3971c54904261249fa00/68747470733a2f2f706f7365722e707567782e6f72672f617765736f6d65392f757064617465732f646f776e6c6f616473)](https://packagist.org/packages/awesome9/updates)[![License](https://camo.githubusercontent.com/4c55e16d69c8968684abc6c790966476dc9c54a840325c389594b2c2e7c6ee5d/68747470733a2f2f706f7365722e707567782e6f72672f617765736f6d65392f757064617465732f6c6963656e7365)](https://packagist.org/packages/awesome9/updates)

 [![](https://camo.githubusercontent.com/1cdca96b70c69a338a8ef84cccc7a3eb31a5522727149aad2012be5b4a3b66e0/68747470733a2f2f696d672e69636f6e73382e636f6d2f6e6f6c616e2f3235362f617070726f76652d616e642d7570646174652e706e67)](https://camo.githubusercontent.com/1cdca96b70c69a338a8ef84cccc7a3eb31a5522727149aad2012be5b4a3b66e0/68747470733a2f2f696d672e69636f6e73382e636f6d2f6e6f6c616e2f3235362f617070726f76652d616e642d7570646174652e706e67)

📃 About Updates
---------------

[](#-about-updates)

This package provides ease of running update routines within a WordPress plugin. It provides methods to check the current installed version of the plugin, determine which updates need to be applied, and apply those updates in order.

💾 Installation
--------------

[](#-installation)

```
composer require awesome9/updates
```

🕹 Usage
-------

[](#-usage)

### Step 1: Implement the `Updates` Class

[](#step-1-implement-the-updates-class)

To use the package, create a class that extends the `Updates` abstract class. Implement the following methods in your custom class:

- `get_updates()` - Returns an associative array of version numbers and update file paths.
- `get_folder()` - Returns the folder path where update files are stored.
- `get_version()` - Returns the current plugin version.
- `get_option_name()` - Returns the option name used to store the plugin version in the database.

```
use Awesome9\Updates\Updates;

class MyPluginUpdates extends Updates {

    /**
     * Define update versions and file paths.
     *
     * @return array
     */
    public function get_updates(): array {
        return [
            '1.0.1' => 'updates/update-1.0.1.php',
            '1.0.2' => 'updates/update-1.0.2.php',
        ];
    }

    /**
     * Specify the updates folder path.
     *
     * @return string
     */
    public function get_folder(): string {
        return plugin_dir_path( __FILE__ ) . 'updates/';
    }

    /**
     * Get the current plugin version.
     *
     * @return string
     */
    public function get_version(): string {
        return '1.0.2'; // Replace with your plugin's current version
    }

    /**
     * Define the database option name for storing the plugin version.
     *
     * @return string
     */
    public function get_option_name(): string {
        return 'awesome9_plugin_version';
    }
}
```

### Step 2: Initialize and Bind Hooks

[](#step-2-initialize-and-bind-hooks)

In your plugin’s main file, instantiate your `MyPluginUpdates` class and bind the hooks to handle updates automatically:

```
$my_plugin_updates = new MyPluginUpdates();
$my_plugin_updates->hooks();
```

### Step 3: Structure Your Plugin’s Update Files

[](#step-3-structure-your-plugins-update-files)

Arrange your plugin folder to include separate files for each update version. Your folder structure might look like this:

```
my-plugin/
└── updates/
   ├── update-1.1.0.php
   └── update-1.1.1.php

```

### Step 4: Write Update Files

[](#step-4-write-update-files)

Each update file should contain code for the specific update, like this example for `update-1.0.1.php`:

```
