主题开发文档

主题选项 – Customize API

💡 云策文档标注

概述

Customize API(Customizer)是 WordPress 中用于实时预览任何更改的框架,为自定义主题和网站提供统一界面,支持主题和插件添加选项。

关键要点

  • Customizer 是添加主题选项的规范方式,允许用户自定义颜色、布局、小工具、菜单等。
  • 选项可基于用户能力进行细粒度控制,默认仅管理员可见,但可配置其他用户访问。
  • Customizer 部分功能具有上下文相关性,例如小工具区域仅显示在当前预览页面中。
  • 建议开发者研究核心 Customizer 代码(文件名包含“customize”的文件)以获取最佳实践和详细文档。

📄 原文内容

The Customize API (Customizer) is a framework for live-previewing any change to WordPress. It provides a unified interface for users to customize various aspects of their theme and their site, from colors and layouts to widgets, menus, and more. Themes and plugins alike can add options to the Customizer. The Customizer is the canonical way to add options to your theme.

The customizer as it appears in WordPress 4.6 with the Twenty Fifteen theme.
The customizer as it appears in WordPress 4.6 with the Twenty Fifteen theme.

Customizer options can be granted to users with different capabilities on a granular basis, so while most options are visible only to administrators by default, other users may access certain options if you want them to be able to. Different parts of the Customizer can also be contextual to whether they’re relevant to the front-end context that the user is previewing. For example, the core widgets functionality only shows widget areas that are displayed on the current page; other widget areas are shown when the user navigates to a page that includes them within the Customizer preview window.

This section contains an overview of the Customize API, including code examples and discussion of best practices. For more details, it is strongly recommended that developers study the core customizer code (all core files containing “customize”). This is considered the canonical, official documentation for the Customize API outside of the inline documentation within the core code.