[WordPress] 外掛分享: Catenis API Client for WordPress

首頁外掛目錄 › Catenis API Client for WordPress
WordPress 外掛 Catenis API Client for WordPress 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
全新外掛
安裝啟用
尚無評分
1260 天前
最後更新
問題解決
WordPress 5.8+ PHP 5.6+ v4.0.0 上架:2019-01-02

內容簡介

Catenis API 客戶端是一款 WordPress 外掛,可讓 WordPress 頁面上的 JavaScript 代碼與 Catenis API 進行交互。

啟用 Catenis API 客戶端

要啟用特定 WordPress 頁面的 Catenis API 客戶端,請前往該頁面的編輯頁面,尋找位於主編輯面板下方的名稱為「Catenis API 客戶端」的區域(元框),確保該區域已展開,並勾選「載入 Catenis API 客戶端」勾選框。

然後,您可以選擇覆寫全域設置,使用不同的設備 ID 和其相關的 API 訪問密鑰在該給定頁面上實例化 Catenis API 客戶端。否則,將會使用插件全域設置中配置的設置,其在「設置」|「Catenis API 客戶端」下配置。

使用 Catenis API 客戶端

啟用後,全域 JavaScript 變數 ctnApiClient 會在該頁面上被加載,該變數保存實例化的 Catenis API 客戶端對象。

使用 ctnApiClient 變數調用 Catenis API 方法,通過在該對象上調用相應的方法來實現。

有關可用方法的參考,請參閱 Catenis API JavaScript 客戶端,它與 WordPress 的 Catenis API 客戶端在功能上幾乎相同,除了通知支持和錯誤處理。

通知支持

WordPress 的 Catenis API 客戶端的通知功能與 Catenis API JavaScript 客戶端上的功能幾乎相同。兩個明顯的不同點是:

Catenis API 對象可以發出 comm-error 事件。
WebSocket 通知通道對象發出的 open 事件可能會返回錯誤。

有關如何在 WordPress 頁面中接收 Catenis 通知的詳細信息,請參閱下面的「接收通知」部分。

錯誤處理

調用 Catenis API 方法時發生的錯誤將以標準 JavaScript 錯誤對象的形式返回。

接收通知

=實例化 WebSocket 通知通道對象

為特定的 Catenis 通知事件創建一個 WebSocket 通知通道。

var wsNotifyChannel = ctnApiClient.createWsNotifyChannel(eventName);

添加事件監聽器

添加事件監聽器以監測通知通道上的活動。

ctnApiClient.on('comm-error', function (error) {
// 與 Catenis 通知過程通信時出現錯誤
});

wsNotifyChannel.on('open', function (error) {
if (error) {
// 確立基礎 WebSocket 連接時出現錯誤
}
else {
// 通知通道成功開啟
}
});

wsNotifyChannel.on('error', function (error) {
// 基礎 WebSocket 連接出現錯誤
});

wsNotifyChannel.on('close', function (code, reason) {
// 基礎 WebSocket 連接已關閉
});

wsNotifyChannel.on('notify', function (eventData) {
// 收到通知
});

注意: 「comm-error」事件由 Catenis API 對象發出,而所有其他事件由 WebSocket 通知通道對象發出。

開啟通知通道

打開 WebSocket 通知通道以開始接收通知。

wsNotifyChannel.open(function (error) {
if (err) {
// 發送打開通知指令時出錯
}
});

外掛標籤

開發者團隊

⬇ 下載最新版 (v4.0.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Catenis API Client for WordPress」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Catenis API Client for WordPress enables (JavaScript) code on WordPress pages to interact with the Catenis API.
Enabling the Catenis API client
To enable the Catenis API client for a given WordPress page, go to the page’s edit page and look for a section (meta box) named “Catenis API Client” below the page’s main editing panel. Make sure the section is expanded, and check the Load Catenis API Client checkbox.
You can then choose to override the global settings used for instantiating the Catenis API client on that given page, like using a different device ID and its associated API access secret. Otherwise, whatever is configured in the plugin’s global settings — configured under “Settings” | “Catenis API Client” — is going to be used.
Using the Catenis API client
Once enabled, a global JavaScript variable named ctnApiClient is made available on the page. That variable holds the instantiated Catenis API client object.
Use the ctnApiClient variable to call the Catenis API methods by invoking the corresponding method on that object.
For a reference of the available methods, please refer to the Catenis API JavaScript Client as it is functionally identical to the Catenis API Client for WordPress, except for notifications support and error handling.
Notifications support
The notification feature on Catenis API Client for WordPress is almost identical to the one found on the Catenis API JavaScript client. The two noticeable differences are:

The Catenis API client object can emit a comm-error event.
The open event emitted by the WebSocket notification channel object may return an error.

Please refer to the “Receiving Notifications” section below for detailed information on how to receive Catenis notifications from within WordPress pages.
Error handling
Errors that take place while calling the Catenis API methods are returned as standard JavaScript Error objects.
Receiving Notifications
= Instantiate WebSocket notification channel object
Create a WebSocket notification channel for a given Catenis notification event.
var wsNotifyChannel = ctnApiClient.createWsNotifyChannel(eventName);

Add listeners
Add event listeners to monitor activity on the notification channel.
ctnApiClient.on('comm-error', function (error) {
// Error communicating with Catenis notification process
});

wsNotifyChannel.on('open', function (error) {
if (error) {
// Error establishing underlying WebSocket connection
}
else {
// Notification channel successfully open
}
});

wsNotifyChannel.on('error', function (error) {
// Error in the underlying WebSocket connection
});

wsNotifyChannel.on('close', function (code, reason) {
// Underlying WebSocket connection has been closed
});

wsNotifyChannel.on('notify', function (eventData) {
// Received notification
});

Note: the ‘comm-error’ event is emitted by the Catenis API client object while all other events are emitted by the WebSocket notification channel object.

Open the notification channel
Open the WebSocket notification channel to start receiving notifications.
wsNotifyChannel.open(function (error) {
if (err) {
// Error sending command to open notification channel
}
});

Close the notification channel
Close the WebSocket notification channel to stop receiving notifications.
wsNotifyChannel.close(function (error) {
if (err) {
// Error sending command to close notification channel
}
});

延伸相關外掛

文章
Filter
Mastodon