[WordPress] 外掛分享: Shortcode Callback

首頁外掛目錄 › Shortcode Callback
WordPress 外掛 Shortcode Callback 的封面圖片
10+
安裝啟用
★★★★★
5/5 分(1 則評價)
3891 天前
最後更新
問題解決
WordPress 2.5+ v1.0.0 上架:2015-06-17

內容簡介

「Shortcode Callback」這個外掛允許您在使用 shortcode 的地方執行任意的 PHP 代碼,只要使用 [callback] shortcode 即可。

用法如下:

使用以下 shortcode 執行 someFunction(),並插入其回傳結果:
[callback function=”someFunction”]

範例:使用以下 shortcode 包含一個 PHP 檔案(路徑相對於 WordPress 的 ABSPATH),然後在使用 shortcode 的地方插入執行 someFunction() 的結果:
[callback include=”custom/filetoinclude.php” function=”someFunction”]

範例:使用以下 shortcode 包含一個 PHP 檔案(路徑相對於 WordPress 的 ABSPATH),然後向 someFunction() 傳遞一個參數,在使用 shortcode 的地方回傳結果:
[callback function=”someFunction” include=”custom/filetoinclude.php” param=”something”]

使用該外掛呼叫類別/方法的格式與上面完全相同,只需在 shortcode 的「function」屬性中指定「class::method」即可。
[callback function=”someClass::someFunction” include=”custom/filetoinclude.php” param=”something”]

這裡有一個範例(並含有 PHP 代碼)。

外掛標籤

開發者團隊

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

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

原文外掛簡介

The Shortcode Callback plugin allows you to use a [callback] shortcode to execute arbitrary PHP code wherever the shortcode is used.
Usage
Execute someFunction() and insert whatever it returns with the following shortcode:
[callback function=”someFunction”]
Example shortcode to include a PHP file (the path is relative to WordPress’ ABSPATH), then insert the results of someFunction() where you used the shortcode:
[callback include=”custom/filetoinclude.php” function=”someFunction”]
Shortcode example that includes a PHP file (the path is relative to WordPress’ ABSPATH), then passes a paramter to someFunction() and returns the results where you used the shortcode:
[callback function=”someFunction” include=”custom/filetoinclude.php” param=”something”]
The format to call a class/method with the shortcode is exactly the same as above, except you specify the class::method in the “function” attribute of the shortcode.
[callback function=”someClass::someFunction” include=”custom/filetoinclude.php” param=”something”]
There is an example (with PHP code) over here.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon