pre_wp_unique_post_slug
云策文档标注
概述
pre_wp_unique_post_slug 是一个 WordPress 过滤器,用于在生成唯一文章 slug 之前进行干预。开发者可以通过此 Hook 自定义 slug 生成逻辑,返回非 null 值可跳过默认的唯一性检查。
关键要点
- 过滤器名称:pre_wp_unique_post_slug,在 wp_unique_post_slug() 函数中被调用。
- 作用:允许在 slug 唯一性生成前修改或覆盖 slug,返回非 null 值会短路默认生成过程。
- 参数:包括 $override_slug(短路返回值)、$slug(期望的 slug)、$post_id(文章 ID)、$post_status(文章状态)、$post_type(文章类型)、$post_parent(父文章 ID)。
- 相关函数:wp_unique_post_slug() 用于计算唯一 slug。
- 版本历史:从 WordPress 5.1.0 版本引入。
原文内容
Filters the post slug before it is generated to be unique.
Description
Returning a non-null value will short-circuit the unique slug generation, returning the passed value instead.
Parameters
$override_slugstring|null-
Short-circuit return value.
$slugstring-
The desired slug (post_name).
$post_idint-
Post ID.
$post_statusstring-
The post status.
$post_typestring-
Post type.
$post_parentint-
Post parent ID.
Source
$override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_id, $post_status, $post_type, $post_parent );
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |