函数原型
avoid_blog_page_permalink_collision( array $data, array $postarr ): array
函数描述
Avoids a collision between a site slug and a permalink slug.
是否弃用
未弃用
函数参数
-
$data
array
Required - An array of post data.
-
$postarr
array
Required - An array of posts. Not currently used.
函数返回值
array The new array of post data after checking for collisions.
函数位置
File: wp-admin/includes/ms.php.
函数源码
function avoid_blog_page_permalink_collision( $data, $postarr ) {
if ( is_subdomain_install() ) {
return $data;
}
if ( 'page' !== $data['post_type'] ) {
return $data;
}
if ( ! isset( $data['post_name'] ) || '' === $data['post_name'] ) {
return $data;
}
if ( ! is_main_site() ) {
return $data;
}
if ( isset( $data['post_parent'] ) && $data['post_parent'] ) {
return $data;
}
$post_name = $data['post_name'];
$c = 0;
while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
$post_name .= mt_rand( 1, 10 );
$c++;
}
if ( $post_name !== $data['post_name'] ) {
$data['post_name'] = $post_name;
}
return $data;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |

