Custom Post Type UI Sync (CPTUIS) is an open source Wordpress plugin that allows replication of custom post types over different environments, replacing the usual behaviour of storing the custom post type registrations in the database by exporting them to the filesystem. This allows custom post types to be stored in source control and prevents the need to constantly sync databases between local, staging and production environments.

Usage Instructions

Download

You can download the plugin on Github or on the Wordpress plugin repository but not on the Wordpress plugin repository because they do not allow plugins that are dependent on other plugins.

Basic Usage

CPTUIS and the actual CPTUI plugin only need to be installed on your local/development environment, then on any other environments where CPTUI is not installed the files created by CPTUIS can just be included. By default this can be acheived by adding the following code to your theme functions.php file.

<?php

if(!function_exists('cptui_init')) {
    if(file_exists('cptui/post_types.php')) require 'cptui/post_types.php';
    if(file_exists('cptui/taxonomies.php')) require 'cptui/taxonomies.php';
}

How To…

Define custom path for saving custom post types

By default CPTUIS will export post type and taxonomy declarations into a cptui folder in your theme directory. This is easily customised by hooking into the cptuis.dir filter. The following code snippet will save the post types to your wp-content directory.

<?php

add_filter('cptuis.dir', 'wtc_customise_cptuis_dir');
function wtc_customise_cptuis_dir($path) {
    return WP_CONTENT_DIR;
}

Remember when changing the directory CPTUIS stores the files in, the paths to include them must be updated as well.