钩子文档

admin_memory_limit

💡 云策文档标注

概述

admin_memory_limit 是一个 WordPress 过滤器,用于调整管理后台的最大内存限制,主要针对管理员用户执行更新等内存密集型任务。默认限制基于 WP_MAX_MEMORY_LIMIT 常量或 PHP 配置。

关键要点

  • 此过滤器仅适用于管理员用户,不处理图像上传或编辑的内存限制。
  • WP_MAX_MEMORY_LIMIT 常量定义管理后台的最大内存限制,默认值为 256M 或更高的 PHP memory_limit 值。
  • 参数 $filtered_limit 接受整数(字节)或简写字符串(如 '256M')。
  • 相关函数 wp_raise_memory_limit() 用于在内存密集型过程中尝试提高 PHP 内存限制。
  • 从版本 4.6.0 起,默认值会考虑原始 memory_limit 配置。

代码示例

$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );

📄 原文内容

Filters the maximum memory limit available for administration screens.

Description

This only applies to administrators, who may require more memory for tasks like updates. Memory limits when processing images (uploaded or edited by users of any role) are handled separately.

The WP_MAX_MEMORY_LIMIT constant specifically defines the maximum memory limit available when in the administration back end. The default is 256M (256 megabytes of memory) or the original memory_limit php.ini value if this is higher.

Parameters

$filtered_limitint|string
The maximum WordPress memory limit. Accepts an integer (bytes), or a shorthand string notation, such as '256M'.

Source

$filtered_limit = apply_filters( 'admin_memory_limit', $filtered_limit );

Changelog

Version Description
4.6.0 The default now takes the original memory_limit into account.
3.0.0 Introduced.