wp_get_image_editor

The timeline below displays how wordpress function wp_get_image_editor has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Returns a WP_Image_Editor instance and loads file into it.
 *
 * @since 3.5.0
 *
 * @param string $path Path to the file to load.
 * @param array  $args Optional. Additional arguments for retrieving the image editor.
 *                     Default empty array.
 * @return WP_Image_Editor|WP_Error The WP_Image_Editor object on success,
 *                                  a WP_Error object otherwise.
 */
function wp_get_image_editor($path, $args = array())
{
    $args['path'] = $path;
    // If the mime type is not set in args, try to extract and set it from the file.
    if (!isset($args['mime_type'])) {
        $file_info = wp_check_filetype($args['path']);
        /*
         * If $file_info['type'] is false, then we let the editor attempt to
         * figure out the file type, rather than forcing a failure based on extension.
         */
        if (isset($file_info) && $file_info['type']) {
            $args['mime_type'] = $file_info['type'];
        }
    }
    // Check and set the output mime type mapped to the input type.
    if (isset($args['mime_type'])) {
        /** This filter is documented in wp-includes/class-wp-image-editor.php */
        $output_format = apply_filters('image_editor_output_format', array(), $path, $args['mime_type']);
        if (isset($output_format[$args['mime_type']])) {
            $args['output_mime_type'] = $output_format[$args['mime_type']];
        }
    }
    $implementation = _wp_image_editor_choose($args);
    if ($implementation) {
        $editor = new $implementation($path);
        $loaded = $editor->load();
        if (is_wp_error($loaded)) {
            return $loaded;
        }
        return $editor;
    }
    return new WP_Error('image_no_editor', __('No editor could be selected.'));
}

WordPress Version: 6.1

/**
 * Returns a WP_Image_Editor instance and loads file into it.
 *
 * @since 3.5.0
 *
 * @param string $path Path to the file to load.
 * @param array  $args Optional. Additional arguments for retrieving the image editor.
 *                     Default empty array.
 * @return WP_Image_Editor|WP_Error The WP_Image_Editor object on success,
 *                                  a WP_Error object otherwise.
 */
function wp_get_image_editor($path, $args = array())
{
    $args['path'] = $path;
    // If the mime type is not set in args, try to extract and set it from the file.
    if (!isset($args['mime_type'])) {
        $file_info = wp_check_filetype($args['path']);
        // If $file_info['type'] is false, then we let the editor attempt to
        // figure out the file type, rather than forcing a failure based on extension.
        if (isset($file_info) && $file_info['type']) {
            $args['mime_type'] = $file_info['type'];
        }
    }
    // Check and set the output mime type mapped to the input type.
    if (isset($args['mime_type'])) {
        /** This filter is documented in wp-includes/class-wp-image-editor.php */
        $output_format = apply_filters('image_editor_output_format', array(), $path, $args['mime_type']);
        if (isset($output_format[$args['mime_type']])) {
            $args['output_mime_type'] = $output_format[$args['mime_type']];
        }
    }
    $implementation = _wp_image_editor_choose($args);
    if ($implementation) {
        $editor = new $implementation($path);
        $loaded = $editor->load();
        if (is_wp_error($loaded)) {
            return $loaded;
        }
        return $editor;
    }
    return new WP_Error('image_no_editor', __('No editor could be selected.'));
}

WordPress Version: 5.7

/**
 * Returns a WP_Image_Editor instance and loads file into it.
 *
 * @since 3.5.0
 *
 * @param string $path Path to the file to load.
 * @param array  $args Optional. Additional arguments for retrieving the image editor.
 *                     Default empty array.
 * @return WP_Image_Editor|WP_Error The WP_Image_Editor object on success,
 *                                  a WP_Error object otherwise.
 */
function wp_get_image_editor($path, $args = array())
{
    $args['path'] = $path;
    if (!isset($args['mime_type'])) {
        $file_info = wp_check_filetype($args['path']);
        // If $file_info['type'] is false, then we let the editor attempt to
        // figure out the file type, rather than forcing a failure based on extension.
        if (isset($file_info) && $file_info['type']) {
            $args['mime_type'] = $file_info['type'];
        }
    }
    $implementation = _wp_image_editor_choose($args);
    if ($implementation) {
        $editor = new $implementation($path);
        $loaded = $editor->load();
        if (is_wp_error($loaded)) {
            return $loaded;
        }
        return $editor;
    }
    return new WP_Error('image_no_editor', __('No editor could be selected.'));
}

WordPress Version: 4.2

/**
 * Returns a WP_Image_Editor instance and loads file into it.
 *
 * @since 3.5.0
 *
 * @param string $path Path to the file to load.
 * @param array  $args Optional. Additional arguments for retrieving the image editor.
 *                     Default empty array.
 * @return WP_Image_Editor|WP_Error The WP_Image_Editor object if successful, an WP_Error
 *                                  object otherwise.
 */
function wp_get_image_editor($path, $args = array())
{
    $args['path'] = $path;
    if (!isset($args['mime_type'])) {
        $file_info = wp_check_filetype($args['path']);
        // If $file_info['type'] is false, then we let the editor attempt to
        // figure out the file type, rather than forcing a failure based on extension.
        if (isset($file_info) && $file_info['type']) {
            $args['mime_type'] = $file_info['type'];
        }
    }
    $implementation = _wp_image_editor_choose($args);
    if ($implementation) {
        $editor = new $implementation($path);
        $loaded = $editor->load();
        if (is_wp_error($loaded)) {
            return $loaded;
        }
        return $editor;
    }
    return new WP_Error('image_no_editor', __('No editor could be selected.'));
}

WordPress Version: 3.7

/**
 * Returns a WP_Image_Editor instance and loads file into it.
 *
 * @since 3.5.0
 * @access public
 *
 * @param string $path Path to file to load
 * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
 * @return WP_Image_Editor|WP_Error
 */
function wp_get_image_editor($path, $args = array())
{
    $args['path'] = $path;
    if (!isset($args['mime_type'])) {
        $file_info = wp_check_filetype($args['path']);
        // If $file_info['type'] is false, then we let the editor attempt to
        // figure out the file type, rather than forcing a failure based on extension.
        if (isset($file_info) && $file_info['type']) {
            $args['mime_type'] = $file_info['type'];
        }
    }
    $implementation = _wp_image_editor_choose($args);
    if ($implementation) {
        $editor = new $implementation($path);
        $loaded = $editor->load();
        if (is_wp_error($loaded)) {
            return $loaded;
        }
        return $editor;
    }
    return new WP_Error('image_no_editor', __('No editor could be selected.'));
}