[wp-trac] [WordPress Trac] #30062: Add Hooks to Image Editor UI
WordPress Trac
noreply at wordpress.org
Tue Oct 21 21:59:48 UTC 2014
#30062: Add Hooks to Image Editor UI
---------------------------------+---------------------------------
Reporter: ericmann | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.0
Severity: normal | Resolution:
Keywords: has-patch has-tests | Focuses: ui, administration
---------------------------------+---------------------------------
Changes (by ericmann):
* keywords: has-patch has-tests reporter-feedback => has-patch has-tests
Comment:
Wanted to take a second to provide some overview for reviewers.
In short, every image edit group in the right rail of the image editor is
now registered by way of a callback. These callbacks can be registered
with a simple API:
- `add_imgedit_group()` - Registers and loads a specific callback
- `register_imgedit_group()` - Registers a callback
- `remove_imgedit_group()` - Unloads a specific callback but leaves it
registered
- `unregister_imgedit_group()` - Unregisters a callback
- `get_imgedit_groups()` - Gets an array/list of all loaded image edit
groups
Core will now register four default image groups:
1. Scale Image
1. Restore Image
1. Apply to
1. Crop Image
(These are the same groups registered pre-patch in the same order.
Registering them as discrete elements here allows developers to filter and
reorder/remove where necessary.)
In addition, several new hooks are defined so developers (themes/plugins)
can hook in wherever needed. Whenever an image edit group is added/removed
or registered/unregistered we trigger an action call passing the unique
name of the edit group.
The `get_imgedit_groups()` function internally calls a filter, passing the
array of all loaded image groups. This allows developers to dynamically
filter which groups show up or don't show up based on whatever conditions
they need.
Internally, the image edit groups are stored in a global array
(`$_imgedit_groups`) in two buckets - > registered and loaded. Registered
edit groups are available for use, but must be loaded (by calling
`add_imgedit_group()`) in order to appear in the UI. This allows plugin
editors to specify callbacks and register edit groups, but leave the
decision to load them up to theme developers instead.
The `wp_image_editor()` function remains largely unchanged, but instead of
building out its own markup for each existing image edit group (see the
numbered list above) it merely calls a `foreach` across the array returned
by `get_imgedit_groups()`. This means, by default, WordPress will still
iterate over the four default groups - developers can, however, inject as
many additional groups as needed into the markup by either
adding/registering a new group through the API or filtering
`imgedit_groups` to manually specify the groups they want printed and
their order.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30062#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list