钩子文档

x_redirect_by

💡 云策文档标注

概述

本文档介绍 WordPress 中的 x_redirect_by 过滤器,用于过滤 X-Redirect-By 头,允许应用程序在重定向时标识自身。

关键要点

  • x_redirect_by 过滤器允许修改或设置 X-Redirect-By 头,以标识执行重定向的应用程序。
  • 过滤器参数包括 $x_redirect_by(应用程序标识字符串或 false 以省略头)、$status(状态码)和 $location(重定向路径)。
  • 在 wp_redirect() 函数中调用,通过 apply_filters 应用,仅当返回字符串时才设置 X-Redirect-By 头。

注意事项

  • 过滤器必须返回字符串,否则 X-Redirect-By 头将不会显示,因为 wp_redirect() 函数使用 is_string() 检查返回值。

📄 原文内容

Filters the X-Redirect-By header.

Description

Allows applications to identify themselves when they’re doing a redirect.

Parameters

$x_redirect_bystring|false
The application doing the redirect or false to omit the header.
$statusint
Status code to use.
$locationstring
The path to redirect to.

Source

$x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );

Changelog

Version Description
5.1.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    a word of caution: it SHOULD return a string.

    If you don’t return a string .. the header will not be shown
    This can be seen in the pluggable.php wp_redirect function

    $x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location );
    		if ( is_string( $x_redirect_by ) ) {
    			header( "X-Redirect-By: $x_redirect_by" );
    		}