PHP code example of license-bridge / wordpress-sdk

1. Go to this page and download the library: Download license-bridge/wordpress-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

license-bridge / wordpress-sdk example snippets


if (!function_exists('my_license')) {
    function my_license()
    {
        global $my_license;

        if ($my_license) {
            return $my_license;
        }

        if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
            return null;
        }

        => 'my-first-product',
        ]);

        return $my_license;
    }

    my_license();
}

$my_license = \LicenseBridge\WordPressSDK\Boot\Loader::register(__FILE__, [
    'plugin-slug'            => plugin_basename(__FILE__),
    'license-product-slug'   => 'my-first-product',
    'license-bridge-url'     => 'http://market.lb.test',
    'license-bridge-api-url' => 'https://your-tunnel.ngrok-free.app',
]);

$bridge = my_license();
$slug   = plugin_basename(__FILE__);

$link = $bridge->purchase_link($slug);
// https://licensebridge.com/market/my-first-product?callback_url=...

echo '<a href="' . esc_url($link) . '">Buy Premium</a>';

echo my_license()->checkout_button($slug, [
    'plugin-file' => __FILE__,
    'gateway'     => 'paddle', // or stripe
    'plan-slug'   => 'pro',
    'plan-type'   => 'annual',
    'label'       => 'Upgrade to Pro',
]);

echo my_license()->checkout_button($slug, [
    'plugin-file'          => __FILE__,
    'gateway'              => 'stripe',
    'allow-plan-selection' => true,
]);

if ($bridge->license_exists($slug)) {
    // Credentials stored locally
}

if ($bridge->is_license_active($slug)) {
    // Active license on License Bridge
}

$details = $bridge->license($slug); // array|false

if ($bridge->cancel_license($slug)) {
    // Cancelled on License Bridge
}

add_action('admin_notices', function () {
    if (isset($_GET['license_upgraded'])) {
        echo '<div class="notice notice-success"><p>Premium activated.</p></div>';
    }
});

// Before/after upgrade (callback handler)
apply_filters('before_upgrade_plugin_' . $plugin_slug, '');
apply_filters('after_upgrade_plugin_' . $plugin_slug, '');