Editing Images in the Block Editor

As most people that follow coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. development already know, a new feature in WordPress 5.5 is editing of images right in the block editor.

The new image editor looks a lot better and is much easier to use. It comes with several presets allowing the users to quickly adjust the aspect ratio, zoom level, and position.

Editing an image in the image block, aspect ration drop-down open.

There are two notable changes:

  • Image editing is done through the REST APIREST API The REST API is an acronym for the RESTful Application Program Interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. It is how the front end of an application (think “phone app” or “website”) can communicate with the data store (think “database” or “file system”) https://developer.wordpress.org/rest-api/.. The new functionality is in WP_REST_Attachments_Controller and introduces wp_edited_image_metadata filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.. Of course all other actions and filters triggered when image sub-sizes are created and saved still work.
  • After editing, the image is saved separately as a new attachment. This lets the users have full control: see the edited image in the Media Library, edit either the original or the edited image again, or delete any of them if not used. (In the old image editor the edited images are saved in the image metaMeta Meta is a term that refers to the inside workings of a group. For us, this is the team that works on internal WordPress sites like WordCamp Central and Make WordPress. reusing the same attachment, and the users cannot access the original “parent” image).

When creating new attachments for edited images the post_title, post_content (image description), post_excerpt (caption stored in the database), and the alt text (stored in post meta in the database) are copied (if present) from the parent image to the edited image. Also the EXIF data stored in image meta is merged.

For plugins, the new wp_edited_image_metadata filter can also be used to migrate any other meta data a pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party may be adding to image attachments, or to save new data.

#5-5, #dev-notes