How to use “NPUSWC Client” – Dev

This page about how to use “NPUSWC Client”, which is client library of plugin “Package Update Server for WooCommerce”.

Currently this is compatible with WordPress Themes and Plugins to be implemented, but for other environment, is not prepared yet.

Just include and initialize it, you enable a package to check for updates, then you can update it in admin page.


Features of “NPUSWC Client”

What can “NPUSWC Client” do?

In current version, it has 3 parts of the features in it. Please regard.

Append admin page under dashboard

The page is to save the token customers get when they make purchase of downloadable product with settings of plugin “Package Update Server for WooCommerce”.

Customers can get token in “Download Tokens” tab in My Account page.


Get the latest version updates

It will fetch the latest version of the package data to check for updates to the shop with your purchased token.

Then, if the shop update the product version, you will know in admin page while your token is valid.


Update the package in admin page like others

It’s like other Themes and Plugins distributed from WordPress Repositories, you can check it in “Dashboard” -> “Updates”.

While your token is valid, you can update the package in admin page like others.


How to use in package for WordPress Themes and Plugins

Extract the zip file in directory you want locate in theme or plugin.

You will see a folder “npuswc-client”.

Write some codes in package in way following.

  1. Include the main class file “class-npuswc-client-loader.php”
  2. Call the static method “load” of class “NPUSWC_Client_Loader”


 * Package Update Server Client
 * @param string $file
 * @param string $textdomain
 * @param string $plugin_dir_name
 * @param string $api_url_base
if ( ! class_exists( 'NPUSWC_Client_Loader' ) ) {
  require_once( 'path/to/npuswc-client/class-npuswc-client-loader.php' );
$npuswc_client = NPUSWC_Client_Loader::load(
  MAIN_FILE, // like "path/to/functions.php" of the theme or "path/to/plugin-file.php" of the plugin
  TEXTDOMAIN, // Textdomain of your theme or of your plugin
  PACKAGE_DIR_NAME, // Folder name of the package
  WC_SITE_URL // URL of WooCommerce site which installed this

As params for the method “load”,

  1. Absolute path of “functions.php” for theme, the main plugin file for plugin
  2. Textdomain
  3. Folder Name of the package
  4. URL of the WooCommerce site

All 4 of them are required.

Only with this code, admin page is automatically appended, you can save the token.


About making update checker plugin

It’s kind a optional use but I recommend to make a plugin only for update checker.

The reason why is, If the package is read with error or cause some trouble and need to be fixed by updating, you maybe have to deactivate the plugin which has update checker.

In order to avoid this, you can separate the update checker from the package you want check for updates with “NPUSWC Client”.