[WordPress] 外掛分享: WP Customizer

首頁外掛目錄 › WP Customizer
WordPress 外掛 WP Customizer 的封面圖片
20+
安裝啟用
★★★★★
5/5 分(2 則評價)
3046 天前
最後更新
問題解決
WordPress 4.8+ v1.0.2 上架:2013-06-04

內容簡介

這個外掛讓你能夠在 WordPress 網站中管理和載入特定的功能、腳本和 CSS 檔案,而不需要編輯你的佈景主題的 functions.php 或其他原始檔案。

設定和選項包括:

選擇你想要載入的客製化類型;包括功能、腳本和 CSS 檔案的任意組合。
選擇你想要載入客製化的位置;在 WordPress 前端、在 WordPress 管理介面或兩者皆載入。
選擇你想要存儲客製化檔案的位置,無需新增或修改你的佈景主題或外掛的原始檔案。

過濾器支援及使用方式

WP Customizer 支援多個過濾器;此外掛的過濾器允許你

修改即將載入的功能檔案集合
修改即將載入的腳本檔案集合
修改即將載入的每個腳本檔案的特性,並傳送作為參數傳至 wp_enqueue_script
修改即將載入的 CSS 檔案集合
修改即將載入的每個 CSS 檔案的特性,並傳送作為參數傳至 wp_enqueue_style

每個過濾器只會在此外掛的選項中啟用客製化類型時呼叫;如果啟用客製化類型但找不到要載入的檔案,該過濾器仍會被呼叫,但會傳送一個空參數。

和所有 WordPress 過濾器一樣,任何過濾器勾子函數應該返回修改後的參數,或是如果沒有進行修改,則返回原本的參數。

wp_customizer_functions、wp_customizer_admin_functions、wp_customizer_common_functions

當準備載入前端功能清單 (wp_customizer_functions)、管理介面功能清單 (wp_customizer_admin_functions) 或共同功能清單 (wp_customizer_common_functions) 時,將呼叫功能過濾器。所有過濾器處理函式接收到的引數都是相同的。過濾函式會接收一個陣列的檔案名稱作為單一引數。

範例: 藉由返回空的檔案清單,防止載入所有功能檔案。

add_filter('wp_customizer_functions', 'function_handler', 10, 1);

function function_handler($files) {
// $files = array(
// array(
// 'file' => (功能檔案的絕對路徑)
// ),
// array(...)
// );

return array();
}

wp_customizer_scripts、wp_customizer_admin_scripts、wp_customizer_common_scripts

當準備載入前端腳本清單 (wp_customizer_scripts)、管理介面腳本清單 (wp_customizer_admin_scripts) 或共同腳本清單 (wp_customizer_common_scripts) 時,將呼叫腳本過濾器。所有過濾器處理函式接收到的引數都是相同的。過濾函式會接收一個陣列的檔案詳細資料作為單一引數。

範例: 將 jQuery 加入所有腳本的相依性,並啟用每個腳本在文章底部載入。

add_filter('wp_customizer_scripts', 'script_handler', 10, 1);

function script_handler($files) {
// $files = array(
// array(
// 'file' => (腳本檔案的絕對路徑),
// 'handle' => (自動產生的腳本 handle),

外掛標籤

開發者團隊

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

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

原文外掛簡介

This plugin allows you to manage and load site specific functions, scripts and CSS files into your WordPress site without the need to edit your theme’s functions.php or any other source file.
Settings and options include:

Choose the type of customization you want to load; functions, scripts, CSS in any combination.
Choose where you want the customizations to load; in the WordPress front-end, in the WordPress admin screens or both.
Choose where you want to store your customization files, without the need to add to or modify your theme’s or your plugin’s source files.

Filter Support And Usage
WP Customizer supports multiple filters; the plugin’s filters allow you to

modify the set of functions files that are about to be loaded
modify the set of script files that are about to be loaded
modify the characteristics of each script file that is about to be loaded and which will be passed as arguments to wp_enqueue_script
modify the set of CSS files that are about to be loaded
modify the characteristics of each CSS file that is about to be loaded and which will be passed as arguments to wp_enqueue_style

Each filter will be only be called if the customization type is enabled in the plugin’s options; if a customization type is enabled but no files are found to be loaded, the filter will still be called but will be passed an empty argument.
As with all WordPress filters, any filter hook function should either return the modified argument or the original argument if no modification were made.
wp_customizer_functions, wp_customizer_admin_functions, wp_customizer_common_functions
The functions filters are called when preparing to load the list of front-end functions (wp_customizer_functions), of admin functions (wp_customizer_admin_functions) and of common functions (wp_customizer_common_functions). The arguments that each filter hook function receives is identical in all cases. The filter hook function takes a single argument which is an array of file names.
Example: Prevent all function files from loading by returning an empty file list.
add_filter('wp_customizer_functions', 'function_handler', 10, 1);

function function_handler($files) {
// $files = array(
// array(
// 'file' => (absolute path of function file)
// ),
// array(...)
// );

return array();
}

wp_customizer_scripts, wp_customizer_admin_scripts, wp_customizer_common_scripts
The scripts filters are called when preparing to load the list of front-end scripts (wp_customizer_scripts), of admin scripts (wp_customizer_admin_scripts) and of common scripts (wp_customizer_common_scripts). The arguments that each filter hook function receives is identical in all cases. The filter hook function takes a single argument which is an array of file details.
Example: Add jQuery as a dependency to all scripts and enable each script to load in the post’s footer.
add_filter('wp_customizer_scripts', 'script_handler', 10, 1);

function script_handler($files) {
// $files = array(
// array(
// 'file' => (absolute path of script file),
// 'handle' => (auto-generated handle for script),
// 'src' => (URL of script file),
// 'deps' => (dependencies, defaults to an empty array),
// 'ver' => (version, defaults to false),
// 'in_footer' => (load in footer, defaults to false),
// ),
// array(...)
// );

foreach ($files as $file) {
$file['deps'] = array('jquery');
$file['in_footer'] = true;
}

return $files;
}

wp_customizer_css, wp_customizer_admin_css, wp_customizer_common_css
The CSS filters are called when preparing to load the list of front-end CSS (wp_customizer_css), of admin CSS (wp_customizer_admin_css) and of common CSS (wp_customizer_common_css). The arguments that each filter hook function receives is identical in all cases. The filter hook function takes a single argument which is an array of file details.
Example: Override the media type for all CSS files to use the screen media type.
add_filter('wp_customizer_css', 'css_handler', 10, 1);

function css_handler($files) {
// $files = array(
// array(
// 'file' => (absolute path of css file),
// 'handle' => (auto-generated handle for CSS),
// 'src' => (URL of CSS file),
// 'deps' => (dependencies, defaults to an empty array),
// 'ver' => (version, defaults to false),
// 'media' => (media type, defaults to 'all')
// ),
// array(...)
// );

foreach ($files as $file) {
$file['media'] = 'screen';
}

return $files;
}

文章
Filter
Apply Filters
Mastodon