钩子文档

shutdown

💡 云策文档标注

概述

shutdown 是一个 WordPress 动作钩子,在 PHP 执行关闭前触发,适用于需要捕获所有请求场景的“兜底”逻辑。

关键要点

  • shutdown 钩子在 PHP 关闭执行前触发,由 shutdown_action_hook() 调用,并通过 register_shutdown_function() 在 wp-settings.php 中注册。
  • 该钩子始终被调用,包括在致命错误、Ajax 请求或使用 exit; 或 die(); 终止请求时,适合用于日志记录等“兜底”操作。
  • 注意:如果在 shutdown 动作处理程序中调用 exit;,请求会立即停止,不会调用其他 shutdown 动作处理程序。

📄 原文内容

Fires just before PHP shuts down execution.

More Information

Runs just before PHP shuts down execution.

This hook is called by shutdown_action_hook() and registered with PHP as a shutdown function by register_shutdown_function() in <a class="external text" href="https://core.trac.wordpress.org/browser/tags/5.5.1/src/wp-settings.php#L0" rel="nofollow">wp-settings.php</a>.

Source

do_action( 'shutdown' );

Changelog

Version Description
1.2.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    The shutdown action is always called, even on fatal errors, Ajax requests, and when using exit; or die(); to terminate a running request.

    That makes this function perfect for a “catch-all” logic, like writing a log file.

    Note: If you call exit; inside your shutdown action-handler, the request will be instantly halted without calling other shutdown action-handlers.