YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.22k stars 403 forks source link

how I find out when The download and replacement process is complete ? #444

Open Alireza-Ghavabesh opened 3 years ago

Alireza-Ghavabesh commented 3 years ago

i want to do something like this:

if (check_lisense() == true) { $result = $myUpdateChecker->checkForUpdates(); //=====> only once if($result == true){ $prosess_is_compelet = $myUpdateChecker->download_replace(); if($prosess_is_compelet == true){ do_important_work(); } } }

i want to more control on process can you guide me how i can implement code above according to this library.

Thanks again for all the guidance and time you spend.

YahnisElsts commented 3 years ago

checkForUpdates returns an update object or null, so if you want to check if an update is available, I would recommend a slight modification:

$result = $myUpdateChecker->checkForUpdates();
if ( $result !== null ) {
    // An update is available.
}

However, this library doesn't have a download_replace() function or anything similar. This is because it doesn't actually download or install updates. It just retrieves updates and then gives them to WordPress. Update notifications and installation are handled by WordPress core.

There probably is a way to force WordPress to install an update, but I don't know it off the top of my head. You might need to take a look at WordPress core source code, or maybe see how other tools like WP-CLI install plugin updates.