WordPress.org

Make WordPress Core

Ticket #32075: 32075.diff

File 32075.diff, 6.7 KB (added by A5hleyRich, 6 years ago)
  • src/wp-admin/admin.php

    diff --git src/wp-admin/admin.php src/wp-admin/admin.php
    index 184d5c2..8dd251f 100644
    else 
    138138        require(ABSPATH . 'wp-admin/menu.php');
    139139
    140140if ( current_user_can( 'manage_options' ) ) {
    141         /**
    142          * Filter the maximum memory limit available for administration screens.
    143          *
    144          * This only applies to administrators, who may require more memory for tasks like updates.
    145          * Memory limits when processing images (uploaded or edited by users of any role) are
    146          * handled separately.
    147          *
    148          * The WP_MAX_MEMORY_LIMIT constant specifically defines the maximum memory limit available
    149          * when in the administration back-end. The default is 256M, or 256 megabytes of memory.
    150          *
    151          * @since 3.0.0
    152          *
    153          * @param string 'WP_MAX_MEMORY_LIMIT' The maximum WordPress memory limit. Default 256M.
    154          */
    155         @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     141        wp_raise_memory_limit( 'admin_memory_limit' );
    156142}
    157143
    158144/**
  • src/wp-admin/includes/file.php

    diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
    index 3b4d1c6..036c039 100644
    function unzip_file($file, $to) { 
    546546                return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    547547
    548548        // Unzip can use a lot of memory, but not this much hopefully
    549         /** This filter is documented in wp-admin/admin.php */
    550         @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     549        wp_raise_memory_limit( 'admin_memory_limit' );
    551550
    552551        $needed_dirs = array();
    553552        $to = trailingslashit($to);
  • src/wp-admin/includes/image-edit.php

    diff --git src/wp-admin/includes/image-edit.php src/wp-admin/includes/image-edit.php
    index 4015f30..38fa83e 100644
    function image_edit_apply_changes( $image, $changes ) { 
    557557function stream_preview_image( $post_id ) {
    558558        $post = get_post( $post_id );
    559559
    560         /** This filter is documented in wp-admin/admin.php */
    561         @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     560        wp_raise_memory_limit( 'admin_memory_limit' );
    562561
    563562        $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
    564563
  • src/wp-includes/class-wp-image-editor-gd.php

    diff --git src/wp-includes/class-wp-image-editor-gd.php src/wp-includes/class-wp-image-editor-gd.php
    index 2093c6b..81fcd90 100644
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    9696                if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) )
    9797                        return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file );
    9898
    99                 /**
    100                  * Filter the memory limit allocated for image manipulation.
    101                  *
    102                  * @since 3.5.0
    103                  *
    104                  * @param int|string $limit Maximum memory limit to allocate for images. Default WP_MAX_MEMORY_LIMIT.
    105                  *                          Accepts an integer (bytes), or a shorthand string notation, such as '256M'.
    106                  */
    107                 // Set artificially high because GD uses uncompressed images in memory
    108                 @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     99                wp_raise_memory_limit( 'image_memory_limit' );
    109100
    110101                $this->image = @imagecreatefromstring( file_get_contents( $this->file ) );
    111102
  • src/wp-includes/class-wp-image-editor-imagick.php

    diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php
    index a14fa40..27117d9 100644
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    129129                if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) )
    130130                        return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file );
    131131
    132                 /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */
    133132                // Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits
    134                 @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     133                wp_raise_memory_limit( 'image_memory_limit' );
    135134
    136135                try {
    137136                        $this->image = new Imagick( $this->file );
  • src/wp-includes/default-constants.php

    diff --git src/wp-includes/default-constants.php src/wp-includes/default-constants.php
    index c9092bd..df004ec 100644
    function wp_initial_constants() { 
    2626                }
    2727        }
    2828
     29        $current_limit     = @ini_get( 'memory_limit' );
     30        $current_limit_int = intval( $current_limit );
     31
    2932        if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
    30                 define( 'WP_MAX_MEMORY_LIMIT', '256M' );
     33                if ( -1 === $current_limit_int || $current_limit_int > 256 ) {
     34                        define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
     35                } else {
     36                        define( 'WP_MAX_MEMORY_LIMIT', '256M' );
     37                }
    3138        }
    3239
    3340        if ( ! isset($blog_id) )
    function wp_initial_constants() { 
    3542
    3643        // set memory limits.
    3744        if ( function_exists( 'memory_get_usage' ) ) {
    38                 $current_limit = @ini_get( 'memory_limit' );
    39                 $current_limit_int = intval( $current_limit );
    4045                if ( false !== strpos( $current_limit, 'G' ) )
    4146                        $current_limit_int *= 1024;
    4247                $wp_limit_int = intval( WP_MEMORY_LIMIT );
  • src/wp-includes/deprecated.php

    diff --git src/wp-includes/deprecated.php src/wp-includes/deprecated.php
    index 91a1543..b50094b 100644
    function wp_load_image( $file ) { 
    31343134                return __('The GD image library is not installed.');
    31353135
    31363136        // Set artificially high because GD uses uncompressed images in memory
    3137         @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     3137        wp_raise_memory_limit( 'image_memory_limit' );
    31383138        $image = imagecreatefromstring( file_get_contents( $file ) );
    31393139
    31403140        if ( !is_resource( $image ) )
  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index e3fb353..5d02471 100644
    function mysql_to_rfc3339( $date_string ) { 
    51665166        // Strip timezone information
    51675167        return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
    51685168}
     5169
     5170/**
     5171 * WP raise memory limit
     5172 *
     5173 * Raises the default memory limit for memory intensive processes.
     5174 * Only allow filter to raise and not lower the limit.
     5175 *
     5176 * @param string $filter Filter name
     5177 */
     5178function wp_raise_memory_limit( $filter ) {
     5179        $current_limit     = WP_MAX_MEMORY_LIMIT;
     5180        $current_limit_int = intval( $current_limit );
     5181        $new_limit         = apply_filters( $filter, $current_limit );
     5182        $new_limit_int     = intval( $new_limit );
     5183
     5184        if ( -1 === $new_limit_int || $new_limit_int > $current_limit_int ) {
     5185                @ini_set( 'memory_limit', $new_limit );
     5186        } else {
     5187                @ini_set( 'memory_limit', $current_limit );
     5188        }
     5189}