wp_should_replace_insecure_home_url
云策文档标注
概述
wp_should_replace_insecure_home_url 是一个 WordPress 过滤器,用于控制是否自动将站点中的旧 HTTP URL 替换为 HTTPS 版本。当站点 URL 从 HTTP 迁移到 HTTPS 时,默认启用此替换行为。
关键要点
- 过滤器名称:wp_should_replace_insecure_home_url
- 参数:$should_replace_insecure_home_url(布尔值),表示是否应替换不安全的 HTTP URL
- 默认行为:如果站点 URL 已从 HTTP 更改为 HTTPS,则返回 true 以启用自动替换
- 用途:可通过此过滤器禁用自动替换,例如在手动更新数据库 URL 后
- 引入版本:WordPress 5.7.0
代码示例
return apply_filters( 'wp_should_replace_insecure_home_url', $should_replace_insecure_home_url );注意事项
此过滤器主要用于 HTTPS 迁移场景,开发者应谨慎使用以避免意外影响 URL 处理。
原文内容
Filters whether WordPress should replace old HTTP URLs to the site with their HTTPS counterpart.
Description
If a WordPress site had its URL changed from HTTP to HTTPS, by default this will return true. This filter can be used to disable that behavior, e.g. after having replaced URLs manually in the database.
Parameters
$should_replace_insecure_home_urlbool-
Whether insecure HTTP URLs to the site should be replaced.
Source
return apply_filters( 'wp_should_replace_insecure_home_url', $should_replace_insecure_home_url );
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |