[WordPress] 外掛分享: Add Admin JavaScript

首頁外掛目錄 › Add Admin JavaScript
WordPress 外掛 Add Admin JavaScript 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
2,000+
安裝啟用
★★★★
4.8/5 分(5 則評價)
1775 天前
最後更新
問題解決
WordPress 4.9+ v2.0 上架:2011-12-04

內容簡介

此外掛提供了新增自訂動態功能至 WordPress 管理員頁面及應用 JavaScript 的能力。您可以透過此插件輕易地定義要新增到所有管理員頁面中的 JavaScript,包含行內或是來自 URL 的程式碼。您可以選擇讓新增的 JavaScript 出現在管理員頁面的標頭、頁腳 (建議),或是 jQuery jQuery(document).ready(function($)) {} 的區段,也可以參考 JavaScript 檔案並將其鏈結至頁面標頭中。所參考的 JavaScript 檔案會出現在標頭的最前方,其順序會遵循插件的設定。然後,行內的 JavaScript 會新增至管理員的頁頭。所有的值皆可以透過篩選器進行進階自訂 (請見篩選器部分)。

連結: 插件首頁 | 插件目錄頁面 | GitHub | 作者首頁

連結 (Hooks)
此外掛提供了四個連結以供外掛使用。一般來說,使用這些篩選器應該要將程式碼放置於 mu 外掛或是特定網域的外掛,這部分超出本文件的範圍。請注意,這些篩選器所控制的功能大部分可透過外掛的設定頁面配置。對於能夠撰寫程式碼的進階使用者而言,這些篩選器才有興趣。

c2c_add_admin_js_files (篩選器)

此篩選器提供程式化修改管理者頁面 enqueue 的 JavaScript 檔案清單的方法。

參數:

$files (array): JavaScript 檔案的陣列。

範例:

/**
* 新增一個 JavaScript 檔案至 WP 管理頁面的 enqueue 清單中。
*
* @param array $files 檔案的陣列。
* @return array
*/
function my_admin_js_files( $files ) {
$files[] = 'http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader-min.js';
return $files;
}
add_filter( 'c2c_add_admin_js_files', 'my_admin_js_files' );

c2c_add_admin_js_head (篩選器)

此篩選器允許自訂 JavaScript 直接新增至管理員頁面標頭的程式碼。

參數:

$js (string): JavaScript 程式碼,不包含 <script> 標籤。

範例:

/**
* 新增 JavaScript 程式碼至管理員頁面標頭。
*
* @param string $js JavaScript 程式碼。
* @return string
*/
function my_add_head_js( $js ) {
$js .= "alert('Hello');";
return $js;
}
add_filter( 'c2c_add_admin_js_head', 'my_add_head_js' );

c2c_add_admin_js_footer (篩選器)

此篩選器允許自訂 JavaScript 直接新增至管理員頁面頁腳的程式碼。

參數:

$js (string): JavaScript 程式碼,不包含 <script> 標籤。

範例:

/**
* 新增 JavaScript 程式碼至管理員頁面頁腳。
*
* @param string $js JavaScript 程式碼。
* @return string
*/
function my_add_footer_js( $js ) {
$js .= "alert('Hello');";
return $js;
}
add_filter( 'c2c_add_admin_js_footer', 'my_add_footer_js' );

c2c_add_admin_js_jq (篩選器)

此篩選器提供一個方法,允許自訂以 jQuery 啟動的管理頁面設定中 JavaScript 資料。

參數:

$jq (string): JavaScript 程式碼,不包含 <script> 標籤。

範例:

/**
* 新增 JavaScript 程式碼至以 jQuery 啟動的管理頁面。
*
* @param string $jq jQuery 程式碼。
* @return string
*/
function my_add_jq_js( $jq ) {
$jq = '$(document).ready(function() { alert("Hello"); });';
return $jq;
}
add_filter( 'c2c_add_admin_js_jq', 'my_add_jq_js' );

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.0) 或搜尋安裝

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

原文外掛簡介

Ever want to introduce custom dynamic functionality to your WordPress admin pages and otherwise harness the power of JavaScript? Any modification you may want to do with JavaScript can be facilitated via this plugin.
Using this plugin you’ll easily be able to define additional JavaScript (inline and/or by URL) to be added to all administration pages. You can define JavaScript to appear inline in the admin head, admin footer (recommended), or in the admin footer within a jQuery jQuery(document).ready(function($)) {} section, or reference JavaScript files to be linked in the page header. The referenced JavaScript files will appear in the admin head first, listed in the order defined in the plugin’s settings. Then any inline admin head JavaScript is added to the admin head. All values can be filtered for advanced customization (see Filters section).
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Hooks
The plugin exposes four filters for hooking. Typically, code making use of filters should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain). Bear in mind that most of the features controlled by these filters are configurable via the plugin’s settings page. These filters are likely only of interest to advanced users able to code.
c2c_add_admin_js_files (filter)
The ‘c2c_add_admin_js_files’ filter allows programmatic modification of the list of JavaScript files to enqueue in the admin.
Arguments:

$files (array): Array of JavaScript files.

Example:
/**
* Adds a JavaScript file to be enqueued in the WP admin.
*
* @param array $files Array of files.
* @return array
*/
function my_admin_js_files( $files ) {
$files[] = 'http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader-min.js';
return $files;
}
add_filter( 'c2c_add_admin_js_files', 'my_admin_js_files' );

c2c_add_admin_js_head (filter)
The ‘c2c_add_admin_js_head’ filter allows customization of the JavaScript that should be added directly to the admin page head.
Arguments:

$js (string): JavaScript code (without

文章
Filter
Apply Filters
Mastodon