跳转到主要内容

Write a check for asserting the value of a given constant

One of the check types included in wp doctor is Constant_Definition, or the ability to assert that a given constant is either defined, a specific value, or falsy. The check type is in use by a couple of the default diagnostic checks, and you can use the Constant_Definition check type in your custom doctor.yml configuration file. As an example, here are two checks using Constant_Definition, one which ensures SAVEQUERIES isn't defined and the other which ensures DISALLOW_FILE_MODS is true:

constant-savequeries-falsy:
  check: Constant_Definition
  options:
    constant: SAVEQUERIES
    falsy: true
constant-disallow-file-mods-true:
  check: Constant_Definition
  options:
    constant: DISALLOW_FILE_MODS
    value: true

Run together, you might see:

$ wp doctor check --config=constant-definition.yml --all
+----------------------------------+---------+--------------------------------------------------+
| name                             | status  | message                                          |
+----------------------------------+---------+--------------------------------------------------+
| constant-savequeries-falsy       | success | Constant 'SAVEQUERIES' is undefined.             |
| constant-disallow-file-mods-true | success | Constant 'DISALLOW_FILE_MODS' is defined 'true'. |
+----------------------------------+---------+--------------------------------------------------+

The Constant_Definition check type accepts the following options:

  • 'constant': Name of the constant.
  • 'defined': Constant is expected to be defined.
  • 'value': Constant is expected to be a specific value.
  • 'falsy': Constant is expected to be undefined or falsy.

📖 来源:WP-CLI Handbook · 作者:WP-CLI 开发组与贡献者 · 许可:MIT · 同步自上游提交 264cb13(2025-06-25)· 改动:仅格式转换

本页由 cocobook 外部书同步自动生成,此处只读;要修改请到菲码书稿仓 CocoBook/external-books 的 overlay 目录提合并请求。