Bricks 中文文档:bricks/wpml/translatable_control_types

标签TAGS: 

📄 原始资料  |  展开查看原始 JSON(bricks-wpml-translatable_control_types.json){ “name”: “bricks/wpml/translatable_control_types”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-wpml-translatable_control_types/”, “scraped_at”: “2026-08-29”, “hook_name”: “bric…

📄 原始资料  |  展开查看原始 JSON(bricks-wpml-translatable_control_types.json)
{
  "name": "bricks/wpml/translatable_control_types",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-wpml-translatable_control_types/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/wpml/translatable_control_types",
  "description": {
    "en": "The bricks/wpml/translatable_control_types filter controls which Bricks control types WPML includes in its translation jobs. Bricks includes text , textarea , editor , repeater , and link controls by default. The code type is excluded because automatic or manual translation can change executable PHP, JavaScript, HTML, or CSS. Add it only for fields whose complete value needs to differ between languages. The filter applies to element controls and Page Settings. Page Settings use a synthetic element with the name page-settings , which lets a callback target page-level custom code without exposing every code control on the site. This example exposes only the code field of the Code element. Its CSS and JavaScript fields remain excluded. The following callback exposes only Page Settings → Custom code → Header scripts . Other page-level CSS and script fields continue to use the source-language value. Available page-level custom-code keys are: After adding the filter, update the source page and send its translation to WPML again. The opted-in code field then appears in the WPML translation job. Review the translated value before publishing, especially when automatic translation is enabled, because a changed quote, variable, selector, or function name can break the code.",
    "zh": "bricks/wpml/translatable_control_types 筛选器控制 WPML 在其翻译任务中包含哪些 Bricks 控件类型。Bricks 默认包含 text、textarea、editor、repeater 和 link 控件。代码类型被排除,因为自动或手动翻译可能会更改可执行的 PHP、JavaScript、HTML 或 CSS。仅当字段的完整值需要在不同语言之间不同时才添加它。此筛选器适用于元素控件和页面设置。页面设置使用名为 page-settings 的合成元素,这允许回调在不暴露站点上每个代码控件的情况下针对页面级自定义代码。本示例仅公开 Code 元素的 code 字段。其 CSS 和 JavaScript 字段仍被排除。以下回调仅公开 Page Settings → Custom code → Header scripts。其他页面级 CSS 和脚本字段继续使用源语言值。可用的页面级自定义代码键是:添加筛选器后,更新源页面并再次将其翻译发送给 WPML。然后选中的代码字段将出现在 WPML 翻译任务中。在发布前审查翻译后的值,尤其是在启用自动翻译时,因为更改的引号、变量、选择器或函数名可能会破坏代码。"
  },
  "parameters": [
    {
      "name": "types",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Control types currently exposed to WPML.",
        "zh": "当前暴露给 WPML 的控件类型。"
      }
    },
    {
      "name": "element",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "The current Bricks element. For Page Settings, its name is page-settings and its id is pageSettings .",
        "zh": "当前的 Bricks 元素。对于 Page Settings,其名称为 page-settings,ID 为 pageSettings。"
      }
    },
    {
      "name": "control",
      "type": "array|null",
      "type_zh": null,
      "description": {
        "en": "The current control definition.",
        "zh": "当前的控件定义。"
      }
    },
    {
      "name": "key",
      "type": "string",
      "type_zh": null,
      "description": {
        "en": "The current control key or repeater field key.",
        "zh": "当前的控件键或 repeater 字段键。"
      }
    }
  ],
  "example_usage": null,
  "additional_sections": [
    {
      "heading": {
        "en": "Translate the PHP and HTML field of Code elements",
        "zh": "翻译 Code 元素的 PHP 和 HTML 字段"
      },
      "content": {
        "en": "This example exposes only the\ncode\nfield of the Code element. Its CSS and JavaScript fields remain excluded.",
        "zh": "此示例仅暴露 Code 元素的 code 字段。其 CSS 和 JavaScript 字段仍被排除。"
      }
    },
    {
      "heading": {
        "en": "Translate a Page Settings custom-code field",
        "zh": "翻译 Page Settings 的自定义代码字段"
      },
      "content": {
        "en": "The following callback exposes only\nPage Settings → Custom code → Header scripts\n. Other page-level CSS and script fields continue to use the source-language value.\nAvailable page-level custom-code keys are:\ncustomCss\ncustomScriptsHeader\ncustomScriptsBodyHeader\ncustomScriptsBodyFooter\nAfter adding the filter, update the source page and send its translation to WPML again. The opted-in code field then appears in the WPML translation job. Review the translated value before publishing, especially when automatic translation is enabled, because a changed quote, variable, selector, or function name can break the code.",
        "zh": "以下回调仅暴露 Page Settings → Custom code → Header scripts。其他页面级 CSS 和脚本字段继续使用源语言值。\n\n可用的页面级自定义代码键是:"
      }
    }
  ]
}

前言

bricks/wpml/translatable_control_types 筛选器控制 WPML 在其翻译任务中包含哪些 Bricks 控件类型。Bricks 默认包含 text、textarea、editor、repeater 和 link 控件。代码类型被排除,因为自动或手动翻译可能会更改可执行的 PHP、JavaScript、HTML 或 CSS。仅当字段的完整值需要在不同语言之间不同时才添加它。此筛选器适用于元素控件和页面设置。页面设置使用名为 page-settings 的合成元素,这允许回调在不暴露站点上每个代码控件的情况下针对页面级自定义代码。本示例仅公开 Code 元素的 code 字段。其 CSS 和 JavaScript 字段仍被排除。以下回调仅公开 Page Settings → Custom code → Header scripts。其他页面级 CSS 和脚本字段继续使用源语言值。可用的页面级自定义代码键是:添加筛选器后,更新源页面并再次将其翻译发送给 WPML。然后选中的代码字段将出现在 WPML 翻译任务中。在发布前审查翻译后的值,尤其是在启用自动翻译时,因为更改的引号、变量、选择器或函数名可能会破坏代码。

参数

  • $types (array):当前暴露给 WPML 的控件类型。
  • $element (array):当前的 Bricks 元素。对于 Page Settings,其名称为 page-settings,ID 为 pageSettings。
  • $control (array|null):当前的控件定义。
  • $key (string):当前的控件键或 repeater 字段键。

补充说明

更多细节可参考 官方文档