Kadenceチュートリアル:WooCommerceでKadenceパターンハブのアクセスキーを販売する

使用中 ケイデンス Pattern Hub を使用する場合、デザイン?ライブラリのアクセス?キーを生成し、他の人にアクセスを提供することができます。デザイン?ライブラリへのアクセスを WooCommerce WooCommerce Software License PluginとLicense Manager for WooCommerceプラグインは理想的なソリューションです。この記事では、このプラグインの基本設(shè)定と、アクセスキー販売のためのKadence Pattern Hubとの統(tǒng)合方法。

畫像 [1]- WooCommerceでKadenceパターンハブアクセスキーを販売するための完全ガイド

ステップ1:パターン?ハブ?アクセス製品の作成

第一に WooCommerce アクセスキーの販売に使用する新しい商品を作成します。出荷プロセスを使用しない仮想商品として設(shè)定します。

  • バーチャル製品の作成
    入り込む ワードプレス バックエンド WooCommerce -> 商品 -> 新しい商品の追加そして、バーチャル?プロダクトとしてセットアップされる。
畫像[2]-WooCommerceでKadenceパターンハブのアクセスキーを販売するための完全ガイド
  • 設(shè)定ライセンス
    使用するプラグイン(WooCommerce Software LicenseまたはLicense Manager for WooCommerce)に応じて、製品のライセンス設(shè)定を行い、アクセスキージェネレータと関連付けます。
畫像[3]-WooCommerceでKadenceパターンハブアクセスキーを販売するための完全ガイド
WooCommerceソフトウェアライセンス(WooCommerceソフトウェアライセンス)
畫像[4]-WooCommerceでKadenceパターンハブアクセスキーを販売するための完全ガイド
WooCommerceライセンスマネージャ(WooCommerce用ライセンスマネージャ)

ステップ 2: Kadence パターン?ハブをライセンス認(rèn)証に接続する

ある WooCommerce Kadence Pattern Hubでアクセスキーを販売した後、Kadence Pattern Hubがライセンスの有効性を確認(rèn)できるようにする必要があります。そのためには、Kadence Pattern Hubにカスタム PHP フィルター

WooCommerceソフトウェア?ライセンス?フィルター設(shè)定::

以下のスニペットは、リクエストされたドメインに対して、リクエスト時(shí)にライセンスが有効で有効化されているかどうかをチェックする。キーが有効でアクティベートされていれば、アクセスは許可されたものとして返されます。

/**
 * Validates license with WooCommerce Software License.
 *
 * @param Boolean         $access true or false based on access.
 * @param String          $key the access key.
 * @param WP_REST_Request $request full details about the request.
 * @return Boolean based on if access should be granted.
 */
