WordPress Plugin

Learn how to set up automatic updates for your private WordPress plugin.

With the AutomagicWP updater library, you can easily add automatic updates to your WordPress plugins. This guide will walk you through the process of integrating the updater into your plugin.

Prerequisites

  • PHP 7.4 or higher
  • WordPress 5.8 or higher
  • Access to your plugin's source code
  • Basic knowledge of PHP and WordPress plugin development
  • Composer (if installing via Composer)

Installation

To integrate the AutomagicWP updater into your plugin, you can either require it via Composer or manually copy the files.

Installing with Composer

Installing with Composer is the recommended way. It allows you to easily update the updater when a new version is released.

First, navigate to your plugin's root directory in the terminal and run:

	composer require wplatest/updater

After installing, require the Composer autoloader in your main plugin file and use the PluginUpdater class:

	<?php
/**
 * Plugin Name: Your Plugin
 * Version:     1.0.0
 * Description: Your plugin description
 * Update URI:  https://automagicwp.com
 *
 * @package ExamplePlugin
 */
 
require_once 'vendor/autoload.php';
 
use WPUpdateHubUpdaterPluginUpdater;
 
class ExamplePlugin
{
    public function __construct()
    {
        add_action('init', array($this, 'initialize'));
    }
 
    public function initialize()
    {
        $options = array(
            'file'   => __FILE__,
            'id'     => '<your-plugin-id>',
            'secret' => '<your-api-secret>',
        );
 
        new PluginUpdater($options);
    }
}
 
new ExamplePlugin();

Installing Manually

If you prefer to install the updater manually, download the PluginUpdater.php file:

	curl -O https://raw.githubusercontent.com/wplatest/updater/main/src/PluginUpdater.php

Place the file in your plugin directory and require it in your main plugin file:

	<?php
/**
 * Plugin Name: Your Plugin
 * Version:     1.0.0
 * Description: Your plugin description
 * Update URI:  https://automagicwp.com
 */
 
require_once 'PluginUpdater.php';
 
class ExamplePlugin
{
    public function __construct()
    {
        add_action('init', array($this, 'initialize'));
    }
 
    public function initialize()
    {
        $options = array(
            'file'   => __FILE__,
            'id'     => '<your-plugin-id>',
            'secret' => '<your-api-secret>',
        );
 
        new WPUpdateHubUpdaterPluginUpdater($options);
    }
}
 
new ExamplePlugin();

Ensure that you replace <your-plugin-id> and <your-api-secret> with your actual plugin ID and API secret.

Next Steps

Success! Your plugin is now set up to receive automatic updates every time you release a new version in the dashboard or via the API.

Want to automate your release process? Check out these resources:

Troubleshooting

Composer Issues

If you encounter issues with Composer, make sure it is installed correctly on your system and you are running the command in your plugin's root directory. You can install Composer from the official website.

Autoloader Problems

Ensure the path to the Composer autoloader in your require_once statement is correct. It should be require_once 'vendor/autoload.php'; if you are using Composer.

Plugin ID and API Secret

Double-check that your plugin ID and API secret are correct and match the values in the dashboard. These values are required for the updater to connect to the AutomagicWP API.

I don't see any updates

If you don't see any updates available, ensure that the version number in your plugin file is smaller than the latest version number in the dashboard. The updater compares these version numbers to determine if an update is available.

Be aware that updates are cached for a certain period, so you may need to wait up to ten minutes before the latest version is available.

Need help? Email support@automagicwp.com