From 80f4e83a8cbbfe5de286b98b736dcd24a6e0af8c Mon Sep 17 00:00:00 2001 From: westi Date: Thu, 28 Apr 2011 16:25:36 +0000 Subject: [PATCH] Introduce WP_MAX_MEMORY_LIMIT constant for the high memory limit we set when image processing and unzipping. Ensure it is always filterable by plugins as well as configurable in wp-config Fixes #13847 props hakre git-svn-id: http://svn.automattic.com/wordpress/trunk@17749 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin.php | 2 +- wp-admin/includes/file.php | 2 +- wp-admin/includes/image-edit.php | 4 ++-- wp-includes/default-constants.php | 4 ++++ wp-includes/media.php | 2 +- wp-settings.php | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wp-admin/admin.php b/wp-admin/admin.php index fcc84bab56..ce1227d7d3 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -106,7 +106,7 @@ else require(ABSPATH . 'wp-admin/menu.php'); if ( current_user_can( 'manage_options' ) ) - @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) ); + @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); do_action('admin_init'); diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 607bc76b91..f77cc6493d 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -518,7 +518,7 @@ function unzip_file($file, $to) { return new WP_Error('fs_unavailable', __('Could not access filesystem.')); // Unzip can use a lot of memory, but not this much hopefully - @ini_set('memory_limit', '256M'); + @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); $needed_dirs = array(); $to = trailingslashit($to); diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 1ab67e5937..86cdfe20a9 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -391,7 +391,7 @@ function image_edit_apply_changes($img, $changes) { function stream_preview_image($post_id) { $post = get_post($post_id); - @ini_set('memory_limit', '256M'); + @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); $img = load_image_to_edit( $post_id, $post->post_mime_type, array(400, 400) ); if ( !is_resource($img) ) @@ -496,7 +496,7 @@ function wp_save_image($post_id) { $return = new stdClass; $success = $delete = $scaled = $nocrop = false; $post = get_post($post_id); - @ini_set('memory_limit', '256M'); + @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); $img = load_image_to_edit($post_id, $post->post_mime_type); if ( !is_resource($img) ) { diff --git a/wp-includes/default-constants.php b/wp-includes/default-constants.php index ba9b2dcc93..c61076ed8a 100644 --- a/wp-includes/default-constants.php +++ b/wp-includes/default-constants.php @@ -24,6 +24,10 @@ function wp_initial_constants( ) { } } + if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) { + define( 'WP_MAX_MEMORY_LIMIT', '256M' ); + } + /** * The $blog_id global, which you can change in the config allows you to create a simple * multiple blog installation using just one WordPress and changing $blog_id around. diff --git a/wp-includes/media.php b/wp-includes/media.php index 856f46bd4e..9418a50c4a 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -250,7 +250,7 @@ function wp_load_image( $file ) { return __('The GD image library is not installed.'); // Set artificially high because GD uses uncompressed images in memory - @ini_set('memory_limit', '256M'); + @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) ); $image = imagecreatefromstring( file_get_contents( $file ) ); if ( !is_resource( $image ) ) diff --git a/wp-settings.php b/wp-settings.php index 9e053c9e50..e24cc7d02e 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -20,7 +20,7 @@ require( ABSPATH . WPINC . '/load.php' ); require( ABSPATH . WPINC . '/default-constants.php' ); require( ABSPATH . WPINC . '/version.php' ); -// Set initial default constants including WP_MEMORY_LIMIT, WP_DEBUG, WP_CONTENT_DIR and WP_CACHE. +// Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, WP_CONTENT_DIR and WP_CACHE. wp_initial_constants( ); // Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php.