The plugin should be placed in /wp-content/plugins/jumpstarter
.
This plugin has some expectations that must be fulfilled:
- SQLite must be used as a database with the sqlite-integration plugin.
- The
js-init.php
script must be run successfully (return exit code 0) before the HTTP port is opened and the WordPress site can accept requests. DB_DIR
must be set to"/app/code/wp-db"
inwp-config.php
.- The
/wp-content/database
folder must not exist as it's a security hazard.
When the js-init.php
is run it does the following:
- Install WordPress if
/app/code/wp-db
does not exist. - Sync the
/app/env.json
and/app/code/wp-env.json
environments with WordPress.
Install is done the following way:
- Clean up previous failed or aborted installations.
- Install WordPress to RAM (in
/tmp
) to get rid of waiting for disk sync. This allows installing in a second or less. - Activating core plugins (
jumpstarter
andsqlite-integration
). - Setting the theme specified in
wp-env.json
. - Run WordPress install hooks registered with
add_action("jumpstarter_install",...)
. - Atomically move the database in place. This allows the install to be idempotent.
- Restart by execve'ing itself so environment sync can run.
Environment sync is done the following way:
- Opening and parsing
/app/code/wp-env.json
. - If the siteurl has changed it performs a safe search/replace of $siteurl in
wp_posts
,wp_postmeta
andwp_options
. - Set theme specified in
theme
. - Update options specified in
options
. - Opening and parsing
/app/env.json
. - Update user details if they are admin default.
- Call the hook
jumpstarter_sync_env
to let themes/plugins modify db state depending on the env.
It also prints logging and error information to stderr
.
Install hooks:
If you need to do modifications to WordPress during the install phase you can take advantage of the install hook functionality provided by js-init. The registered hooks are executed at step 6 in the install process and as such they are run an the context of an initialized WordPress instance.
To register an install hook add the following to your theme or plugin:
add_action("jumpstarter_install", function() {
// Do your installation modifications here.
});
Alternative install:
If your WordPress app requires the database to be filled with example content it might be a good idea to speed up the process by running through the install before users starts their instances. These are the steps needed to do this kind of install:
- Do a normal install by issuing
php /app/code/src/wp-content/plugins/jumpstarter/js-init.php
. - Make the db/content modifications needed (this could be done with the install hooks).
- Create the directory
/app/code/js-init-state
.
When the user starts a new instance of the app the init script will use the files inside /app/code/js-init-state
and then update the WordPress database with the users information.
When the plugin itself is run by WordPress after installing it does the following:
- Sandboxes all users (even super admins) and overrides any user capabilities defined in
wp-env.json
. - Injects a login link to support Jumpstarter reflected login on
/wp-login.php
. - Handles login requests from Jumpstarter by authenticating posts of
jumpstarter-auth-token
. On successful authentication the user is logged in as the admin user. - Hooks in on set_url_scheme and uses the env to determine if the url should use http or https.
- Disables the possibility to delete the theme that's specified in the wp env.
- Rewrites urls passed to
wp_enqueue_script
andwp_enqueue_style
.
WordPress settings that you want the Jumpstarter plugin to automatically sync with the install should be defined in /app/code/wp-env.json
. The env file has the following format. If a field is omitted it will be ignored.
{
"theme": "",
"disabled_capabilities": [],
"options": {}
}
Field explanation:
theme
- A string containing the name of the folder containing the theme in wp-content/themes/disabled_capabilities
- A list of WordPress capabilities. (["edit_posts", "edit_pages"]).options
- An object of Key -> Val.