返回一个WP_Image_Editor实例并将文件加载到其中。

原型

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

参数

$path (string) (Required) 要加载的文件的路径。

$args (array) (Optional)  检索图像编辑器的其他参数。

返回值

(WP_Image_Editor|WP_Error)  该

源文件

路径:wp-includes/media.php

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

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_get_image_editor/