Ticket #22356: 22356.5.2.diff

File 22356.5.2.diff, 32.2 KB (added by scribu, 6 months ago)

re-order the static methods, to be closer together

  • wp-admin/includes/media.php

    diff --git wp-admin/includes/media.php wp-admin/includes/media.php
    index 6cc1b63..185b096 100644
    function get_media_item( $attachment_id, $args = null ) { 
    11221122        $media_dims = apply_filters( 'media_meta', $media_dims, $post ); 
    11231123 
    11241124        $image_edit_button = ''; 
    1125         if ( gd_edit_image_support( $post->post_mime_type ) ) { 
     1125        if ( WP_Image_Editor::supports( array( 'mime_type' => $post->post_mime_type ) ) ) { 
    11261126                $nonce = wp_create_nonce( "image_editor-$post->ID" ); 
    11271127                $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; 
    11281128        } 
    function edit_form_image_editor() { 
    22542254        $att_url = wp_get_attachment_url( $post->ID ); 
    22552255 
    22562256        $image_edit_button = ''; 
    2257         if ( gd_edit_image_support( $post->post_mime_type ) ) { 
     2257        if ( WP_Image_Editor::supports( array( 'mime_type' => $post->post_mime_type ) ) ) { 
    22582258                $nonce = wp_create_nonce( "image_editor-$post->ID" ); 
    22592259                $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; 
    22602260        } 
  • new file wp-includes/class-wp-image-editor-base.php

    diff --git wp-includes/class-wp-image-editor-base.php wp-includes/class-wp-image-editor-base.php
    new file mode 100644
    index 0000000..b2219a8
    - +  
     1<?php 
     2/** 
     3 * Base image editor class from which implementations extend 
     4 * 
     5 * @since 3.5.0 
     6 */ 
     7abstract class WP_Image_Editor_Base { 
     8 
     9        protected $file = null; 
     10        protected $size = null; 
     11        protected $mime_type = null; 
     12        protected $default_mime_type = 'image/jpeg'; 
     13        protected $quality = 90; 
     14 
     15        /** 
     16         * Checks to see if current environment supports the editor chosen. 
     17         * Must be overridden in a sub-class. 
     18         * 
     19         * @since 3.5.0 
     20         * @access public 
     21         * @abstract 
     22         * 
     23         * @param array $args 
     24         * @return boolean 
     25         */ 
     26        public static function test() { 
     27                return false; 
     28        } 
     29 
     30        /** 
     31         * Checks to see if editor supports the mime-type specified. 
     32         * Must be overridden in a sub-class. 
     33         * 
     34         * @since 3.5.0 
     35         * @access public 
     36         * @abstract 
     37         * 
     38         * @param string $mime_type 
     39         * @return boolean 
     40         */ 
     41        public static function supports_mime_type( $mime_type ) { 
     42                return false; 
     43        } 
     44 
     45        /** 
     46         * Each instance handles a single file. 
     47         */ 
     48        public function __construct( $file ) { 
     49                $this->file = $file; 
     50        } 
     51 
     52        /** 
     53         * Loads image from $this->file into editor. 
     54         * 
     55         * @since 3.5.0 
     56         * @access protected 
     57         * @abstract 
     58         * 
     59         * @return boolean|WP_Error True if loaded; WP_Error on failure. 
     60         */ 
     61        abstract public function load(); 
     62 
     63        /** 
     64         * Saves current image to file. 
     65         * 
     66         * @since 3.5.0 
     67         * @access public 
     68         * @abstract 
     69         * 
     70         * @param string $destfilename 
     71         * @param string $mime_type 
     72         * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} 
     73         */ 
     74        abstract public function save( $destfilename = null, $mime_type = null ); 
     75 
     76        /** 
     77         * Resizes current image. 
     78         * 
     79         * @since 3.5.0 
     80         * @access public 
     81         * @abstract 
     82         * 
     83         * @param int $max_w 
     84         * @param int $max_h 
     85         * @param boolean $crop 
     86         * @return boolean|WP_Error 
     87         */ 
     88        abstract public function resize( $max_w, $max_h, $crop = false ); 
     89 
     90        /** 
     91         * Processes current image and saves to disk 
     92         * multiple sizes from single source. 
     93         * 
     94         * @since 3.5.0 
     95         * @access public 
     96         * @abstract 
     97         * 
     98         * @param array $sizes 
     99         * @return array 
     100         */ 
     101        abstract public function multi_resize( $sizes ); 
     102 
     103        /** 
     104         * Crops Image. 
     105         * 
     106         * @since 3.5.0 
     107         * @access public 
     108         * @abstract 
     109         * 
     110         * @param string|int $src The source file or Attachment ID. 
     111         * @param int $src_x The start x position to crop from. 
     112         * @param int $src_y The start y position to crop from. 
     113         * @param int $src_w The width to crop. 
     114         * @param int $src_h The height to crop. 
     115         * @param int $dst_w Optional. The destination width. 
     116         * @param int $dst_h Optional. The destination height. 
     117         * @param boolean $src_abs Optional. If the source crop points are absolute. 
     118         * @return boolean|WP_Error 
     119         */ 
     120        abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ); 
     121 
     122        /** 
     123         * Rotates current image counter-clockwise by $angle. 
     124         * 
     125         * @since 3.5.0 
     126         * @access public 
     127         * @abstract 
     128         * 
     129         * @param float $angle 
     130         * @return boolean|WP_Error 
     131         */ 
     132        abstract public function rotate( $angle ); 
     133 
     134        /** 
     135         * Flips current image. 
     136         * 
     137         * @since 3.5.0 
     138         * @access public 
     139         * @abstract 
     140         * 
     141         * @param boolean $horz Horizontal Flip 
     142         * @param boolean $vert Vertical Flip 
     143         * @return boolean|WP_Error 
     144         */ 
     145        abstract public function flip( $horz, $vert ); 
     146 
     147        /** 
     148         * Streams current image to browser. 
     149         * 
     150         * @since 3.5.0 
     151         * @access public 
     152         * @abstract 
     153         * 
     154         * @param string $mime_type 
     155         * @return boolean|WP_Error 
     156         */ 
     157        abstract public function stream( $mime_type = null ); 
     158 
     159        /** 
     160         * Gets dimensions of image. 
     161         * 
     162         * @since 3.5.0 
     163         * @access public 
     164         * 
     165         * @return array {'width'=>int, 'height'=>int} 
     166         */ 
     167        public function get_size() { 
     168                return $this->size; 
     169        } 
     170 
     171        /** 
     172         * Sets current image size. 
     173         * 
     174         * @since 3.5.0 
     175         * @access protected 
     176         * 
     177         * @param int $width 
     178         * @param int $height 
     179         */ 
     180        protected function update_size( $width = null, $height = null ) { 
     181                $this->size = array( 
     182                        'width' => $width, 
     183                        'height' => $height 
     184                ); 
     185                return true; 
     186        } 
     187 
     188        /** 
     189         * Sets Image Compression quality on a 1-100% scale. 
     190         * 
     191         * @since 3.5.0 
     192         * @access public 
     193         * 
     194         * @param int $quality Compression Quality. Range: [1,100] 
     195         * @return boolean 
     196         */ 
     197        public function set_quality( $quality ) { 
     198                $this->quality = apply_filters( 'wp_editor_set_quality', $quality ); 
     199 
     200                return ( (bool) $this->quality ); 
     201        } 
     202 
     203        /** 
     204         * Returns preferred mime-type and extension based on provided 
     205         * file's extension and mime, or current file's extension and mime. 
     206         * 
     207         * Will default to $this->default_mime_type if requested is not supported. 
     208         * 
     209         * Provides corrected filename only if filename is provided. 
     210         * 
     211         * @since 3.5.0 
     212         * @access protected 
     213         * 
     214         * @param string $filename 
     215         * @param string $mime_type 
     216         * @return array { filename|null, extension, mime-type } 
     217         */ 
     218        protected function get_output_format( $filename = null, $mime_type = null ) { 
     219                $new_ext = $file_ext = null; 
     220                $file_mime = null; 
     221 
     222                // By default, assume specified type takes priority 
     223                if ( $mime_type ) { 
     224                        $new_ext = $this->get_extension( $mime_type ); 
     225                } 
     226 
     227                if ( $filename ) { 
     228                        $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); 
     229                        $file_mime = $this->get_mime_type( $file_ext ); 
     230                } 
     231                else { 
     232                        // If no file specified, grab editor's current extension and mime-type. 
     233                        $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); 
     234                        $file_mime = $this->mime_type; 
     235                } 
     236 
     237                // Check to see if specified mime-type is the same as type implied by 
     238                // file extension.  If so, prefer extension from file. 
     239                if ( ! $mime_type || ( $file_mime == $mime_type ) ) { 
     240                        $mime_type = $file_mime; 
     241                        $new_ext = $file_ext; 
     242                } 
     243 
     244                // Double-check that the mime-type selected is supported by the editor. 
     245                // If not, choose a default instead. 
     246                if ( ! $this->supports_mime_type( $mime_type ) ) { 
     247                        $mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type ); 
     248                        $new_ext = $this->get_extension( $mime_type ); 
     249                } 
     250 
     251                if ( $filename ) { 
     252                        $ext = ''; 
     253                        $info = pathinfo( $filename ); 
     254                        $dir  = $info['dirname']; 
     255 
     256                        if( isset( $info['extension'] ) ) 
     257                                $ext = $info['extension']; 
     258 
     259                        $filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}"; 
     260                } 
     261 
     262                return array( $filename, $new_ext, $mime_type ); 
     263        } 
     264 
     265        /** 
     266         * Builds an output filename based on current file, and adding proper suffix 
     267         * 
     268         * @since 3.5.0 
     269         * @access public 
     270         * 
     271         * @param string $suffix 
     272         * @param string $dest_path 
     273         * @param string $extension 
     274         * @return string filename 
     275         */ 
     276        public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 
     277                // $suffix will be appended to the destination filename, just before the extension 
     278                if ( ! $suffix ) 
     279                        $suffix = $this->get_suffix(); 
     280 
     281                $info = pathinfo( $this->file ); 
     282                $dir  = $info['dirname']; 
     283                $ext  = $info['extension']; 
     284 
     285                $name = wp_basename( $this->file, ".$ext" ); 
     286                $new_ext = strtolower( $extension ? $extension : $ext ); 
     287 
     288                if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) 
     289                        $dir = $_dest_path; 
     290 
     291                return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; 
     292        } 
     293 
     294        /** 
     295         * Builds and returns proper suffix for file based on height and width. 
     296         * 
     297         * @since 3.5.0 
     298         * @access public 
     299         * 
     300         * @return string suffix 
     301         */ 
     302        public function get_suffix() { 
     303                if ( ! $this->get_size() ) 
     304                        return false; 
     305 
     306                return "{$this->size['width']}x{$this->size['height']}"; 
     307        } 
     308 
     309        /** 
     310         * Either calls editor's save function or handles file as a stream. 
     311         * 
     312         * @since 3.5.0 
     313         * @access protected 
     314         * 
     315         * @param string|stream $filename 
     316         * @param callable $function 
     317         * @param array $arguments 
     318         * @return boolean 
     319         */ 
     320        protected function make_image( $filename, $function, $arguments ) { 
     321                $dst_file = $filename; 
     322 
     323                if ( $stream = wp_is_stream( $filename ) ) { 
     324                        $filename = null; 
     325                        ob_start(); 
     326                } 
     327 
     328                $result = call_user_func_array( $function, $arguments ); 
     329 
     330                if ( $result && $stream ) { 
     331                        $contents = ob_get_contents(); 
     332 
     333                        $fp = fopen( $dst_file, 'w' ); 
     334 
     335                        if ( ! $fp ) 
     336                                return false; 
     337 
     338                        fwrite( $fp, $contents ); 
     339                        fclose( $fp ); 
     340                } 
     341 
     342                if ( $stream ) { 
     343                        ob_end_clean(); 
     344                } 
     345 
     346                return $result; 
     347        } 
     348 
     349        /** 
     350         * Returns first matched mime-type from extension, 
     351         * as mapped from wp_get_mime_types() 
     352         * 
     353         * @since 3.5.0 
     354         * @access protected 
     355         * 
     356         * @param string $extension 
     357         * @return string|boolean 
     358         */ 
     359        protected static function get_mime_type( $extension = null ) { 
     360                if ( ! $extension ) 
     361                        return false; 
     362 
     363                $mime_types = wp_get_mime_types(); 
     364                $extensions = array_keys( $mime_types ); 
     365 
     366                foreach( $extensions as $_extension ) { 
     367                        if ( preg_match( "/{$extension}/i", $_extension ) ) { 
     368                                return $mime_types[$_extension]; 
     369                        } 
     370                } 
     371 
     372                return false; 
     373        } 
     374 
     375        /** 
     376         * Returns first matched extension from Mime-type, 
     377         * as mapped from wp_get_mime_types() 
     378         * 
     379         * @since 3.5.0 
     380         * @access protected 
     381         * 
     382         * @param string $mime_type 
     383         * @return string|boolean 
     384         */ 
     385        protected static function get_extension( $mime_type = null ) { 
     386                $extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) ); 
     387 
     388                if ( empty( $extensions[0] ) ) 
     389                        return false; 
     390 
     391                return $extensions[0]; 
     392        } 
     393} 
     394 
  • wp-includes/class-wp-image-editor-gd.php

    diff --git wp-includes/class-wp-image-editor-gd.php wp-includes/class-wp-image-editor-gd.php
    index ca76006..411e18f 100644
     
    1414 * @subpackage Image_Editor 
    1515 * @uses WP_Image_Editor Extends class 
    1616 */ 
    17 class WP_Image_Editor_GD extends WP_Image_Editor { 
     17class WP_Image_Editor_GD extends WP_Image_Editor_Base { 
     18 
    1819        protected $image = false; // GD Resource 
    1920 
    2021        function __destruct() { 
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    3233         * 
    3334         * @return boolean 
    3435         */ 
    35         public static function test( $args = null ) { 
     36        public static function test() { 
    3637                if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) 
    3738                        return false; 
    3839 
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    4041        } 
    4142 
    4243        /** 
     44         * Checks to see if editor supports the mime-type specified. 
     45         * 
     46         * @since 3.5.0 
     47         * @access public 
     48         * 
     49         * @param string $mime_type 
     50         * @return boolean 
     51         */ 
     52        public static function supports_mime_type( $mime_type ) { 
     53                $image_types = imagetypes(); 
     54                switch( $mime_type ) { 
     55                        case 'image/jpeg': 
     56                                return ($image_types & IMG_JPG) != 0; 
     57                        case 'image/png': 
     58                                return ($image_types & IMG_PNG) != 0; 
     59                        case 'image/gif': 
     60                                return ($image_types & IMG_GIF) != 0; 
     61                } 
     62 
     63                return false; 
     64        } 
     65 
     66        /** 
    4367         * Loads image from $this->file into new GD Resource. 
    4468         * 
    4569         * @since 3.5.0 
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    4771         * 
    4872         * @return boolean|\WP_Error 
    4973         */ 
    50         protected function load() { 
     74        public function load() { 
    5175                if ( $this->image ) 
    5276                        return true; 
    5377 
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    91115        } 
    92116 
    93117        /** 
    94          * Checks to see if editor supports the mime-type specified. 
    95          * 
    96          * @since 3.5.0 
    97          * @access public 
    98          * 
    99          * @param string $mime_type 
    100          * @return boolean 
    101          */ 
    102         public static function supports_mime_type( $mime_type ) { 
    103                 $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' ); 
    104  
    105                 return in_array( $mime_type, $allowed_mime_types ); 
    106         } 
    107  
    108         /** 
    109118         * Resizes current image. 
    110119         * Wraps _resize, since _resize returns a GD Resource. 
    111120         * 
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    261270         * @since 3.5.0 
    262271         * @access public 
    263272         * 
    264          * @param boolean $horz Horizonal Flip 
     273         * @param boolean $horz Horizontal Flip 
    265274         * @param boolean $vert Vertical Flip 
    266275         * @returns boolean|WP_Error 
    267276         */ 
    class WP_Image_Editor_GD extends WP_Image_Editor { 
    369378                                return imagejpeg( $this->image, null, $this->quality ); 
    370379                } 
    371380        } 
    372 } 
    373  No newline at end of file 
     381} 
  • wp-includes/class-wp-image-editor-imagick.php

    diff --git wp-includes/class-wp-image-editor-imagick.php wp-includes/class-wp-image-editor-imagick.php
    index 601b99b..5fccaee 100644
     
    1414 * @subpackage Image_Editor 
    1515 * @uses WP_Image_Editor Extends class 
    1616 */ 
    17 class WP_Image_Editor_Imagick extends WP_Image_Editor { 
     17class WP_Image_Editor_Imagick extends WP_Image_Editor_Base { 
     18 
    1819        protected $image = null; // Imagick Object 
    1920 
    2021        function __destruct() { 
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    3637         * 
    3738         * @return boolean 
    3839         */ 
    39         public static function test( $args = null ) { 
     40        public static function test() { 
    4041                if ( ! extension_loaded( 'imagick' ) || ! is_callable( 'Imagick', 'queryFormats' ) ) 
    4142                        return false; 
    4243 
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    4445        } 
    4546 
    4647        /** 
     48         * Checks to see if editor supports the mime-type specified. 
     49         * 
     50         * @since 3.5.0 
     51         * @access public 
     52         * 
     53         * @param string $mime_type 
     54         * @return boolean 
     55         */ 
     56        public static function supports_mime_type( $mime_type ) { 
     57                $imagick_extension = strtoupper( self::get_extension( $mime_type ) ); 
     58 
     59                if ( ! $imagick_extension ) 
     60                        return false; 
     61 
     62                try { 
     63                        return ( (bool) Imagick::queryFormats( $imagick_extension ) ); 
     64                } 
     65                catch ( Exception $e ) { 
     66                        return false; 
     67                } 
     68        } 
     69 
     70        /** 
    4771         * Loads image from $this->file into new Imagick Object. 
    4872         * 
    4973         * @since 3.5.0 
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    5175         * 
    5276         * @return boolean|WP_Error True if loaded; WP_Error on failure. 
    5377         */ 
    54         protected function load() { 
     78        public function load() { 
    5579                if ( $this->image ) 
    5680                        return true; 
    5781 
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    138162        } 
    139163 
    140164        /** 
    141          * Checks to see if editor supports the mime-type specified. 
    142          * 
    143          * @since 3.5.0 
    144          * @access public 
    145          * 
    146          * @param string $mime_type 
    147          * @return boolean 
    148          */ 
    149         public static function supports_mime_type( $mime_type ) { 
    150                 if ( ! $mime_type ) 
    151                         return false; 
    152  
    153                 $imagick_extension = strtoupper( self::get_extension( $mime_type ) ); 
    154  
    155                 try { 
    156                         return ( (bool) Imagick::queryFormats( $imagick_extension ) ); 
    157                 } 
    158                 catch ( Exception $e ) { 
    159                         return false; 
    160                 } 
    161         } 
    162  
    163         /** 
    164165         * Resizes current image. 
    165166         * 
    166167         * @since 3.5.0 
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    312313         * @since 3.5.0 
    313314         * @access public 
    314315         * 
    315          * @param boolean $horz Horizonal Flip 
     316         * @param boolean $horz Horizontal Flip 
    316317         * @param boolean $vert Vertical Flip 
    317318         * @returns boolean|WP_Error 
    318319         */ 
  • wp-includes/class-wp-image-editor.php

    diff --git wp-includes/class-wp-image-editor.php wp-includes/class-wp-image-editor.php
    index 920e4a4..391c8e1 100644
     
    11<?php 
    22/** 
    3  * Base WordPress Image Editor 
    4  * 
    5  * @package WordPress 
    6  * @subpackage Image_Editor 
    7  */ 
    8  
    9 /** 
    10  * Base WordPress Image Editor class for which Editor implementations extend 
     3 * Class for choosing image editor implementations 
    114 * 
    125 * @since 3.5.0 
    136 */ 
    14 abstract class WP_Image_Editor { 
    15         protected $file = null; 
    16         protected $size = null; 
    17         protected $mime_type  = null; 
    18         protected $default_mime_type = 'image/jpeg'; 
    19         protected $quality = 90; 
    20  
    21         protected function __construct( $filename ) { 
    22                 $this->file = $filename; 
    23         } 
     7class WP_Image_Editor { 
    248 
    259        /** 
    2610         * Returns a WP_Image_Editor instance and loads file into it. 
    abstract class WP_Image_Editor { 
    2812         * @since 3.5.0 
    2913         * @access public 
    3014         * 
    31          * @param string $path Path to File to Load 
    32          * @param array $required_methods Methods to require in implementation 
     15         * @param string $path Path to file to load 
     16         * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } 
    3317         * @return WP_Image_Editor|WP_Error 
    3418         */ 
    35         public final static function get_instance( $path = null, $required_methods = null ) { 
    36                 $implementation = apply_filters( 'wp_image_editor_class', self::choose_implementation( $required_methods ), $path ); 
     19        public final static function get_instance( $path, $args = array() ) { 
     20                if ( ! isset( $args['mime_type'] ) ) { 
     21                        $file_info  = wp_check_filetype( $path ); 
     22 
     23                        // If $file_info['type'] is false, then we let the editor attempt to 
     24                        // figure out the file type, rather than forcing a failure based on extension. 
     25                        if ( isset( $file_info ) && $file_info['type'] ) 
     26                                $args['mime_type'] = $file_info['type']; 
     27                } 
     28 
     29                $implementation = apply_filters( 'wp_image_editor_class', self::choose_implementation( $args ) ); 
    3730 
    3831                if ( $implementation ) { 
    3932                        $editor = new $implementation( $path ); 
    abstract class WP_Image_Editor { 
    4538                        return $editor; 
    4639                } 
    4740 
    48                 return new WP_Error( 'no_editor', __('No editor could be selected') ); 
    49         } 
    50  
    51         /** 
    52          * Tests which editors are capable of supporting the request. 
    53          * 
    54          * @since 3.5.0 
    55          * @access private 
    56          * 
    57          * @param array $required_methods String array of all methods required for implementation returned. 
    58          * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. 
    59          */ 
    60         private final static function choose_implementation( $required_methods = null ) { 
    61                 $request_order = apply_filters( 'wp_image_editors', 
    62                         array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); 
    63  
    64                 if ( ! $required_methods ) 
    65                         $required_methods = array(); 
    66  
    67                 // Loop over each editor on each request looking for one which will serve this request's needs 
    68                 foreach ( $request_order as $editor ) { 
    69                         // Check to see if this editor is a possibility, calls the editor statically 
    70                         if ( ! call_user_func( array( $editor, 'test' ) ) ) 
    71                                 continue; 
    72  
    73                         // Make sure that all methods are supported by editor. 
    74                         if ( array_diff( $required_methods, get_class_methods( $editor ) ) ) 
    75                                 continue; 
    76  
    77                         return $editor; 
    78                 } 
    79                 return false; 
    80         } 
    81  
    82         /** 
    83          * Loads image from $this->file into editor. 
    84          * 
    85          * @since 3.5.0 
    86          * @access protected 
    87          * @abstract 
    88          * 
    89          * @return boolean|WP_Error True if loaded; WP_Error on failure. 
    90          */ 
    91         abstract protected function load(); 
    92  
    93         /** 
    94          * Saves current image to file. 
    95          * 
    96          * @since 3.5.0 
    97          * @access public 
    98          * @abstract 
    99          * 
    100          * @param string $destfilename 
    101          * @param string $mime_type 
    102          * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} 
    103          */ 
    104         abstract public function save( $destfilename = null, $mime_type = null ); 
    105  
    106         /** 
    107          * Resizes current image. 
    108          * 
    109          * @since 3.5.0 
    110          * @access public 
    111          * @abstract 
    112          * 
    113          * @param int $max_w 
    114          * @param int $max_h 
    115          * @param boolean $crop 
    116          * @return boolean|WP_Error 
    117          */ 
    118         abstract public function resize( $max_w, $max_h, $crop = false ); 
    119  
    120         /** 
    121          * Processes current image and saves to disk 
    122          * multiple sizes from single source. 
    123          * 
    124          * @since 3.5.0 
    125          * @access public 
    126          * @abstract 
    127          * 
    128          * @param array $sizes 
    129          * @return array 
    130          */ 
    131         abstract public function multi_resize( $sizes ); 
    132  
    133         /** 
    134          * Crops Image. 
    135          * 
    136          * @since 3.5.0 
    137          * @access public 
    138          * @abstract 
    139          * 
    140          * @param string|int $src The source file or Attachment ID. 
    141          * @param int $src_x The start x position to crop from. 
    142          * @param int $src_y The start y position to crop from. 
    143          * @param int $src_w The width to crop. 
    144          * @param int $src_h The height to crop. 
    145          * @param int $dst_w Optional. The destination width. 
    146          * @param int $dst_h Optional. The destination height. 
    147          * @param boolean $src_abs Optional. If the source crop points are absolute. 
    148          * @return boolean|WP_Error 
    149          */ 
    150         abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ); 
    151  
    152         /** 
    153          * Rotates current image counter-clockwise by $angle. 
    154          * 
    155          * @since 3.5.0 
    156          * @access public 
    157          * @abstract 
    158          * 
    159          * @param float $angle 
    160          * @return boolean|WP_Error 
    161          */ 
    162         abstract public function rotate( $angle ); 
    163  
    164         /** 
    165          * Flips current image. 
    166          * 
    167          * @since 3.5.0 
    168          * @access public 
    169          * @abstract 
    170          * 
    171          * @param boolean $horz Horizonal Flip 
    172          * @param boolean $vert Vertical Flip 
    173          * @return boolean|WP_Error 
    174          */ 
    175         abstract public function flip( $horz, $vert ); 
    176  
    177         /** 
    178          * Streams current image to browser. 
    179          * 
    180          * @since 3.5.0 
    181          * @access public 
    182          * @abstract 
    183          * 
    184          * @param string $mime_type 
    185          * @return boolean|WP_Error 
    186          */ 
    187         abstract public function stream( $mime_type = null ); 
    188  
    189         /** 
    190          * Checks to see if current environment supports the editor chosen. 
    191          * Must be overridden in a sub-class. 
    192          * 
    193          * @since 3.5.0 
    194          * @access public 
    195          * @abstract 
    196          * 
    197          * @param array $args 
    198          * @return boolean 
    199          */ 
    200         public static function test( $args = null ) { 
    201                 return false; 
    202         } 
    203  
    204         /** 
    205          * Checks to see if editor supports the mime-type specified. 
    206          * Must be overridden in a sub-class. 
    207          * 
    208          * @since 3.5.0 
    209          * @access public 
    210          * @abstract 
    211          * 
    212          * @param string $mime_type 
    213          * @return boolean 
    214          */ 
    215         public static function supports_mime_type( $mime_type ) { 
    216                 return false; 
    217         } 
    218  
    219         /** 
    220          * Gets dimensions of image. 
    221          * 
    222          * @since 3.5.0 
    223          * @access public 
    224          * 
    225          * @return array {'width'=>int, 'height'=>int} 
    226          */ 
    227         public function get_size() { 
    228                 return $this->size; 
    229         } 
    230  
    231         /** 
    232          * Sets current image size. 
    233          * 
    234          * @since 3.5.0 
    235          * @access protected 
    236          * 
    237          * @param int $width 
    238          * @param int $height 
    239          */ 
    240         protected function update_size( $width = null, $height = null ) { 
    241                 $this->size = array( 
    242                         'width' => $width, 
    243                         'height' => $height 
    244                 ); 
    245                 return true; 
    246         } 
    247  
    248         /** 
    249          * Sets Image Compression quality on a 1-100% scale. 
    250          * 
    251          * @since 3.5.0 
    252          * @access public 
    253          * 
    254          * @param int $quality Compression Quality. Range: [1,100] 
    255          * @return boolean 
    256          */ 
    257         public function set_quality( $quality ) { 
    258                 $this->quality = apply_filters( 'wp_editor_set_quality', $quality ); 
    259  
    260                 return ( (bool) $this->quality ); 
    261         } 
    262  
    263         /** 
    264          * Returns preferred mime-type and extension based on provided 
    265          * file's extension and mime, or current file's extension and mime. 
    266          * 
    267          * Will default to $this->default_mime_type if requested is not supported. 
    268          * 
    269          * Provides corrected filename only if filename is provided. 
    270          * 
    271          * @since 3.5.0 
    272          * @access protected 
    273          * 
    274          * @param string $filename 
    275          * @param string $mime_type 
    276          * @return array { filename|null, extension, mime-type } 
    277          */ 
    278         protected function get_output_format( $filename = null, $mime_type = null ) { 
    279                 $new_ext = $file_ext = null; 
    280                 $file_mime = null; 
    281  
    282                 // By default, assume specified type takes priority 
    283                 if ( $mime_type ) { 
    284                         $new_ext = $this->get_extension( $mime_type ); 
    285                 } 
    286  
    287                 if ( $filename ) { 
    288                         $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); 
    289                         $file_mime = $this->get_mime_type( $file_ext ); 
    290                 } 
    291                 else { 
    292                         // If no file specified, grab editor's current extension and mime-type. 
    293                         $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); 
    294                         $file_mime = $this->mime_type; 
    295                 } 
    296  
    297                 // Check to see if specified mime-type is the same as type implied by 
    298                 // file extension.  If so, prefer extension from file. 
    299                 if ( ! $mime_type || ( $file_mime == $mime_type ) ) { 
    300                         $mime_type = $file_mime; 
    301                         $new_ext = $file_ext; 
    302                 } 
    303  
    304                 // Double-check that the mime-type selected is supported by the editor. 
    305                 // If not, choose a default instead. 
    306                 if ( ! $this->supports_mime_type( $mime_type ) ) { 
    307                         $mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type ); 
    308                         $new_ext = $this->get_extension( $mime_type ); 
    309                 } 
    310  
    311                 if ( $filename ) { 
    312                         $ext = ''; 
    313                         $info = pathinfo( $filename ); 
    314                         $dir  = $info['dirname']; 
    315  
    316                         if( isset( $info['extension'] ) ) 
    317                                 $ext = $info['extension']; 
    318  
    319                         $filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}"; 
    320                 } 
    321  
    322                 return array( $filename, $new_ext, $mime_type ); 
     41                return new WP_Error( 'image_no_editor', __('No editor could be selected.') ); 
    32342        } 
    32443 
    32544        /** 
    326          * Builds an output filename based on current file, and adding proper suffix 
     45         * Tests whether there is an editor that supports a given mime type or methods. 
    32746         * 
    32847         * @since 3.5.0 
    32948         * @access public 
    33049         * 
    331          * @param string $suffix 
    332          * @param string $dest_path 
    333          * @param string $extension 
    334          * @return string filename 
     50         * @param string|array $args String path to image to check for support, or array of arguments.  Accepts { 'path'=>string, 'mime_type'=>string, 'methods'=>{string, string, ...} } 
     51         * @return boolean true if an eligible editor is found; false otherwise 
    33552         */ 
    336         public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 
    337                 // $suffix will be appended to the destination filename, just before the extension 
    338                 if ( ! $suffix ) 
    339                         $suffix = $this->get_suffix(); 
    340  
    341                 $info = pathinfo( $this->file ); 
    342                 $dir  = $info['dirname']; 
    343                 $ext  = $info['extension']; 
    344  
    345                 $name = wp_basename( $this->file, ".$ext" ); 
    346                 $new_ext = strtolower( $extension ? $extension : $ext ); 
    347  
    348                 if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) 
    349                         $dir = $_dest_path; 
    350  
    351                 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; 
    352         } 
    353  
    354         /** 
    355          * Builds and returns proper suffix for file based on height and width. 
    356          * 
    357          * @since 3.5.0 
    358          * @access public 
    359          * 
    360          * @return string suffix 
    361          */ 
    362         public function get_suffix() { 
    363                 if ( ! $this->get_size() ) 
    364                         return false; 
    365  
    366                 return "{$this->size['width']}x{$this->size['height']}"; 
     53        public static function supports( $args = array() ) { 
     54                return (bool) self::choose_implementation( $args ); 
    36755        } 
    36856 
    36957        /** 
    370          * Either calls editor's save function or handles file as a stream. 
     58         * Tests which editors are capable of supporting the request. 
    37159         * 
    37260         * @since 3.5.0 
    373          * @access protected 
     61         * @access private 
    37462         * 
    375          * @param string|stream $filename 
    376          * @param callable $function 
    377          * @param array $arguments 
    378          * @return boolean 
     63         * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } 
     64         * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. 
    37965         */ 
    380         protected function make_image( $filename, $function, $arguments ) { 
    381                 $dst_file = $filename; 
    382  
    383                 if ( $stream = wp_is_stream( $filename ) ) { 
    384                         $filename = null; 
    385                         ob_start(); 
    386                 } 
    387  
    388                 $result = call_user_func_array( $function, $arguments ); 
    389  
    390                 if ( $result && $stream ) { 
    391                         $contents = ob_get_contents(); 
    392  
    393                         $fp = fopen( $dst_file, 'w' ); 
    394  
    395                         if ( ! $fp ) 
    396                                 return false; 
    397  
    398                         fwrite( $fp, $contents ); 
    399                         fclose( $fp ); 
    400                 } 
    401  
    402                 if ( $stream ) { 
    403                         ob_end_clean(); 
    404                 } 
    405  
    406                 return $result; 
    407         } 
     66        private static function choose_implementation( $args = array() ) { 
     67                $implementations = apply_filters( 'wp_image_editors', 
     68                        array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); 
    40869 
    409         /** 
    410          * Returns first matched mime-type from extension, 
    411          * as mapped from wp_get_mime_types() 
    412          * 
    413          * @since 3.5.0 
    414          * @access protected 
    415          * 
    416          * @param string $extension 
    417          * @return string|boolean 
    418          */ 
    419         protected static function get_mime_type( $extension = null ) { 
    420                 if ( ! $extension ) 
    421                         return false; 
     70                foreach ( $implementations as $implementation ) { 
     71                        if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) 
     72                                continue; 
    42273 
    423                 $mime_types = wp_get_mime_types(); 
    424                 $extensions = array_keys( $mime_types ); 
     74                        if ( isset( $args['mime_type'] ) && 
     75                                ! call_user_func( 
     76                                        array( $implementation, 'supports_mime_type' ), 
     77                                        $args['mime_type'] ) ) { 
     78                                continue; 
     79                        } 
    42580 
    426                 foreach( $extensions as $_extension ) { 
    427                         if ( preg_match( "/{$extension}/i", $_extension ) ) { 
    428                                 return $mime_types[$_extension]; 
     81                        if ( isset( $args['methods'] ) && 
     82                                 array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { 
     83                                continue; 
    42984                        } 
     85 
     86                        return $implementation; 
    43087                } 
    43188 
    43289                return false; 
    43390        } 
    434  
    435         /** 
    436          * Returns first matched extension from Mime-type, 
    437          * as mapped from wp_get_mime_types() 
    438          * 
    439          * @since 3.5.0 
    440          * @access protected 
    441          * 
    442          * @param string $mime_type 
    443          * @return string|boolean 
    444          */ 
    445         protected static function get_extension( $mime_type = null ) { 
    446                 $extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) ); 
    447  
    448                 if ( empty( $extensions[0] ) ) 
    449                         return false; 
    450  
    451                 return $extensions[0]; 
    452         } 
    45391} 
     92 
  • wp-includes/deprecated.php

    diff --git wp-includes/deprecated.php wp-includes/deprecated.php
    index 9e99614..5b841df 100644
    function user_pass_ok($user_login, $user_pass) { 
    33283328 * @since 2.3.0 
    33293329 * @deprecated 3.5.0 
    33303330 */ 
    3331 function _save_post_hook() {} 
    3332  No newline at end of file 
     3331function _save_post_hook() {} 
     3332 
     3333/** 
     3334 * Check if the installed version of GD supports particular image type 
     3335 * 
     3336 * @since 2.9.0 
     3337 * @deprecated 3.5.0 
     3338 * @see WP_Image_Editor::supports() 
     3339 * 
     3340 * @param string $mime_type 
     3341 * @return bool 
     3342 */ 
     3343function gd_edit_image_support($mime_type) { 
     3344        _deprecated_function( __FUNCTION__, '3.5', 'WP_Image_Editor::supports()' ); 
     3345        if ( function_exists('imagetypes') ) { 
     3346                switch( $mime_type ) { 
     3347                        case 'image/jpeg': 
     3348                                return (imagetypes() & IMG_JPG) != 0; 
     3349                        case 'image/png': 
     3350                                return (imagetypes() & IMG_PNG) != 0; 
     3351                        case 'image/gif': 
     3352                                return (imagetypes() & IMG_GIF) != 0; 
     3353                } 
     3354        } else { 
     3355                switch( $mime_type ) { 
     3356                        case 'image/jpeg': 
     3357                                return function_exists('imagecreatefromjpeg'); 
     3358                        case 'image/png': 
     3359                                return function_exists('imagecreatefrompng'); 
     3360                        case 'image/gif': 
     3361                                return function_exists('imagecreatefromgif'); 
     3362                } 
     3363        } 
     3364        return false; 
     3365} 
     3366 No newline at end of file 
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index d8475f1..cfc7172 100644
    function get_taxonomies_for_attachments( $output = 'names' ) { 
    904904} 
    905905 
    906906/** 
    907  * Check if the installed version of GD supports particular image type 
    908  * 
    909  * @since 2.9.0 
    910  * 
    911  * @param string $mime_type 
    912  * @return bool 
    913  */ 
    914 function gd_edit_image_support($mime_type) { 
    915         if ( function_exists('imagetypes') ) { 
    916                 switch( $mime_type ) { 
    917                         case 'image/jpeg': 
    918                                 return (imagetypes() & IMG_JPG) != 0; 
    919                         case 'image/png': 
    920                                 return (imagetypes() & IMG_PNG) != 0; 
    921                         case 'image/gif': 
    922                                 return (imagetypes() & IMG_GIF) != 0; 
    923                 } 
    924         } else { 
    925                 switch( $mime_type ) { 
    926                         case 'image/jpeg': 
    927                                 return function_exists('imagecreatefromjpeg'); 
    928                         case 'image/png': 
    929                                 return function_exists('imagecreatefrompng'); 
    930                         case 'image/gif': 
    931                                 return function_exists('imagecreatefromgif'); 
    932                 } 
    933         } 
    934         return false; 
    935 } 
    936  
    937 /** 
    938907 * Create new GD image resource with transparency support 
    939908 * @TODO: Deprecate if possible. 
    940909 * 
  • wp-settings.php

    diff --git wp-settings.php wp-settings.php
    index ac331c2..bb15067 100644
    require( ABSPATH . WPINC . '/nav-menu-template.php' ); 
    144144require( ABSPATH . WPINC . '/admin-bar.php' ); 
    145145 
    146146require( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 
     147require( ABSPATH . WPINC . '/class-wp-image-editor-base.php' ); 
    147148require( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' ); 
    148149require( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' ); 
    149150