function custom_check_cloud_access( $access, $key, $request ) {
	// If true the key matches with settings in Kadence Pattern Hub. Let that pass for testing purposes.
	if ( $access ) {
		return $access;
	}
	// Make sure WooCommerce Software License exists.
	global $WOO_SL_API;
	if ( $WOO_SL_API ) {
		$site = preg_replace('(^https?://)', '', $request->get_param( 'site' ) );
		$args =   array(
			'licence_key'       => $key,
			'domain'            => $site,
			'woo_sl_action'     => 'status-check',
			'product_unique_id' => 'PRODUCT_UNIQUE_ID',
		);
		$response = $WOO_SL_API->API_call( $args );
		$response = json_decode( $response );
		end( $response );
		$response_data = current( $response );
		if ( is_object( $response_data ) && 'success' === $response_data->status ) {
			// Lets activate it for this domain if it's not.
			if ( $response_data->status_code && 's203' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
			}
			return true;
		} else if ( is_object( $response_data ) && 'error' === $response_data->status ) {
			// Lets activate it for this domain if possible.
			if ( $response_data->status_code && 'e204' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
				$response = json_decode( $response );
				end( $response );
				$response_data = current( $response );
				if ( is_object( $response_data ) && 'success' === $response_data->status ) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	return $access;
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );

特定のパターン?ライブラリー?コレクションへのアクセス制限

あるアクセス?キーが特定のスキーマ?ライブラリのコレクションにしかアクセスできないように制限したい場合は、以下のコードで行うことができる:

/**
 * 特定のパターンハブライブラリコレクションへのアクセスを設(shè)定します。
 /** * 特定のパターンハブライブラリコレクションへのアクセスを設(shè)定します。
 * @param array $args アイテム取得のためのクエリ引數(shù) * @param string $key アクセスキー。
 * @param string $key アクセスキー。
 * @param array $request_extras リクエストの追加引數(shù) * @return array with updated query args.
 * 更新されたクエリ引數(shù)を配列で返します。
 */
function custom_kadence_cloud_query_args( $args, $key, $request_extras ) { 以下のようにします。
if ( ! isset( $args['tax_query'] ) ) { { $args['tax_query'] )
$args['tax_query'] = array(
array(
'taxonomy' => 'kadence-cloud-collections'、
'field' => 'slug'、
'terms' => array( 'COLLECTION_SLUG')
),
);
}
return $args.
}
add_filter( 'kadence_cloud_template_query_args', 'custom_kadence_cloud_query_args', 10, 3 );

複數(shù)のコレクションのアクセスキーを販売

販売するスキーマコレクションが複數(shù)ある場合は、コレクションごとに異なるライセンス接頭辭を設(shè)定することで販売できます:

/**
 * Validates license with WooCommerce Software License.
 *
 * @param Boolean         $access true or false based on access.
 * @param String          $key the access key.
 * @param WP_REST_Request $request full details about the request.
 * @return Boolean based on if access should be granted.
 */
function custom_check_cloud_access( $access, $key, $request ) {
	// If true the key matches with settings in Kadence Pattern Hub. Let that pass for testing purposes.
	if ( $access ) {
		return $access;
	}
	// Make sure WooCommerce Software License exists.
	global $WOO_SL_API;
	if ( $WOO_SL_API ) {
		if ( substr( $key, 0, strlen( 'col_one' ) ) === 'col_one' ) {
			$product_id = 'PRODUCT_UNIQUE_ID';
		} else {
			$product_id = 'PRODUCT_UNIQUE_ID_TWO';
		}
		$site = preg_replace('(^https?://)', '', $request->get_param( 'site' ) );
		$args =   array(
			'licence_key'       => $key,
			'domain'            => $site,
			'woo_sl_action'     => 'status-check',
			'product_unique_id' => $product_id,
		);
		$response = $WOO_SL_API->API_call( $args );
		$response = json_decode( $response );
		end( $response );
		$response_data = current( $response );
		if ( is_object( $response_data ) && 'success' === $response_data->status ) {
			// Lets activate it for this domain if it's not.
			if ( $response_data->status_code && 's203' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
			}
			return true;
		} else if ( is_object( $response_data ) && 'error' === $response_data->status ) {
			// Lets activate it for this domain if possible.
			if ( $response_data->status_code && 'e204' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
				$response = json_decode( $response );
				end( $response );
				$response_data = current( $response );
				if ( is_object( $response_data ) && 'success' === $response_data->status ) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	return $access;
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );

WooCommerce用ライセンスマネージャ フィルター設(shè)定

License Manager for WooCommerce プラグインを使用している場合、以下のようになります。 PHP このコードは、ライセンスの有効性を確認(rèn)するのに役立ちます:

/**
 * ライセンスマネージャでライセンスを検証します。
 /** * ライセンスをwoocommerceのライセンスマネージャで検証します。
 * @param Boolean $access アクセスに基づき、true または false を返します。
 * @param String $key アクセスキー。
 * @param WP_REST_Request $request リクエストの詳細(xì) * @return WP_REST_Request に基づく Boolean。
 * アクセスが許可されるべきかどうかに基づいてブール値を返す。
 */ 関數(shù) custom_check_cloud
function custom_check_cloud_access( $access, $key, $request ) { // trueの場合、キーが設(shè)定と一致します。
// もしtrueなら、キーはKadence Cloudの設(shè)定と一致します。
もしtrueなら、キーはKadence Cloudの設(shè)定と一致します。
if ( $access ) { return $access; // true の場合、キーは Kadence Cloud の設(shè)定と一致する。
}
// woocommerce用のライセンスマネージャが存在することを確認(rèn)します。
if ( class_exists( 'LicenseManagerForWooCommerceRepositoriesResources?License' ) { { $license = ?$license。
$license = ¦LicenseManagerForWooCommerce¦Repositories¦License::instance()->findBy(
array( 'hash' => apply_filters( 'lmfwc_hash', $key ) )
);
if ( ! $license ) { // ライセンスは見つかりませんでした。
// ライセンスは見つかりませんでした。
return false; } else { // ライセンスは見つかりませんでした。
} else {
// 期限切れかどうかをチェックします。
$expiresAt = $license->getExpiresAt(); $dateExpiresAt = new DateTime($expires)
$dateExpiresAt = new DateTime($expiresAt); $dateNow
$dateNow = new DateTime('now', new DateTimeZone('UTC'));
if ( $dateNow < $dateExpiresAt ) { if ( $dateNow getTimesActivated() ) update()
$license->getId()、
array(
'times_activated' => $timesActivatedNew
)
);
}
// 成功しました。
成功しました。
}
}
return $access; }.
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );

概要

結(jié)合 WooCommerce ソフトウェアライセンスプラグインまたはWooCommerceプラグインのLicense Manager。ケイデンス Pattern Hubは強(qiáng)力なアクセスキー管理機(jī)能を提供します。これらのプラグインを使用することで、アクセスキーを簡単に管理し、正確なパーミッション制御を設(shè)定し、複數(shù)のコレクションの販売をサポートし、コンテンツの販売と管理を大幅に促進(jìn)します。


お問い合わせ
チュートリアルが読めない?無料でお答えします!個(gè)人サイト、中小企業(yè)サイトのための無料ヘルプ!
カスタマーサービス WeChat
カスタマーサービス WeChat
電話:020-2206-9892
QQ咨詢:1025174874
Eメール:info@361sale.com
勤務(wù)時(shí)間: 月~金、9:30~18:30、祝日休み
? 複製に関する聲明
この記事を書いた人:泥棒はネズミの勇気になる
終わり
好きなら応援してください。
クドス464 分かち合う
おすすめ
解説 ソファ購入

コメントを投稿するにはログインしてください

    コメントなし