前言介紹
- 這款 WordPress 外掛「Cookie Connector For Themer」是 2019-01-20 上架。
- 目前有 10 個安裝啟用數。
- 上一次更新是 2023-06-01,距離現在已有 702 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 4.7 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 5.6.3 以上。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
cookie | connector | beaver themer | beaver builder |
內容簡介
Cookie Connector for (Beaver) Themer
外掛描述
Cookie Connector for Beaver Themer 是一個非官方的外掛,它可以與常見的Beaver Themer外掛搭配使用。此外掛使用Beaver Themer Connector讀取cookie值,並使用條件邏輯根據cookie值來隱藏/顯示不同的節點(模塊,列和/或行)。
Cookie Connector還可以通過AJAX調用創建cookie。由於安全措施,您需要自行編寫AJAX,但可以在此處的示例文件夾中找到如何操作的示例文件:
https://github.com/badabingbreda/cookie-connector-for-themer/
使用Cookie Connector
您可以像字符串一樣在任何位置顯示Cookie Connector,使用連接或插入按鈕。
使用條件邏輯過濾器
由於cookie有一定的有效性,當cookie不存在或已失效時,該過濾器無法返回任何值。條件邏輯過濾器有一個額外的參數,用於設置當它無法返回任何值時的默認值。設置此參數將在不存在時返回該值。
編寫cookie值
在編寫cookie值之前,必須先編寫任何標頭發送給訪問者的瀏覽器。這樣做的缺點是,在訪問者發送請求之前就只能讀取cookie,因為它們是隨請求一起發送的。這意味著您不能寫入cookie的值,並立即在單次頁面調用中讀取那個cookie的新值。
為了解決這個問題,可以使用AJAX調用來編寫cookie。
“Cookie Connector for Themer”會排隊註冊處理安全和發送請求的“cookieConnector”對象腳本。
讓我們考慮在HTML模塊中使用的以下HTML代碼:
第一個參數是要在PHP腳本中調用的“動作名”,因此在此示例中(參見下文)是“wp_ajax_”和“wp_ajax_nopriv_”之後的部分。
您還可以添加一個可選的第三個參數“debug”,它將添加響應的console.log dump,以便您知道正在回答什麼:
添加創建/更改/刪除cookie的PHP代碼
單擊鏈接將觸發AJAX調用,該調用將在訪問者設備上設置cookie(如果其瀏覽器允許)。
在服務器端,您需要添加一個或兩個ajax回調,具體取決於是否可以在未登錄的情況下進行調用。
add_action( 'wp_ajax_setmycookie' , 'callback_setmycookie' );
add_action( 'wp_ajax_nopriv_setmycookie' , 'callback_setmycookie' );
add_action( 'wp_ajax_unsetmycookie' , 'callback_setmycookie' );
add_action( 'wp_ajax_nopriv_unsetmycookie' , 'callback_setmycookie' );
function callback_setmycookie() {
// first check if this ajax call is
// done using the script belonging to the installation
// 略
}
?>
原文外掛簡介
Cookie Connector for (Beaver) Themer
Plugin description
Cookie Connector for Beaver Themer is an unofficial addon-plugin for the popular Beaver Themer plugin. It allows you to read cookie-values using the Beaver Themer Connector and use Conditional Logic to hide/show seperate nodes (modules, columns and/or rows) using cookie values.
Cookie Connector also allows you to create cookies using an AJAX call. For security measures you will need to write the AJAX yourself, but an example file on how to do that can be found here, in the example folder:
https://github.com/badabingbreda/cookie-connector-for-themer/
Using the Cookie Connector
You can display the Cookie Connector wherever you’d normally insert it as a string, using either the connect or insert button.
Using the Conditional Logic filter
Because cookies have a certain validity, it can’t return a value when the cookie isn’t there or has become invalid. The Conditional Logic filter has an extra parameter to set a default value for whenever it doesn’t return anything. Setting this parameter return that value whenever it doesn’t exist.
Writing cookies values
Cookies are written before any headers are written to the visitor’s browser. The downside to that is that cookies can only be read when the visitor’s sends a request, since they are sent over WITH the request. This means that you can’t write a cookie’s value and immediately read that cookies new value, within a single run of a page-call.
To work around that, cookies can be written using an AJAX call.
“Cookie Connector for Themer” enqueues a script that registers the cookieConnector object, which handles the security and sending of requests.
Let’s consider the following html-code that is used in a HTML module:
The first parameter is the actionname that is going to be called in the PHP script, so in this example (see below) the part after ‘wp_ajax_’ and ‘wp_ajax_nopriv_’.
You can also add an extra, optional, third parameter debug that will add a console.log dump of the response, should you need to know what’s being answered:
Adding the PHP code to create/change/delete the cookie
Clicking the link wil trigger an AJAX call that will set a cookie on the visitor’s device, if their browser allows it.
On the server-side, you will need to add one or two ajax callbacks, depending if the call can be made without being logged in.
false, 'error' => '402', 'message' => 'cookie not set, no value given. ( cv )' ) );
}
// check action parameter
// UNSET mycookie
if ( 'unsetmycookie' == $_GET['action'] ) {
setcookie( $cookie_name , 'unset value' , time() - 1 , COOKIEPATH, COOKIE_DOMAIN , isset($_SERVER["HTTPS"]) );
wp_send_json( array( 'success' => true, 'message' => "Done unsetting cookie '{$cookie_name}'." ) );
} else if ( 'setmycookie' == $_GET['action'] ) {
setcookie( $cookie_name , $cookie_value , time() + $cookie_valid , COOKIEPATH, COOKIE_DOMAIN , isset($_SERVER["HTTPS"]), true );
wp_send_json( array( 'success' => true, 'message' => "Done setting cookie '{$cookie_name}' to value '{$cookie_value}' with validity $cookie_valid seconds." ) );
}
wp_die();
}
It is advised to use wp_send_json with a ‘success’ parameter (either true or false) so that you check it in your javascript and add actions after sending the cookieConnector() command, for instance a reload of the page or forwarding to an url that you received from the server based on the click.
For instance, the javascript below will try to create the cookie. When successful it will display an alert on the browser and reload the page after 1.5 seconds.
Special thanks
Thanks to 10UP for creating this github action for easy deployment. https://github.com/marketplace/actions/wordpress-plugin-deploy
version history
1.3.1
Forgot to update readme.md (this file). Small fix for isset because it’s not the value that we want (could be falsy) but return if the cookie is set.
1.3.0
Rewrite of plugin using Autoloader. Fixed isset error.
1.2.0
Removed admin_notice so that plugin can be used without Beaver Themer and Beaver Builder too (scripts), for ajax calls.
1.1.0
Updated the version because it works on WP 5.4 too
1.0.1
Updated example code
1.0.0
Initial release (January 18th, 2019)
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Cookie Connector For Themer」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
1.2.2 | 1.3.0 | 1.3.1 | 1.3.2 | trunk |
延伸相關外掛(你可能也想知道)
WooCommerce JTL-Connector 》ons to JTL-Wawi., 使用 JTL-Connector for WooCommerce,您可以將您的 WooCommerce 在線商店與免費, 的 JTL-Wawi ERP 系統連接起來,該系統由 JTL-Software ...。
Bitly URL Shortener 》Bitly URL Shortener(以前稱為 Codehaveli Bitly URL Shortener)使用 Bitly API 功能,在您發布新文章時,在您的 WordPress 管理面板中自動生成 bitly 短連...。
Contact Form 7 to Mailjet 》「Contact Form 7 to Mailjet」是一款由 Youdemus 開發的WordPress外掛。, 這個外掛可以讓你在WordPress網站上使用「Contact Form 7」的聯絡表單,每次使用者...。
Fluent Connect – Connect ThriveCart with your WordPress and FluentCRM 》將 ThriveCart 與 FluentCRM 和 WordPress 連線, 這個外掛的目的是將 ThriveCart 與 FluentCRM 連線。ThriveCart 是一個簡單而強大的購物車解決方案,適用於...。
osTicket Connector 》此 WordPress 外掛支援透過 osTicket API 創建新的 osTicket 系統問題單。本外掛只支援採用 wp_mail 函數發送電子郵件的聯絡表單,以便獲取表單資料。, 注意...。
Connector for Gravity Forms and MailPoet 》HTML 標籤的項目說明:, , 總結:, Gravity Forms 和 MailPoet 外掛連接器讓您輕鬆將 Gravity Forms 與 Mailpoet 電子報服務完美整合。這個外掛能夠在用戶在...。
Easy ACF Connect For Themer 》說明, 輕鬆地在 Beaver Themer 中連接 ACF 欄位。無需記住欄位名稱,只需從下拉選單中輕鬆選擇即可。它會返回所有欄位名稱,跨越所有欄位分組。, Easy ACF Co...。
Connector to CiviCRM with CiviMcRestFace 》此外掛提供連接本地或遠端 CiviCRM 的連接器,其他外掛如CiviCRM 表單處理器與 Caldera 表單的整合可以重複使用此連接器。, 配置, 可在「設定 > CiviCRM McRe...。
CI HUB Connector 》此外掛將為您連接所有的圖片、圖像和文本資源,以輕鬆快捷地同步您的資料庫(DAM/PIM/Stock)。這是處理圖片、圖形素材等所有需求的平台首選。CI HUB連接器插件...。
WP GestSup Connector 》WP GestSup Connector 可以讓您將 WordPress 網站連接到 GestSup 幫助台, 在您的網站上添加一個表單,讓您的客戶能夠直接在您的 GestSup 幫助台中開啟票證, /...。
MiragetConnector 》MiragetConnector 是唯一可用的 WordPress 外掛程式,用於在 1,000 多個支援的 WordPress 外掛程式和 SaaS 軟體、CRM、資料庫、雲端應用程式等平台之間進行即...。
FLC forma.lms connector 》當 WordPress 中建立、編輯或刪除使用者時,forma.lms 會相對建立、編輯或刪除對應的使用者。, 當使用者登入 WordPress 後,他可以透過訪問自動產生的 SSO 頁...。
Bumbal connector 》透過這個外掛程式,您可以自動將訂單傳送至 Bumbal。顧客可以在付款完成後,自行規劃路線。, 一個簡單的 Markdown 範例, 排序清單:, , 直接將訂單傳送至 Bum...。
Imago Images 》總結:Imago Images 的官方 WordPress 外掛,透過連接 WordPress 媒體庫與 Imago Images 庫,新增了方便導入圖片的 Import from Imago 選項。, , HTML 程式碼...。
Dynamic Connector Block 》總結:這個 WordPress 外掛可以讓你在多個文章中插入經過精選的內容,使用邏輯決定整個網站顯示的內容,而不需要聘請開發人員或寫程式碼。, 問題與答案:, 1....。