Make WordPress Core


Ignore:
Timestamp:
07/04/2020 04:13:17 AM (5 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/mock-image-editor.php

    r46586 r48291  
    88        public static $test_return = true;
    99        public static $save_return = array();
     10        public static $spy         = array();
     11        public static $edit_return = array();
     12        public static $size_return = null;
    1013
    1114        // Allow testing of jpeg_quality filter.
     
    2427        }
    2528        public function resize( $max_w, $max_h, $crop = false ) {
    26 
     29            self::$spy[ __FUNCTION__ ][] = func_get_args();
     30            if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
     31                return self::$edit_return[ __FUNCTION__ ];
     32            }
    2733        }
    2834        public function multi_resize( $sizes ) {
    29 
     35            self::$spy[ __FUNCTION__ ][] = func_get_args();
     36            if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
     37                return self::$edit_return[ __FUNCTION__ ];
     38            }
    3039        }
    3140        public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
    32 
     41            self::$spy[ __FUNCTION__ ][] = func_get_args();
     42            if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
     43                return self::$edit_return[ __FUNCTION__ ];
     44            }
    3345        }
    3446        public function rotate( $angle ) {
    35 
     47            self::$spy[ __FUNCTION__ ][] = func_get_args();
     48            if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
     49                return self::$edit_return[ __FUNCTION__ ];
     50            }
    3651        }
    3752        public function flip( $horz, $vert ) {
    38 
     53            self::$spy[ __FUNCTION__ ][] = func_get_args();
     54            if ( isset( self::$edit_return[ __FUNCTION__ ] ) ) {
     55                return self::$edit_return[ __FUNCTION__ ];
     56            }
    3957        }
    4058        public function save( $destfilename = null, $mime_type = null ) {
     
    4462
    4563        }
     64
     65        public function get_size() {
     66            if ( self::$size_return ) {
     67                return self::$size_return;
     68            }
     69
     70            return parent::get_size();
     71        }
    4672    }
    4773
Note: See TracChangeset for help on using the changeset viewer.