wp_get_image_editor() WordPress Function

The wp_get_image_editor() function is used to retrieve an image editor instance. It is used by the image editing functions. This function can be used to create and modify images.

wp_get_image_editor( string $path, array $args = array() ) #

Returns a WP_Image_Editor instance and loads file into it.


Parameters

$path

(string)(Required)Path to the file to load.

$args

(array)(Optional) Additional arguments for retrieving the image editor.

Default value: array()


Top ↑

Return

(WP_Image_Editor|WP_Error) The WP_Image_Editor object on success, a WP_Error object otherwise.


Top ↑

Source

File: wp-includes/media.php

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.' ) );
}


Top ↑

Changelog

Changelog
VersionDescription
3.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More