uaktags/wordpress-RPG — pull request #2 by JDGrimes (2014-07-01 20:45:57+00:00)
Title: Avoid an error when installing

When the latest version of the plugin is first activated, it will give
an error:

```
[01-Jul-2014 20:08:06 UTC] WordPress database error Table
'wp_dev_1.wptrunk_rpg_usermeta' doesn't exist for query select * from
wptrunk_rpg_usermeta made by activate_plugin,
include_once('/plugins/wprpg/wordpress-rpg.php'), transition_db
```

This is because the database transition function is called, and it
attempts to transition the database, even though the old database
doesn’t exist (because this is a fresh install, not an update from an
old version).

I’ve made the following changes:

- Renamed `transition_db()` to `wpRPG_transition_db()`, to avoid
possible conflicts if another plugin has a function with the same name.
- Added a check to the transition function to see if the old database
exists, and only attempting the transition if it does.

Note that this code is all untested, I’ll leave that to you. :)

Also, I don’t think this is actually the _best_ solution. Ideally, it
could be changed in the following ways:

- The option stored in the database wouldn’t be a 0/1 on/off value.
Instead you could store an option that would hold the database version.
That way if you make more changes in the future, you won’t have to add
a new option each time. Instead, you could check a single option
storing the current DB version, and run the updates needed for newer
versions.
- The database version option would be added with an initial value
(maybe the version of the plugin) when it is activated.
- The transition/update would need to run later in code execution,
hooked to an action like `’admin_init’`. That would be needed so that
the activation code could set the initial database version before the
transition is attempted. Otherwise you’d get an empty database version
from the option in the transition function.