Giter VIP home page Giter VIP logo

wordpress-sdk's Introduction

SureCart Theme and Plugin Licensing SDK

Installation

Clone the repository in your project.

cd /path/to/your/project/folder
git clone https://github.com/surecart/wordpress-sdk.git licensing

Or, you can download the repository zip file, and place it in the licensing folder of your plugin or theme.

Now include the dependencies in your plugin/theme.

if ( ! class_exists( 'SureCart\Licensing\Client' ) ) {
    require_once __DIR__ . '/licensing/src/Client.php';
}

Include a release.json

Add a release.json file to the root of your plugin or theme project. release.json requires the following:

Property Description
name Your plugin or theme display name.
slug Your plugin or theme slug. IMPORTANT This must match the folder name of your project.
author HTML to be used for the author of the plugin.
author_profile A url to your author profile.
version The version of your plugin or theme.
requires The required WordPress version.
tested The version of WordPress the plugin has been tested with.
requires_php The required php version.
sections An array of sections to tab through in the update UI.

Sections will require a changelog property with an html string of your changelog.

release.json example

{
  "name": "SureCart Example Plugin",
  "slug": "surecart-plugin-example",
  "author": "<a href='https://surecart.com'>SureCart</a>",
  "author_profile": "https://surecart.com",
  "version": "0.9.0",
  "requires": "5.6",
  "tested": "6.1.0",
  "requires_php": "5.3",
  "sections": {
    "description": "This is my plugin description.",
    "changelog": "<h4>1.0 –  July 20, 2022</h4><ul><li>Bug fixes.</li><li>Initital release.</li></ul>",
    "frequently asked questions": "<h4>Question<h4><p>Answer</p>"
  }
}

⚠️ Important

In order for updates to work, the slug in release.json must match the folder name of your plugin or theme. So if for example your plugin folder name is ralphs-biscuits, the slug in release.json must also be ralphs-biscuits.

Usage Example

Please refer to the installation step before start using the class.

if ( ! class_exists( 'SureCart\Licensing\Client' ) ) {
    require_once __DIR__ . '/licensing/src/Client.php';
}

// initialize client with your plugin name and your public token.
$client = new \SureCart\Licensing\Client( 'Your Plugin', 'pt_jzieNYQdE5LMAxksscgU6H4', __FILE__ );

// set your textdomain.
$client->set_textdomain( 'your-textdomain' );

// add the pre-built license settings page.
$client->settings()->add_page( 
    [
	'type'                 => 'submenu', // Can be: menu, options, submenu.
	'parent_slug'          => 'your-plugin-menu-slug', // add your plugin menu slug.
	'page_title'           => 'Manage License',
	'menu_title'           => 'Manage License',
	'capability'           => 'manage_options',
	'menu_slug'            => $client->slug . '-manage-license',
	'icon_url'             => '',
	'position'             => null,
	'parent_slug'          => '',
	'activated_redirect'   => admin_url( 'admin.php?page=my-plugin-page' ), // should you want to redirect on activation of license.
	'deactivated_redirect' => admin_url( 'admin.php?page=my-plugin-deactivation-page' ), // should you want to redirect on detactivation of license.
    ] 
);

Make sure you call this function directly, never use any action hook to call this function.

For plugins example code that needs to be used on your main plugin file. For themes example code that needs to be used on your themes functions.php file.

More Usage

$client = new \SureCart\Licensing\Client( 'Twenty Twelve', 'pt_jzieNYQdE5LMAxksscgU6H4', __FILE__ );

Set textdomain

You may set your own textdomain to translate text.

$client->set_textdomain( 'your-project-textdomain' );

wordpress-sdk's People

Contributors

ajgagnon avatar sandeshjangam avatar adi3890 avatar aryadhiratara avatar gijo-varghese avatar

Stargazers

Paul Ryley avatar Martin Valchev avatar  avatar Mike Gillihan avatar Rodrigo Espinoza avatar Ryan Munil Lee avatar Donald Nguyen avatar David Carton avatar Oleg avatar

Watchers

 avatar  avatar Maniruzzaman Akash avatar

wordpress-sdk's Issues

Updater issue

Hey there,

Im testing Surecart licensing add-on in a blank plugin.

I followed the steps of your readme and when activating my testing plugin I can´t see a "Check for updates" option at the plugin. I don´t even know if this feature is included in the licensing add-on as there is very few information but I guess it is as there is an Updater class handling the logic. An add-on like this should be much more documented.

Wanted to ask you what extra code is required or conditions to get it functional. If no additional code is required then I have to be facing a bug/error.

Thanks.

Undefined property: stdClass::$plugin

This warning occasionally appear and reported by our customer.

After investigating, the Undefined property: stdClass::$plugin warning came from the transient data generated by SureCart's check_plugin_update() method in Updater.php. It did not consistently include the plugin property, which caused the warning when WordPress ran the version check.

We can fix this by ensuring the plugin property is always set before it's used.

// Ensure the 'plugin' property is set
if ( ! isset( $version_info->plugin ) ) {
    $version_info->plugin = $this->client->basename;
}

Steps to reproduce the issue:

  1. Make sure the installed version is not the latest version
  2. Clear the transient
  3. Force the update check by going to /wp-admin/update-core.php?force-check=1, or click Check again in /wp-admin/update-core.php
  4. Visit /wp-admin/plugin-install.php. The Undefined property: stdClass::$plugin warning should appear

Steps to test the fix:

  1. Modify the check_plugin_update() to:
public function check_plugin_update($transient_data) {
    global $pagenow;

    if (!is_object($transient_data)) {
        $transient_data = new \stdClass();
    }

    if ('plugins.php' === $pagenow && is_multisite()) {
        return $transient_data;
    }

    if (!empty($transient_data->response) && !empty($transient_data->response[$this->client->basename])) {
        return $transient_data;
    }

    $version_info = $this->get_version_info();

    if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) {
        unset($version_info->sections);

        // Ensure the 'plugin' property is set
        if (!isset($version_info->plugin)) {
            $version_info->plugin = $this->client->basename;
        }

        // If new version available then set to `response`.
        if (version_compare($this->client->project_version, $version_info->new_version, '<')) {
            $transient_data->response[$this->client->basename] = $version_info;
        } else {
            // If new version is not available then set to `no_update`.
            $transient_data->no_update[$this->client->basename] = $version_info;
        }

        $transient_data->last_checked = time();
        $transient_data->checked[$this->client->basename] = $this->client->project_version;
    }

    return $transient_data;
}
  1. Clear the transient
  2. Re-visit the /wp-admin/plugin-install.php. The Undefined property: stdClass::$plugin warning should no longer appear. (It's also a good idea to test by forcing the update check /wp-admin/update-core.php?force-check=1 to make sure the warning does not reappear)

Warning at "Add new plugin"

Hey there,

I´m getting this warning when using your licensing system at "Add New Plugin" option:

Warning: Undefined property: stdClass::$plugin in /home/clients/f108e2079c2f39aa6629cc3c197b2ecc/sites/mysite/wp-includes/class-wp-list-util.php on line 168

Any clue about this?

Thanks

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.