[wp-trac] [WordPress Trac] #42558: Reduce the number of capability checks performed by the Customizer
WordPress Trac
noreply at wordpress.org
Wed Nov 15 17:08:34 UTC 2017
#42558: Reduce the number of capability checks performed by the Customizer
-------------------------+-----------------------------
Reporter: johnbillion | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version:
Severity: normal | Keywords: needs-patch
Focuses: performance |
-------------------------+-----------------------------
On a vanilla installation of WordPress running the Twenty Seventeen theme,
the Customizer performs over 400 user capability checks via
`current_user_can()`.
The majority of these are duplicate checks performed for each customizer
setting. This includes:
* ~140 calls to `current_user_can( 'customize' )`
* ~220 calls to `current_user_can( 'edit_theme_options' )`
* ~20 calls to `current_user_can( 'manage_options' )`
The main offenders are:
* `WP_Customize_Manager->unsanitized_post_values()`
* `WP_Customize_Setting->check_capabilities()`
* `WP_Customize_Section->check_capabilities()`
* `WP_Customize_Panel->check_capabilities()`
Calls to `current_user_can()` are quite cheap, but they're certainly not
free, especially on sites which have filters hooked onto the
`map_meta_cap` and `user_has_cap` filters, and sites with extra Customizer
controls registered.
With a static property cache in each of the `WP_Customize_Manager`,
`WP_Customize_Section`, and `WP_Customize_Setting` classes, the 400
capability checks are reduced to fewer than 30.
Patch coming up soon, after some more testing.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42558>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list