Easy Digital Downloads の ソフトウェアライセンス 拡張機能を使用すると、テーマの自動アップグレードを設定できます。これは、お客様のテーマが自動的に更新されるという意味ではありません。むしろ、お客様は、テーマが WordPress.org でホストされているかのように、従来の WordPress アップデートツールを使用してテーマを更新できます。
サンプルには2つの主要なコンポーネントがあります。
- WordPress プラグインでソフトウェアライセンス API の使用を開始するために必要なすべてを設定する
composer.jsonファイル。 functions.phpファイル。これは、EDD ソフトウェアライセンス SDK にフックするためのコードを含みます。これは、WordPress プラグインおよびテーマ開発者が、複雑なセットアップやカスタム管理インターフェイスなしで、Easy Digital Downloads ソフトウェアライセンスを製品に迅速に統合するためのドロップイン ソリューションです。
ステップ 1: composer パッケージをインストールする
メインプラグインディレクトリにあるプラグインのcomposer.jsonファイルを更新(または作成)します。composer installを実行して、プラグインにソフトウェアライセンスSDKを追加します(このリンクには最新の指示と例も含まれています)。
ステップ 2: SDK を使用するようにテーマを更新する
このスニペットは、SDK と統合するためにテーマに必要なコードの開始点を提供します。
/**
* This is just a demonstration of how theme licensing works with
* Easy Digital Downloads.
*
* @package EDD Sample Theme
*/
/**
* Load theme updater functions.
* Action is used so that child themes can easily disable.
*/
/**
* Initialize the theme license handler and updater.
*
* This registry handles activating and deactivating the license key,
* as well as checking for updates to the theme.
*/
add_action(
'edd_sl_sdk_registry',
function ( $init ) {
$init->register(
array(
'id' => 'edd-sample-theme',
'url' => 'https://edd.local',
'item_id' => 36894,
'version' => '1.0.0',
'file' => __FILE__,
'type' => 'theme',
)
);
}
);
// Load the SDK from the vendor directory. The SDK handles autoloader setup automatically.
if ( file_exists( __DIR__ . '/vendor/easy-digital-downloads/edd-sl-sdk/edd-sl-sdk.php' ) ) {
require_once __DIR__ . '/vendor/easy-digital-downloads/edd-sl-sdk/edd-sl-sdk.php';
}
}
ストアに合わせて情報を変更してください:
id– プラグイン/テーマのスラッグ。url– ストアのURL。item_id– アイテムID(ストア上の)。version– 現在のバージョン番号。file– メインプラグインファイル。テーマには不要です。type–pluginまたはtheme。プラグインには不要です。weekly_check– オプション:ライセンス状況を確認するために週に1回リクエストを行うかどうか。デフォルトはtrueです。
テーマがアクティブ化されると、顧客はライセンス キーを追加し、ストアが PHP および WordPress のバージョンをアクティベーション データに追加できるように選択できます。

重要な注意点
- アップデートをリクエストする際にSSL検証で問題が発生した場合は、
edd_sl_api_request_verify_sslフィルターを使用してSSL検証フラグを無効にすることができます。 - ユーザーがテーマまたはプラグインの自動更新を有効にすることを防ぎたい場合は、配布コードにスニペットを追加して自動更新を無効にすることができます。
add_filter( 'auto_update_plugin', 'edd_sample_disable_plugin_autoupdates', 10, 2 );
function edd_sample_disable_plugin_autoupdates( $update, $plugin ) {
if ( 'my-plugin/my-plugin.php' === $plugin->plugin ) {
return false;
}
return $update;
}
add_filter( 'auto_update_theme', 'edd_sample_disable_theme_autoupdates', 10, 2 );
function edd_sample_disable_theme_autoupdates( $update, $theme ) {
if ( 'my-theme' === $theme->theme ) {
return false;
}
return $update;
}
