钩子文档

pre_get_table_charset

💡 云策文档标注

概述

pre_get_table_charset 是一个 WordPress 过滤器,用于在数据库检查表字符集之前过滤其值。通过返回非空值,可以绕过数据库检查,直接使用过滤后的字符集。

关键要点

  • 过滤器名称:pre_get_table_charset
  • 作用:在 wpdb::get_table_charset() 检查数据库前,过滤表字符集值
  • 参数:$charset(字符集或 WP_Error,默认 null)和 $table(表名)
  • 返回值:返回非空值(如字符串)将跳过数据库检查,直接使用该值
  • 引入版本:WordPress 4.2.0

代码示例

$charset = apply_filters( 'pre_get_table_charset', null, $table );

注意事项

  • 此过滤器主要用于自定义字符集处理或优化性能,避免不必要的数据库查询
  • 相关函数:wpdb::get_table_charset(),用于检索表的字符集

📄 原文内容

Filters the table charset value before the DB is checked.

Description

Returning a non-null value from the filter will effectively short-circuit checking the DB for the charset, returning that value instead.

Parameters

$charsetstring|WP_Error|null
The character set to use, WP_Error object if it couldn’t be found. Default null.
$tablestring
The name of the table being checked.

Source

$charset = apply_filters( 'pre_get_table_charset', null, $table );

Changelog

Version Description
4.2.0 Introduced.