钩子文档

upgrader_pre_install

💡 云策文档标注

概述

upgrader_pre_install 是一个 WordPress 过滤器钩子,用于在安装过程开始前拦截并修改安装响应。开发者可以通过此钩子控制安装流程,例如通过返回 WP_Error 来中止安装。

关键要点

  • 钩子名称:upgrader_pre_install,在安装启动前触发。
  • 功能:过滤安装响应,允许返回 WP_Error 以短路安装过程。
  • 参数:$response(bool 或 WP_Error 类型,表示安装响应)和 $hook_extra(数组,传递给钩子的额外参数)。
  • 应用场景:常用于调试或自定义安装逻辑,如保留数据库中的版本信息。
  • 相关函数:在 WP_Upgrader::install_package() 中使用,位于 wp-admin/includes/class-wp-upgrader.php。
  • 版本历史:自 WordPress 2.8.0 引入。

📄 原文内容

Filters the installation response before the installation has started.

Description

Returning a value that could be evaluated as a WP_Error will effectively short-circuit the installation, returning that value instead.

Parameters

$responsebool|WP_Error
Installation response.
$hook_extraarray
Extra arguments passed to hooked filters.

Source

$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );

Changelog

Version Description
2.8.0 Introduced.

User Contributed Notes