Update custom plugin with WP-CLI

You would implement this:

https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/

First you would add a Update URI: header to your plugin with a custom domain.

Second, you would add a filter to your plugin, using the filter name update_plugins_{$hostname} where {$hostname} is the value you gave your Update URI: . E.g. Update URI: example.com would have the filter update_plugins_example.com.

In this filter, you would then run some code that checks if there is an update for your plugin. When your code is finished running, it will return the answer.

https://developer.wordpress.org/reference/hooks/update_plugins_hostname/

The value you return will need to be an array containing the values in the parameter section. Or it can return false to indicate there are not updates.

The second and third parameters can be used to figure out which plugin WP is asking for update information.

There are very few examples of this filter being used, it’s very new and the documentation describes how to use it instead of demonstrating.

Here’s some untested pseudocode of what I think such a filter might look like:

add_filter( 'update_plugins_example.com', function( $update, array $plugin_data, string $plugin_file, $locales ) {
    // only check this plugin
    if ( $plugin_file !== 'myplugin.php' ) {
        return $update;
    }

    // already done update check elsewhere
    if ( ! empty( $update ) ) {
        return $update;
    }

    // CODE GOES HERE TO FIND UPDATE, maybe ask a server what
    // the latest version number is and call `version_compare`?
    $is_update_available = true;

    // no updates found
    if ( ! $is_update_available ) {
        return false;
    }

    // Update found?
    return [
        'slug' => 'myplugin',
        'version' => '9000',
        'url' => 'example.com/myplugin/',
        'package' => 'example.com/newversion.zip',
    ];
}, 10, 4 );

As for the actual checking of the update, that depends entirely on you, there is no canonical correct way to do that.

For example, you could toss a coin and return gibberish values. You could make a HTTP request to a file on a server to fetch the latest version number and compare it to the version installed. You could implement a license key check, or ping Githubs API for release versions, etc. It is entirely up to you.