From d0a7b4d15c25fbef78e2de8db12f63801b3456bc Mon Sep 17 00:00:00 2001 From: Jignesh Dhandhukiya Date: Fri, 3 Jan 2025 11:31:32 +0530 Subject: [PATCH] 54117 memory limit changes --- src/wp-admin/includes/class-wp-debug-data.php | 12 +++++----- src/wp-includes/default-constants.php | 24 +++++++++---------- src/wp-includes/functions.php | 10 ++++---- src/wp-settings.php | 2 +- tests/phpunit/includes/bootstrap.php | 4 ++-- tests/phpunit/tests/functions.php | 8 +++---- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index f227c9fdd2f7e..7314b94432092 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -1476,13 +1476,13 @@ private static function get_wp_constants(): array { 'label' => 'WP_PLUGIN_DIR', 'value' => WP_PLUGIN_DIR, ), - 'WP_MEMORY_LIMIT' => array( - 'label' => 'WP_MEMORY_LIMIT', - 'value' => WP_MEMORY_LIMIT, + 'WP_VISITOR_MEMORY_LIMIT' => array( + 'label' => 'WP_VISITOR_MEMORY_LIMIT', + 'value' => WP_VISITOR_MEMORY_LIMIT, ), - 'WP_MAX_MEMORY_LIMIT' => array( - 'label' => 'WP_MAX_MEMORY_LIMIT', - 'value' => WP_MAX_MEMORY_LIMIT, + 'WP_ADMIN_MEMORY_LIMIT' => array( + 'label' => 'WP_ADMIN_MEMORY_LIMIT', + 'value' => WP_ADMIN_MEMORY_LIMIT, ), 'WP_DEBUG' => array( 'label' => 'WP_DEBUG', diff --git a/src/wp-includes/default-constants.php b/src/wp-includes/default-constants.php index acfc878fb7138..7197022c93f0b 100644 --- a/src/wp-includes/default-constants.php +++ b/src/wp-includes/default-constants.php @@ -43,32 +43,32 @@ function wp_initial_constants() { $current_limit_int = wp_convert_hr_to_bytes( $current_limit ); // Define memory limits. - if ( ! defined( 'WP_MEMORY_LIMIT' ) ) { + if ( ! defined( 'WP_VISITOR_MEMORY_LIMIT' ) ) { if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) { - define( 'WP_MEMORY_LIMIT', $current_limit ); + define( 'WP_VISITOR_MEMORY_LIMIT', $current_limit ); } elseif ( is_multisite() ) { - define( 'WP_MEMORY_LIMIT', '64M' ); + define( 'WP_VISITOR_MEMORY_LIMIT', '64M' ); } else { - define( 'WP_MEMORY_LIMIT', '40M' ); + define( 'WP_VISITOR_MEMORY_LIMIT', '40M' ); } } - if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) { + if ( ! defined( 'WP_ADMIN_MEMORY_LIMIT' ) ) { if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) { - define( 'WP_MAX_MEMORY_LIMIT', $current_limit ); + define( 'WP_ADMIN_MEMORY_LIMIT', $current_limit ); } elseif ( -1 === $current_limit_int || $current_limit_int > 256 * MB_IN_BYTES ) { - define( 'WP_MAX_MEMORY_LIMIT', $current_limit ); - } elseif ( wp_convert_hr_to_bytes( WP_MEMORY_LIMIT ) > 256 * MB_IN_BYTES ) { - define( 'WP_MAX_MEMORY_LIMIT', WP_MEMORY_LIMIT ); + define( 'WP_ADMIN_MEMORY_LIMIT', $current_limit ); + } elseif ( wp_convert_hr_to_bytes( WP_VISITOR_MEMORY_LIMIT ) > 256 * MB_IN_BYTES ) { + define( 'WP_ADMIN_MEMORY_LIMIT', WP_VISITOR_MEMORY_LIMIT ); } else { - define( 'WP_MAX_MEMORY_LIMIT', '256M' ); + define( 'WP_ADMIN_MEMORY_LIMIT', '256M' ); } } // Set memory limits. - $wp_limit_int = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT ); + $wp_limit_int = wp_convert_hr_to_bytes( WP_VISITOR_MEMORY_LIMIT ); if ( -1 !== $current_limit_int && ( -1 === $wp_limit_int || $wp_limit_int > $current_limit_int ) ) { - ini_set( 'memory_limit', WP_MEMORY_LIMIT ); + ini_set( 'memory_limit', WP_VISITOR_MEMORY_LIMIT ); } if ( ! isset( $blog_id ) ) { diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 7e46dd53cab2d..ce50b9cabda08 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -7803,7 +7803,7 @@ function wp_raise_memory_limit( $context = 'admin' ) { return false; } - $wp_max_limit = WP_MAX_MEMORY_LIMIT; + $wp_max_limit = WP_ADMIN_MEMORY_LIMIT; $wp_max_limit_int = wp_convert_hr_to_bytes( $wp_max_limit ); $filtered_limit = $wp_max_limit; @@ -7816,7 +7816,7 @@ function wp_raise_memory_limit( $context = 'admin' ) { * 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 + * The `WP_ADMIN_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. @@ -7838,7 +7838,7 @@ function wp_raise_memory_limit( $context = 'admin' ) { * @since 4.6.0 The default now takes the original `memory_limit` into account. * * @param int|string $filtered_limit Maximum memory limit to allocate for image processing. - * Default `WP_MAX_MEMORY_LIMIT` or the original + * Default `WP_ADMIN_MEMORY_LIMIT` or the original * php.ini `memory_limit`, whichever is higher. * Accepts an integer (bytes), or a shorthand string * notation, such as '256M'. @@ -7853,7 +7853,7 @@ function wp_raise_memory_limit( $context = 'admin' ) { * @since 6.3.0 * * @param int|string $filtered_limit Maximum memory limit to allocate for WP-Cron. - * Default `WP_MAX_MEMORY_LIMIT` or the original + * Default `WP_ADMIN_MEMORY_LIMIT` or the original * php.ini `memory_limit`, whichever is higher. * Accepts an integer (bytes), or a shorthand string * notation, such as '256M'. @@ -7872,7 +7872,7 @@ function wp_raise_memory_limit( $context = 'admin' ) { * @since 4.6.0 * * @param int|string $filtered_limit Maximum memory limit to allocate for this context. - * Default WP_MAX_MEMORY_LIMIT` or the original php.ini `memory_limit`, + * Default WP_ADMIN_MEMORY_LIMIT` or the original php.ini `memory_limit`, * whichever is higher. Accepts an integer (bytes), or a * shorthand string notation, such as '256M'. */ diff --git a/src/wp-settings.php b/src/wp-settings.php index 635f6de248dd5..9b5b6adf4d7b0 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -60,7 +60,7 @@ */ global $blog_id; -// Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, SCRIPT_DEBUG, WP_CONTENT_DIR and WP_CACHE. +// Set initial default constants including WP_VISITOR_MEMORY_LIMIT, WP_ADMIN_MEMORY_LIMIT, WP_DEBUG, SCRIPT_DEBUG, WP_CONTENT_DIR and WP_CACHE. wp_initial_constants(); // Register the shutdown handler for fatal errors as soon as possible. diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 5ee8f38b5753f..d304e01233631 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -232,8 +232,8 @@ */ define( 'DISABLE_WP_CRON', true ); -define( 'WP_MEMORY_LIMIT', -1 ); -define( 'WP_MAX_MEMORY_LIMIT', -1 ); +define( 'WP_VISITOR_MEMORY_LIMIT', -1 ); +define( 'WP_ADMIN_MEMORY_LIMIT', -1 ); define( 'REST_TESTS_IMPOSSIBLY_HIGH_NUMBER', 99999999 ); diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index d2775393a6a83..b8305524b8e88 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1158,14 +1158,14 @@ public function test_wp_ext2type() { /** * Tests raising the memory limit. * - * Unfortunately as the default for 'WP_MAX_MEMORY_LIMIT' in the + * Unfortunately as the default for 'WP_ADMIN_MEMORY_LIMIT' in the * test suite is -1, we can not test the memory limit negotiations. * * @ticket 32075 */ public function test_wp_raise_memory_limit() { - if ( -1 !== WP_MAX_MEMORY_LIMIT ) { - $this->markTestSkipped( 'WP_MAX_MEMORY_LIMIT should be set to -1.' ); + if ( -1 !== WP_ADMIN_MEMORY_LIMIT ) { + $this->markTestSkipped( 'WP_ADMIN_MEMORY_LIMIT should be set to -1.' ); } $ini_limit_before = ini_get( 'memory_limit' ); @@ -1174,7 +1174,7 @@ public function test_wp_raise_memory_limit() { $this->assertSame( $ini_limit_before, $ini_limit_after ); $this->assertFalse( $raised_limit ); - $this->assertEquals( WP_MAX_MEMORY_LIMIT, $ini_limit_after ); + $this->assertEquals( WP_ADMIN_MEMORY_LIMIT, $ini_limit_after ); } /**