钩子文档

customize_changeset_branching

💡 云策文档标注

概述

本文档介绍了 WordPress 自定义器中 changeset 分支功能的过滤器,用于控制是否允许多个 changeset 同时存在。默认情况下,changeset 以线性方式运行,适合大多数用户;而启用分支后,允许多用户独立管理 changeset,适合多用户协作场景。

关键要点

  • 过滤器名称:customize_changeset_branching,用于控制 changeset 分支是否允许。
  • 默认行为:分支不允许,changeset 以线性方式运行,类似编辑单个文章,所有用户共享一个 changeset。
  • 启用分支:允许后,changeset 以分支方式运行,类似创建新页面,每个用户拥有独立的 changeset 和自动草稿。
  • 适用场景:线性 changeset 适合大多数用户;分支 changeset 适合多用户在自定义器中频繁协作管理的站点。
  • 参数:$allow_branching(布尔值,是否允许分支)和 $wp_customize(WP_Customize_Manager 实例)。

代码示例

$this->branching = apply_filters( 'customize_changeset_branching', $this->branching, $this );

注意事项

  • 此过滤器在 WordPress 4.9.0 版本中引入。
  • 相关函数:WP_Customize_Manager::branching(),用于检查 changeset 分支是否允许。

📄 原文内容

Filters whether or not changeset branching is allowed.

Description

By default in core, when changeset branching is not allowed, changesets will operate linearly in that only one saved changeset will exist at a time (with a ‘draft’ or ‘future’ status). This makes the Customizer operate in a way that is similar to going to “edit” to one existing post: all users will be making changes to the same post, and autosave revisions will be made for that post.

By contrast, when changeset branching is allowed, then the model is like users going to “add new” for a page and each user makes changes independently of each other since they are all operating on their own separate pages, each getting their own separate initial auto-drafts and then once initially saved, autosave revisions on top of that user’s specific post.

Since linear changesets are deemed to be more suitable for the majority of WordPress users, they are the default. For WordPress sites that have heavy site management in the Customizer by multiple users then branching changesets should be enabled by means of this filter.

Parameters

$allow_branchingbool
Whether branching is allowed. If false, the default, then only one saved changeset exists at a time.
$wp_customizeWP_Customize_Manager
Manager instance.

Source

$this->branching = apply_filters( 'customize_changeset_branching', $this->branching, $this );

Changelog

Version Description
4.9.0 Introduced.