diff --git wp-admin/includes/media.php wp-admin/includes/media.php
index 6cc1b63..185b096 100644
|
|
|
function get_media_item( $attachment_id, $args = null ) { |
| 1122 | 1122 | $media_dims = apply_filters( 'media_meta', $media_dims, $post ); |
| 1123 | 1123 | |
| 1124 | 1124 | $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 ) ) ) { |
| 1126 | 1126 | $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
| 1127 | 1127 | $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>"; |
| 1128 | 1128 | } |
| … |
… |
function edit_form_image_editor() { |
| 2254 | 2254 | $att_url = wp_get_attachment_url( $post->ID ); |
| 2255 | 2255 | |
| 2256 | 2256 | $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 ) ) ) { |
| 2258 | 2258 | $nonce = wp_create_nonce( "image_editor-$post->ID" ); |
| 2259 | 2259 | $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>"; |
| 2260 | 2260 | } |
diff --git wp-includes/class-wp-image-editor-gd.php wp-includes/class-wp-image-editor-gd.php
index ca76006..28716f3 100644
|
|
|
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 32 | 32 | * |
| 33 | 33 | * @return boolean |
| 34 | 34 | */ |
| 35 | | public static function test( $args = null ) { |
| | 35 | public static function exists() { |
| 36 | 36 | if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
| 37 | 37 | return false; |
| 38 | 38 | |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 100 | 100 | * @return boolean |
| 101 | 101 | */ |
| 102 | 102 | public static function supports_mime_type( $mime_type ) { |
| 103 | | $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' ); |
| | 103 | $image_types = imagetypes(); |
| | 104 | switch( $mime_type ) { |
| | 105 | case 'image/jpeg': |
| | 106 | return ($image_types & IMG_JPG) != 0; |
| | 107 | case 'image/png': |
| | 108 | return ($image_types & IMG_PNG) != 0; |
| | 109 | case 'image/gif': |
| | 110 | return ($image_types & IMG_GIF) != 0; |
| | 111 | } |
| 104 | 112 | |
| 105 | | return in_array( $mime_type, $allowed_mime_types ); |
| | 113 | return false; |
| 106 | 114 | } |
| 107 | 115 | |
| 108 | 116 | /** |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 261 | 269 | * @since 3.5.0 |
| 262 | 270 | * @access public |
| 263 | 271 | * |
| 264 | | * @param boolean $horz Horizonal Flip |
| | 272 | * @param boolean $horz Horizontal Flip |
| 265 | 273 | * @param boolean $vert Vertical Flip |
| 266 | 274 | * @returns boolean|WP_Error |
| 267 | 275 | */ |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 369 | 377 | return imagejpeg( $this->image, null, $this->quality ); |
| 370 | 378 | } |
| 371 | 379 | } |
| 372 | | } |
| 373 | | No newline at end of file |
| | 380 | } |
diff --git wp-includes/class-wp-image-editor-imagick.php wp-includes/class-wp-image-editor-imagick.php
index 601b99b..b104941 100644
|
|
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 36 | 36 | * |
| 37 | 37 | * @return boolean |
| 38 | 38 | */ |
| 39 | | public static function test( $args = null ) { |
| | 39 | public static function exists() { |
| 40 | 40 | if ( ! extension_loaded( 'imagick' ) || ! is_callable( 'Imagick', 'queryFormats' ) ) |
| 41 | 41 | return false; |
| 42 | 42 | |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 147 | 147 | * @return boolean |
| 148 | 148 | */ |
| 149 | 149 | public static function supports_mime_type( $mime_type ) { |
| 150 | | if ( ! $mime_type ) |
| 151 | | return false; |
| 152 | | |
| 153 | 150 | $imagick_extension = strtoupper( self::get_extension( $mime_type ) ); |
| 154 | 151 | |
| | 152 | if ( ! $imagick_extension ) |
| | 153 | return false; |
| | 154 | |
| 155 | 155 | try { |
| 156 | 156 | return ( (bool) Imagick::queryFormats( $imagick_extension ) ); |
| 157 | 157 | } |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 312 | 312 | * @since 3.5.0 |
| 313 | 313 | * @access public |
| 314 | 314 | * |
| 315 | | * @param boolean $horz Horizonal Flip |
| | 315 | * @param boolean $horz Horizontal Flip |
| 316 | 316 | * @param boolean $vert Vertical Flip |
| 317 | 317 | * @returns boolean|WP_Error |
| 318 | 318 | */ |
diff --git wp-includes/class-wp-image-editor.php wp-includes/class-wp-image-editor.php
index 920e4a4..5fc2511 100644
|
|
|
abstract class WP_Image_Editor { |
| 28 | 28 | * @since 3.5.0 |
| 29 | 29 | * @access public |
| 30 | 30 | * |
| 31 | | * @param string $path Path to File to Load |
| 32 | | * @param array $required_methods Methods to require in implementation |
| | 31 | * @param string $path Path to file to load |
| | 32 | * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } |
| 33 | 33 | * @return WP_Image_Editor|WP_Error |
| 34 | 34 | */ |
| 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 ); |
| | 35 | public final static function get_instance( $path, $args = array() ) { |
| | 36 | if ( ! isset( $args['mime_type'] ) ) { |
| | 37 | $file_info = wp_check_filetype( $path ); |
| | 38 | |
| | 39 | // If $file_info['type'] is false, then we let the editor attempt to |
| | 40 | // figure out the file type, rather than forcing a failure based on extension. |
| | 41 | if ( isset( $file_info ) && $file_info['type'] ) |
| | 42 | $args['mime_type'] = $file_info['type']; |
| | 43 | } |
| | 44 | |
| | 45 | $implementation = apply_filters( 'wp_image_editor_class', self::choose_implementation( $args ) ); |
| 37 | 46 | |
| 38 | 47 | if ( $implementation ) { |
| 39 | 48 | $editor = new $implementation( $path ); |
| … |
… |
abstract class WP_Image_Editor { |
| 45 | 54 | return $editor; |
| 46 | 55 | } |
| 47 | 56 | |
| 48 | | return new WP_Error( 'no_editor', __('No editor could be selected') ); |
| | 57 | return new WP_Error( 'image_no_editor', __('No editor could be selected.') ); |
| 49 | 58 | } |
| 50 | 59 | |
| 51 | 60 | /** |
| … |
… |
abstract class WP_Image_Editor { |
| 54 | 63 | * @since 3.5.0 |
| 55 | 64 | * @access private |
| 56 | 65 | * |
| 57 | | * @param array $required_methods String array of all methods required for implementation returned. |
| | 66 | * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } |
| 58 | 67 | * @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 | 68 | */ |
| 60 | | private final static function choose_implementation( $required_methods = null ) { |
| 61 | | $request_order = apply_filters( 'wp_image_editors', |
| | 69 | private final static function choose_implementation( $path, $args = array() ) { |
| | 70 | $implementations = apply_filters( 'wp_image_editors', |
| 62 | 71 | array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); |
| 63 | 72 | |
| 64 | | if ( ! $required_methods ) |
| 65 | | $required_methods = array(); |
| | 73 | foreach ( $implementations as $implementation ) { |
| | 74 | if ( ! call_user_func( array( $implementation, 'exists' ), $args ) ) |
| | 75 | continue; |
| 66 | 76 | |
| 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' ) ) ) |
| | 77 | if ( isset( $args['mime_type'] ) && |
| | 78 | ! call_user_func( |
| | 79 | array( $implementation, 'supports_mime_type' ), |
| | 80 | $args['mime_type'] ) ) { |
| 71 | 81 | continue; |
| | 82 | } |
| 72 | 83 | |
| 73 | | // Make sure that all methods are supported by editor. |
| 74 | | if ( array_diff( $required_methods, get_class_methods( $editor ) ) ) |
| | 84 | if ( isset( $args['methods'] ) && |
| | 85 | array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { |
| 75 | 86 | continue; |
| | 87 | } |
| 76 | 88 | |
| 77 | | return $editor; |
| | 89 | return $implementation; |
| 78 | 90 | } |
| | 91 | |
| 79 | 92 | return false; |
| 80 | 93 | } |
| 81 | 94 | |
| 82 | 95 | /** |
| | 96 | * Tests whether there is an editor that supports a given mime type or methods. |
| | 97 | * |
| | 98 | * @since 3.5.0 |
| | 99 | * @access public |
| | 100 | * |
| | 101 | * @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, ...} } |
| | 102 | * @return boolean true if an eligible editor is found; false otherwise |
| | 103 | */ |
| | 104 | public final static function supports( $args = array() ) { |
| | 105 | return (bool) self::choose_implementation( $args ); |
| | 106 | } |
| | 107 | |
| | 108 | /** |
| 83 | 109 | * Loads image from $this->file into editor. |
| 84 | 110 | * |
| 85 | 111 | * @since 3.5.0 |
| … |
… |
abstract class WP_Image_Editor { |
| 168 | 194 | * @access public |
| 169 | 195 | * @abstract |
| 170 | 196 | * |
| 171 | | * @param boolean $horz Horizonal Flip |
| | 197 | * @param boolean $horz Horizontal Flip |
| 172 | 198 | * @param boolean $vert Vertical Flip |
| 173 | 199 | * @return boolean|WP_Error |
| 174 | 200 | */ |
| … |
… |
abstract class WP_Image_Editor { |
| 197 | 223 | * @param array $args |
| 198 | 224 | * @return boolean |
| 199 | 225 | */ |
| 200 | | public static function test( $args = null ) { |
| | 226 | public static function exists() { |
| 201 | 227 | return false; |
| 202 | 228 | } |
| 203 | 229 | |
diff --git wp-includes/deprecated.php wp-includes/deprecated.php
index 9e99614..5b841df 100644
|
|
|
function user_pass_ok($user_login, $user_pass) { |
| 3328 | 3328 | * @since 2.3.0 |
| 3329 | 3329 | * @deprecated 3.5.0 |
| 3330 | 3330 | */ |
| 3331 | | function _save_post_hook() {} |
| 3332 | | No newline at end of file |
| | 3331 | function _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 | */ |
| | 3343 | function 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 |
diff --git wp-includes/media.php wp-includes/media.php
index d8475f1..cfc7172 100644
|
|
|
function get_taxonomies_for_attachments( $output = 'names' ) { |
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
| 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 | | /** |
| 938 | 907 | * Create new GD image resource with transparency support |
| 939 | 908 | * @TODO: Deprecate if possible. |
| 940 | 909 | * |