Main Docs Page: AutoHosted Docs

Add Updater Class in your THEME.

Create a “includes” folder in your theme, and add “theme-updater.php” from example theme “Bowser”.

In this file, change all instance of Class name Bowser_Theme_Updater with your theme prefix, for example My_Awesome_Theme_Updater. There is two instance of this class name, one is in the actual class in the file, and the second is when the class is used (in the bottom) of functions.php file.

new Bowser_Theme_Updater;

You can also change all ‘text-domain‘ string with your plugin text domain if your theme support language

Include and activate

Now, you need to include and use the updater class from your theme functions.php file. You can see how to use it in Bowser theme example. Let’s create it for dummy theme: “awesome-theme

/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'awesome_theme_setup' );

/**
 * Theme setup function.
 */
function awesome_theme_setup(){

    /* updater args */
    $updater_args = array(
        'repo_uri'  => 'http://yoursite.com/',
        'repo_slug' => 'awesome-theme',
        'key'       => '',
        'dashboard' => false,
        'username'  => false,
    );

    /* add support for updater */
    add_theme_support( 'auto-hosted-theme-updater', $updater_args );
}

/* Load Theme Updater */
require_once( trailingslashit( get_template_directory() ) . 'includes/theme-updater.php' );
new My_Awesome_Theme_Updater;

First you need to load the updater file using require_once.

Load THEME Updater

This is where we load the “theme-updater.php” file using require_once.

Updater ARGS THEME SUPPORT

    /* updater args */
    $updater_args = array(
        'repo_uri'    => 'http://yoursite.com/',
        'repo_slug'   => 'awesome-theme',
        'key'         => '',
        'dashboard'   => false,
        'username'    => false,
    );

    /* add support for updater */
    add_theme_support( 'auto-hosted-theme-updater', $updater_args );

Updater arguments is an array with, this array is the configuration of your theme updater and activate the updater using theme support ‘auto-hosted-theme-updater‘. You can read more in Theme Updater Config Cheat Sheet Documentation.

dashboard

If this set to true, the updater class will register a dashboard meta box where your user can input activation key. If you don’t use update restriction by activation key feature in your theme you can set it to false, or remove the line.

The input is saved in database with option name aht_theme-folder_activation_key. The theme-folder part is your theme folder.

if you create your own activation key input, for example in your theme settings/options page, you also do not need this.

key

You only need this if you create your own activation key input, it’s not needed if you set dashboard to true and you only need this if you choose to use update restriction by activation key.

Example usage if you use your own input:

    /* updater args */
    $updater_args = array(
        'repo_uri'   => 'http://yoursite.com/',
        'repo_slug'  => 'awesome-theme',
        'key'        => get_option( 'your_theme_db' ),
    );

If you use this, i assume you already familiar with creating theme settings page, using the database saved in your settings page, and how to use get_option function.

username

Set this to true if you want to restrict update by members (role). If set to true and dashboard also set to true, there will be two input in dashboard meta box. Username and Email. Members of your site with role selected can activate automatic update feature after they input their username and email.

If you want to use your own settings and not using dashboard meta box, you can add the data in this key too.

    $updater_args = array(
        'key'       => get_option( 'your_theme_db_for_email' ),
        'username   => get_option( 'your_theme_db_for_username' ),
        'repo_uri'  => 'http://yoursite.com/',
        'repo_slug' => 'awesome-theme',
    );

repo_uri

This is the home url of the site where you install Auto Hosted plugin. you can get it from Updater data meta box repo_uri.

repo_slug

This is unique for each theme, this is your theme entry slug in your repository.

And that’s it. 🙂