1. 首页
  2. WordPress 函数手册

wp_get_image_editor()

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

返回WP_Image_编辑器实例并将文件加载到其中。
Returns a WP_Image_Editor instance and loads file into it.

目录锚点:#参数#源码#笔记


参数(Parameters)

参数 类型 说明
$path (string) 要加载的文件的路径。
$args (array) 用于检索图像编辑器的其他参数。

源码(Source)

/**
 * 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.') );
}
更新版本 源码位置 使用 被使用
3.5.0 wp-includes/media.php 10 18

笔记(Notes)

基本示例

wp_get_image_editor() 为WP2原创文章,链接:https://www.wp2.cn/functions/wp_get_image_editor/