News & Info

CSA Daily Updates and Tech Chatter

WordPress Activation Hook

WordPress Development

We recently discovered an issue in our commercial plugins related to a change in the WordPress API. It turns out that since WordPress 3.1 was released the register_activation_hook() function is no longer called during a plugin upgrade! This is a significant change in behavior from previous versions that called the WordPress activation hook on every update.   This has caused numerous problems and forced Cyber Sprocket to come up with a patch in our own wpCSL framework.

Why Is This A Problem?

Any site running a version of WordPress older than 3.1 would automatically get any feature  and supporting application tweaks whenever they upgraded the plugin.   Most plugin authors, Cyber Sprocket included, would use the register_activation_hook API call to make sure the user had the latest database structure, settings, and other elements that keep the plugin working.    For example, with Store Locator Plus 3.0 this hook would ensure that the user’s Google Maps API v2.0 settings were converted to the Google Maps API v3.0 equivalent.

As of WordPress 3.1 the function that does this conversion is not called.    To make matters worse, it is not called only in certain circumstances.  For example:

  • User installs upgrade via a downloaded zip file: updates called.
  • User does auto-update on a deactivated plugin then activates the plugin: updates called.
  • User does auto-update on an activated plugin: updates NOT called.

As you can see this is inconsistent.  Even worse, plugins that worked find up to version 3.1 now have the potential to suddenly break.

The Solution?

Cyber Sprocket has created a new version of our wpCSL framework that we use to build WordPress plugins.   The update uses standard admin panel interfaces to call our own “plugin has changed” hooks.    The short version of how this works is as follows:

  • User is on the admin panel…
  • The plugin is active…
  • Check the version of the plugin as stored in the options table of WordPress…
  • Is it different than the current version of our plugin?
    • Yes, run the upgrade callback function if it is set.
    • Update the plugin version stored in the options table to the current installed version.

That’s it.  A fairly simple solution, but more things we need to manage in our plugin framework because the WordPress development team changed things.

 

Tags: , ,

About Lance Cleveland

I started my high-tech career in the early 80's as a computer technician. I became a lead engineer at a Boston area database company a few years later. When the Internet was just starting to show up on people's radar I quit my corner-office job and founded ProActive Web Marketing, my first start up company. That was the genesis of several successful start up companies including Time Magazine award winner The Lobster Net. After brief retirement in my mid-30s I co-founded the software consulting firm, Cyber Sprocket Labs. In addition to being "man of all hats" at Charleston Software Associates, I currently serve on the board or as technical adviser for several companies including Musiplicity, Model Locate, and Advanced Media Ltd. In the past I consulted for Data General, Kimberly Clark, Kraft, Philip Morris, Rich Foods, Telefonica, Aribtron, and a half-dozen other Fortune 500 companies. I've appeared as a keynote speaker for the USVI Economic Development Summit, showed up as a lead interviewee for Microsoft infomercials, and have been a cited performance advertising, Internet retail, and cybercrime expert in The Wall Street Journal and New York Times. I currently spend most of my time hanging with friends & family while hacking WordPress plugins. ### Code geek. Dad. Husband. Rum Lover. Not necessarily in that order.

Socialize

Enter your email below to sign up for the monthly Store Locator Plus newsletter. Click the Facebook icon to get almost-daily updates on what I'm working on now. The RSS feed icon will bring my bi-weekly blog posts to your feed reader.

Trackbacks/Pingbacks

  1. Launch of LiveJam.com, Offers of Free WordPress Training and of Integration … | Open Knowledge - June 11, 2012

    [...] We recently discovered an issue in our commercial plugins related to a change in the WordPress API. It turns out that since WordPress 3.1 was released the register_activation_hook() function is no longer called during a plugin upgrade!More By lcleveland [...]