Main Docs Page: AutoHosted Docs
Add Updater Class in your THEME.
Create a “includes” folder in your child theme, and add “child-theme-updater.php” from example child theme “Bowser Jr.”. Bowser Jr. is a child theme for example theme “Bowser”.
In this file, change all instance of Class name Auto_Hosted_Child_Theme_Updater
with your theme prefix, for example My_Awesome_Child_Theme_Updater
. There is two instance of this class name, one is in the actual class, and the second is when the class is used (in the bottom) of functions.php file.
new Bowser_Jr_Child_Theme_Updater;
You can also change all ‘text-domain
‘ string with your plugin text domain if your child theme support language translation.
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 Jr. theme example. Let’s create it for dummy theme: “awesome-child-theme”
/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'awesome_child_theme_setup', 11 );
/**
* Theme setup function.
*/
function awesome_child_theme_setup(){
/* updater args */
$updater_args = array(
'repo_uri' => 'http://yoursite.com/',
'repo_slug' => 'awesome-child-theme',
'key' => '',
'dashboard' => false,
'username' => false,
);
/* add support for updater */
add_theme_support( 'auto-hosted-child-theme-updater', $updater_args );
}
/* Load Child Theme Updater */
require_once( trailingslashit( get_stylesheet_directory() ) . 'includes/child-theme-updater.php' );
new My_Awesome_Child_Theme_Updater;
First you need to load the updater file using require_once
.
Load CHILD THEME Updater
This is where we load the “child-theme-updater.php” file using require_once
.
Updater ARGS THEME SUPPORT
/* updater args */
$updater_args = array(
'repo_uri' => 'http://yoursite.com/',
'repo_slug' => 'awesome-child-theme',
'key' => '',
'dashboard' => true,
'username' => false,
);
/* add support for updater */
add_theme_support( 'auto-hosted-child-theme-updater', $updater_args );
Updater arguments is an array with, this array is the configuration of your child theme updater and activate the updater using theme suport ‘auto-hosted-child-theme-updater
‘.
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 child 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 child 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_child_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. 🙂