Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
1.3 Convert a standalone install to the WordPress plugin
Converting from the standalone GlotPress to the WordPress Plugin
Much of the code is shared between the standalone and plugin versions of GlotPress, however there are some differences that make converting between them a manual process.
The basic steps are:
- MAKE A BACKUP
- Read this entire document at least once
- Install WordPress 4.4 or newer
- Install the plugin, don't activate it
- Update table names (see "Table Names" below for more detail)
- Convert your user table if required (see "User Table and Permissions" below for more detail)
- Optionally set your base path (see "GlotPress Base Path" below for more detail)
- Activate the plugin
Some important items include:
- Table Names
- Unused Tables
- User Table and Permissions
- Breaking Changes
- Configuration Directives
- GlotPress Base Path
Each of the above will be addressed in the following sections.
The standalone code uses "gp_" as a prefix for table names in GlotPress. To work better with WordPress and support multi-site, the plugin adopts the WordPress prefix in addition to the "gp_" format.
This means a table from the standalone code, like originals, will be named "gp_originals" but in the plugin will be named "wp_gp_originals" (assuming you haven't changed the WordPress prefix of course).
You have two options to move your standalone code to the plugin:
- Rename your tables and add the WordPress prefix on them.
- Change the $gp_table_prefix by adding it to the wp-config.php file.
The safest (aka most future proof) way is option 1.
However you can add the following lines to your wp-config.php file (near the end, before the
/* That's all, stop editing! Happy blogging. */ line of course):
GLOBAL $gp_table_prefix; $gp_table_prefix = 'gp_';
Note you can set the value to anything you like.
WARNING Do not edit the gp-settings.php file and change this value or it will be overwritten each time you upgrade the plugin.
There are a few tables in the standalone version that are no longer used in the plugin, these are (using the default gp_ prefix):
User Table and Permissions
The standalone user table has been replaced by the WordPress user table. If you were using the standalone user table this will be the hardest part of migrating to the plugin.
If you have already been using the WordPress user table, then you don't need to do anything.
You already have users in WordPress
If you already have users in WordPress, you'll going to have to make a choice of either matching the user id's of WordPress with your old GlotPress table or starting from scratch and re-applying your user permissions.
Either way the first step is to generate a report of your current permissions to work from, you can use the following SQL statement to do so:
SELECT * FROM gp_permissions INNER JOIN gp_users ON gp_permissions.user_id=gp_users.id;
If your feeling adventurous you could use the same basic process to join the above on your WordPress users table as well using a unique key from the gp_users table and then generate a file you could import back in to the permissions table.
Your WordPress users table is empty
This is slightly easier, you can basically export the gp_users table and re-import it the WordPress users table. You do need to be careful you don't re-import your admin user.
The plugin has several low level API changes to use WordPress instead of BackPress, if you have any custom code (like plugins of theme changes) you may need to update them.
You can find a complete list of breaking changes on the GlotPress Wiki.
Many of these changes are very low level so be careful to understand what they mean.
One of the biggest breaking changes from above, is the removal/rewrite of the old GlotPress plugin system. Plugins are now just WordPress plugins that can be submitted to the WordPress plugin directory like any other plugin.
You can find a quick guide on how to convert any of your existing GlotPress plugins to the new format on the GlotPress Wiki.
Many of the configuration directives from the standalone code still work in the plugin, however the gp-config.php file no longer exists. Instead you should add any configuration directives to your wp-config.php file so that during upgrades to GlotPress they are not lost.
GlotPress Base Path
The standalone code lived in the root of whatever directory you installed it in, the plugin lives in the "glotpress" virtual path under your WordPress install.
If you wish to have GlotPress take over your entire WordPress site, effectively emulating the old behaviour, you can set the "GP_URL_BASE" configuration directive to your wp-config.php file.
Make sure when you install WordPress to set the permalink structure to something pretty, the default is not supported in the plugin as we require the rewrite rules to be active.
If you have created your own templates to use with the standalone version you can still use these in the plugin, they have not changed.
Simply add a configuration directive to your wp-config.php file like:
define( 'GP_TMPL_PATH', '/var/www/example.org/gp-templates' );