REST API: Introduce endpoint for editing images.

To facilitate inline image editing in Gutenberg, a new endpoint at wp/v2/media/<id>/edit has been introduced. This is functionally similar to the existing ajax image editor, however the REST API editor creates a new attachment record instead of updating an existing attachment.

Fixes #44405.
Props ajlende, ellatrix, spacedmonkey, azaozz.



git-svn-id: https://develop.svn.wordpress.org/trunk@48291 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2020-07-04 04:13:17 +00:00
parent c2d5f9515d
commit e51a554f5d
5 changed files with 544 additions and 21 deletions

View File

@@ -7,6 +7,9 @@ if ( class_exists( 'WP_Image_Editor' ) ) :
public static $load_return = true;
public static $test_return = true;
public static $save_return = array();
public static $spy = array();
public static $edit_return = array();
public static $size_return = null;
// Allow testing of jpeg_quality filter.
public function set_mime_type( $mime_type = null ) {
@@ -23,19 +26,34 @@ if ( class_exists( 'WP_Image_Editor' ) ) :
return true;
}
public function resize( $max_w, $max_h, $crop = false ) {
self::$spy[ __FUNCTION__ ][] = func_get_args();
if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
return self::$edit_return[ __FUNCTION__ ];
}
}
public function multi_resize( $sizes ) {
self::$spy[ __FUNCTION__ ][] = func_get_args();
if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
return self::$edit_return[ __FUNCTION__ ];
}
}
public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
self::$spy[ __FUNCTION__ ][] = func_get_args();
if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
return self::$edit_return[ __FUNCTION__ ];
}
}
public function rotate( $angle ) {
self::$spy[ __FUNCTION__ ][] = func_get_args();
if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
return self::$edit_return[ __FUNCTION__ ];
}
}
public function flip( $horz, $vert ) {
self::$spy[ __FUNCTION__ ][] = func_get_args();
if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
return self::$edit_return[ __FUNCTION__ ];
}
}
public function save( $destfilename = null, $mime_type = null ) {
return self::$save_return;
@@ -43,6 +61,14 @@ if ( class_exists( 'WP_Image_Editor' ) ) :
public function stream( $mime_type = null ) {
}
public function get_size() {
if ( self::$size_return ) {
return self::$size_return;
}
return parent::get_size();
}
}
endif;