WordPress Update Plugin Hook/Action? Since 3.9

I’ve researched this a few times, yet my searching does not reveal much except custom code which may or may not be good WordPress practice.

As of the latest releases (WordPress 3.9 “Smith”), has a hook been added to the plugin update process? I’m asking because its a very basic need, yet I do not see it added to the codex (yet). If not, what is the common and best practice developers employ?

EDIT: Just to clarify, I’m not talking about activation, but about updating, that way, if there are changes in database or otherwise it can be addressed.

4

I don’t think an action has been added. You can look at version details for any version and see any new actions added.

The WordPress Way to run code on plugin update is what is described here:

The proper way to handle an upgrade path is to only run an upgrade procedure when you need to. Ideally, you would store a “version” in your plugin’s database option, and then a version in the code. If they do not match, you would fire your upgrade procedure, and then set the database option to equal the version in the code. This is how many plugins handle upgrades, and this is how core works as well.

and with code example here:

function myplugin_update_db_check() {
    global $jal_db_version;
    if (get_site_option( 'jal_db_version' ) != $jal_db_version) {
        jal_install();
    }
}
add_action( 'plugins_loaded', 'myplugin_update_db_check' );

Leave a Comment