Coder Social home page Coder Social logo

lemonsqueezy-wp-updater-example's Introduction

Lemon Squeezy WordPress Updater Example

This repository contains an example WordPress plugin that demonstrates how to implement automatic updates for premium WordPress plugins using the Lemon Squeezy WordPress plugin and the Lemon Squeezy Licenses API.

Usage

1. Set up your WordPress site

  1. Install the Lemon Squeezy WordPress plugin on your WordPress site and connect it to Lemon Squeezy.
  2. Make sure external requests to the WordPress REST API (http://example.com/wp-json) aren't disabled or blocked by a firewall.

2. Set up the updater class

  1. Copy the includes/class-plugin-updater.php file into your plugin.
  2. Rename the ExamplePluginUpdater class so that it's unique to your plugin (e.g. MyPluginUpdater)
  3. Override the get_license_key() method to retrieve the users Lemon Squeezy license key. Normally, your plugin would have a settings page where you ask for and store a license key.

3. Instanciate the updater class

  1. In your plugin code, store the plugin version (e.g. in a define( 'EXAMPLE_PLUGIN_VERSION', '1.0.0' )).
  2. In your plugin code, store the API URL for the updater. This should point to your WordPress site that is running the Lemon Squeezy WordPress plugin (e.g. define( 'EXAMPLE_PLUGIN_API_URL', 'http://example.com/wp-json/lsq/v1' ))
  3. Instanciate your updater class, passing in the plugin ID and plugin slug as well as the plugin version and API URL.

See example-plugin.php for an example of how to set this up.

How it works

  1. This plugin code overrides WordPress default updater process to request update information from your WordPress site running the Lemon Squeezy WordPress plugin instead of WordPress.org.
  2. The Lemon Squeezy WordPress plugin then uses the Lemon Squeezy API to validate the license key and fetch the required file information.
  3. Finally, the Lemon Squeezy WordPress plugin returns the information required for this plugin to determine if it needs an update or not. If an update is required, the download URL returned by the Lemon Squeezy API will be used to provide the update.
┌─────────────────────────┐                  ┌───────────────────────────────────┐                   ┌─────────────────────┐
│                         │                  │                                   │                   │                     │
│  Your WordPress Plugin  │                  │  Lemon Squeezy WordPress Updater  │                   │  Lemon Squeezy API  │
│                         │                  │                                   │                   │                     │
└───────────┬─────────────┘                  └─────────────────┬─────────────────┘                   └──────────┬──────────┘
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │            Request udpate information            │                                                │
            ├─────────────────────────────────────────────────►│                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │           Request file information             │
            │                                                  ├───────────────────────────────────────────────►│
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │             Validate license key               │
            │                                                  │                      +                         │
            │                                                  │            Return file information             │
            │                                                  │◄───────────────────────────────────────────────┤
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │           Return update information              │                                                │
            │◄─────────────────────────────────────────────────┤                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │
            │                                                  │                                                │

lemonsqueezy-wp-updater-example's People

Contributors

gilbitron avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.