钩子文档

log_query_custom_data

💡 云策文档标注

概述

log_query_custom_data 是一个 WordPress 过滤器,用于在记录查询时自定义附加数据。开发者可以通过此 Hook 修改或扩展查询日志中的自定义信息。

关键要点

  • 过滤器名称:log_query_custom_data
  • 用途:过滤与查询一起记录的自定义数据,允许开发者添加或修改查询日志中的额外信息
  • 参数:$query_data(自定义查询数据数组)、$query(查询的 SQL 字符串)、$query_time(查询总时间,秒)、$query_callstack(调用函数列表,逗号分隔)、$query_start(查询开始时间的 Unix 时间戳)
  • 注意事项:修改数据时应谨慎,建议将额外信息作为新的关联数组元素添加,以避免破坏现有结构
  • 相关函数:wpdb::log_query() 使用此过滤器记录查询数据
  • 引入版本:WordPress 5.3.0

代码示例

$query_data = apply_filters( 'log_query_custom_data', $query_data, $query, $query_time, $query_callstack, $query_start );

📄 原文内容

Filters the custom data to log alongside a query.

Description

Caution should be used when modifying any of this data, it is recommended that any additional information you need to store about a query be added as a new associative array element.

Parameters

$query_dataarray
Custom query data.
$querystring
The query’s SQL.
$query_timefloat
Total time spent on the query, in seconds.
$query_callstackstring
Comma-separated list of the calling functions.
$query_startfloat
Unix timestamp of the time at the start of the query.

Source

$query_data = apply_filters( 'log_query_custom_data', $query_data, $query, $query_time, $query_callstack, $query_start );

Changelog

Version Description
5.3.0 Introduced.