Skip to content

DEV: Partially Licensed

Ale Mostajo edited this page Oct 4, 2020 · 4 revisions

TAG: FOR DEVELOPER

A partially licensed product will allow you to determine which parts of your software will be restricted by a license key.

Code Setup

Change the following use statement at the beginning of your Main Class:

use WPMVC\Bridge;

Replace it with these lines:

use WPMVC\Addons\LicenseKey\Traits\LicenseTrait;
use WPMVC\Addons\LicenseKey\Core\LicensedBridge as Bridge;

Then add the following line inside the main class:

class Main extends Bridge
{
    use LicenseTrait;

    /********
    YOUR CODE HERE
    ********/
}

Restricting access

Use main class' property is_valid to add restrictions in your code.

Sample within the main class:

class Main extends Bridge
{
    public function init()
    {
        // Restricted hooks
        if ( $this->is_valid ) {
            $this->add_action('init', 'SampleController@init');
        }
        // Public hooks
        $this->add_action('init', 'SampleController@init2');
    }
}

Sample within a controller:

class SampleController extends Controller
{
    /**
     * @global Bridge $myproject Main class global variable.
     */
    public function example()
    {
        if ( get_bridge( 'MyNamespace' )->is_valid ) {
            // Access restricted code
        }
    }
}
Clone this wiki locally