Saturday, November 23, 2024
HomeEveryday WordPressArchitecting a WordPress plugin to support extensions

Architecting a WordPress plugin to support extensions


In the WordPress ecosystem, adopting a freemium model is a prevalent method for promoting and monetizing commercial plugins. This approach entails releasing a basic version of the plugin for free—usually through the WordPress plugin directory—and offering enhanced features through a PRO version or add-ons, typically sold on the plugin’s website.

There are three different ways to integrate commercial features within a freemium model:

  1. Ship these commercial features within the free plugin, and activate them only when the commercial version is installed on the website or a commercial license key is provided.
  2. Create the free and PRO versions as independent plugins, with the PRO version designed to replace the free version, ensuring that only one version is installed at any given time.
  3. Install the PRO version alongside the free plugin, extending its functionality. This requires both versions to be present.

However, the first approach is incompatible with the guidelines for plugins distributed via the WordPress plugin directory, as these rules prohibit the inclusion of features that are restricted or locked until a payment or upgrade is made.

This leaves us with the last two options, which offer advantages and disadvantages. The sections below explain why the latter strategy, “PRO on top of free,” is our best choice.

Let’s delve into the second option, “PRO as replacement of free,” its defects, and why it is ultimately not recommended.

Subsequently, we explore in depth the “PRO on top of free,” highlighting why it stands out as the preferred choice.

Advantages of the “PRO as replacement of free” strategy

The “PRO as replacement of free” strategy is relatively easy to implement because the developers can use a single codebase for both plugins (free and PRO) and create two outputs from it, with the free (or “standard”) version simply including a subset of the code, and the PRO version including all the code.

For example, the project’s codebase could be split into standard/ and pro/ directories. The plugin would always load the standard code, with the PRO code being loaded conditionally, based on the presence of the respective directory:

// Main plugin file: myplugin.php

// Always load the standard plugin's code
require_once __DIR__ . '/standard/load.php';

// Load the PRO plugin's code only if the folder exists
$proFolder = __DIR__ . '/pro';
if (file_exists($proFolder)) {
  require_once $proFolder . '/load.php';
}

Then, when generating the plugin via a Continuous Integration tool, we can create the two assets myplugin-standard.zip and myplugin-pro.zip from the same source code.

If hosting the project on GitHub and generating the assets via GitHub Actions, the following workflow does the job:

name: Generate the standard and PRO plugins
on:
  release:
    types: [published]

jobs:
  process:
    name: Generate plugins
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Install zip
        uses: montudor/[email protected]

      - name: Create the standard plugin .zip file (excluding all PRO code)
        run: zip -X -r myplugin-standard.zip . -x **/src/pro/*

      - name: Create the PRO plugin .zip file
        run: zip -X -r myplugin-pro.zip . -x myplugin-standard.zip

      - name: Upload both plugins to the release page
        uses: softprops/action-gh-release@v1
        with:
          files: |
            myplugin-standard.zip
            myplugin-pro.zip
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}





Source link

RELATED ARTICLES
Continue to the category

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Most Popular

Recent Comments