wp_get_image_editor

Returns a WP_Image_Editor instance and loads file into it.

Description

(WP_Image_Editor|WP_Error) wp_get_image_editor( (string) $path, (array) $args = array() ); 

Returns (WP_Image_Editor|WP_Error)

The WP_Image_Editor object if successful, an WP_Error object otherwise.

Parameters (2)

0. $path (string)
Path to the file to load.
1. $args — Optional. (array) => array()
Additional arguments for retrieving the image editor. Default empty array.

Usage

  1. if ( !function_exists( 'wp_get_image_editor' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Path to the file to load. 
  5. $path = ''; 
  6.  
  7. // Optional. Additional arguments for retrieving the image editor. 
  8. // Default empty array. 
  9. $args = array(); 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = wp_get_image_editor($path, $args); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/media.php  
  1. function wp_get_image_editor( $path, $args = array() ) { 
  2. $args['path'] = $path; 
  3.  
  4. if ( ! isset( $args['mime_type'] ) ) { 
  5. $file_info = wp_check_filetype( $args['path'] ); 
  6.  
  7. // If $file_info['type'] is false, then we let the editor attempt to 
  8. // figure out the file type, rather than forcing a failure based on extension. 
  9. if ( isset( $file_info ) && $file_info['type'] ) 
  10. $args['mime_type'] = $file_info['type']; 
  11.  
  12. $implementation = _wp_image_editor_choose( $args ); 
  13.  
  14. if ( $implementation ) { 
  15. $editor = new $implementation( $path ); 
  16. $loaded = $editor->load(); 
  17.  
  18. if ( is_wp_error( $loaded ) ) 
  19. return $loaded; 
  20.  
  21. return $editor; 
  22.  
  23. return new WP_Error( 'image_no_editor', __('No editor could be selected.') );