Generally, if you are planing to release your plugin into a WordPress repo, you do not need to manually handle the update process. WordPress will handle this for you.
When your plugin will be approved, you will receive SVN access. When you will push new version there, all WordPresses will know that there is new version and they will handle update process. You do not need to do anything on your side to have this information covered.
If you want to store plugin files somewhere else (on your server for example) It is better to use this filter:
add_filter( 'site_transient_update_plugins', array( $this, 'check_for_new_version' ) );
/**
* Checks if there is new update, and prepare WordPress transient.
*
* @param stdClass $transient - array of available updates.
* @return array
*/
public function check_for_new_version( $transient ) {
if ( empty( $transient->checked ) ) {
return $transient;
}
$remote = $this->get_plugin_info();
if ( $remote && version_compare( $this->current_version, $remote->version, '<' ) && version_compare( $remote->requires, get_bloginfo( 'version' ), '<=' ) && version_compare( $remote->requires_php, PHP_VERSION, '<' ) ) {
$res = new \stdClass();
$res->slug = self::PLUGIN_SLUG;
$res->plugin = self::PLUGIN_NAME;
$res->new_version = $remote->version;
$res->tested = $remote->tested;
$res->package = $remote->download_url;
$transient->response[ $res->plugin ] = $res;
} elseif ( $remote ) {
$res = new \stdClass();
$res->slug = self::PLUGIN_SLUG;
$res->plugin = self::PLUGIN_NAME;
$res->new_version = $remote->version;
$res->tested = $remote->tested;
$res->package = $remote->download_url;
$transient->no_update[ $res->plugin ] = $res;
}
return $transient;
}
Where:
get_plugin_info() - function that will return basic information about your plugin current version (for example from external file)
self::PLUGIN_SLUG = 'test'
slef::PLUGIN_NAME = 'test/test.php'
$current_version = '1.0.0' - current version of the plugin
Also, to be sure you are displaying proper details about new plugin version on plugins page you can use this filter:
add_filter( 'plugins_api', array( $this, 'prefill_plugin_details' ), 20, 3 );
/**
* Function to prefill plugin details on Plugins page.
*
* @param stdClass $res - empty at this step.
* @param string $action - 'plugin_information'.
* @param stdClass $args - stdClass Object ( [slug] => test [is_ssl] => [fields] => Array ( [banners] => 1 [reviews] => 1 [downloaded] => [active_installs] => 1 ) [per_page] => 24 [locale] => en_US ).
* @return stdClass
*/
public function prefill_plugin_details( $res, $action, $args ) {
// do nothing if this is not about getting plugin information.
if ( 'plugin_information' !== $action ) {
return $res;
}
// do nothing if it is not our plugin.
if ( self::PLUGIN_SLUG !== $args->slug ) {
return $res;
}
$remote = $this->get_plugin_info();
$res = new \stdClass();
$res->name = $remote->name;
$res->slug = $remote->slug;
$res->author = $remote->author;
$res->author_profile = $remote->author_profile;
$res->version = $remote->version;
$res->tested = $remote->tested;
$res->requires = $remote->requires;
$res->requires_php = $remote->requires_php;
$res->download_link = $remote->download_url;
$res->trunk = $remote->download_url;
$res->last_updated = $remote->last_updated;
$res->sections = array(
'description' => $remote->sections->description,
'installation' => $remote->sections->installation,
'changelog' => $remote->sections->changelog,
);
// in case you want the screenshots tab, use the following HTML format for its content:
// <ol><li><a href="IMG_URL" target="_blank"><img src="IMG_URL" alt="CAPTION" /></a><p>CAPTION</p></li></ol>.
if ( ! empty( $remote->sections->screenshots ) ) {
$res->sections['screenshots'] = $remote->sections->screenshots;
}
$res->banners = array(
'low' => $remote->banners->low,
'high' => $remote->banners->high,
);
return $res;
}
It relays on the same get_plugin_info
function, that returns details about your newest version of the plugin.
Code above is from one of my old plugins I didn’t test it right now, but should work.
plugins_api filter docs:
https://developer.wordpress.org/reference/functions/plugins_api/
But in generall if possible, I would not use this methods, and relay on SVN you will receive.