[wp-trac] [WordPress Trac] #40527: Decouple WP_Customize_Manager

WordPress Trac noreply at wordpress.org
Tue Sep 5 03:39:41 UTC 2017


#40527: Decouple WP_Customize_Manager
--------------------------+------------------
 Reporter:  utkarshpatel  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  4.9
Component:  Customize     |     Version:  4.8
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+------------------

Comment (by dlh):

 In [attachment:40527.2.diff]:

 - Remove the cached copy of changeset data inside `WP_Customize_Manager`
 to address comment:3.

 - Return `null` when instantiating a changeset for an invalid post.

 - Remove a duplicate call to `json_last_error()`, and other minor fixes.

 Although comment:3 mentions using the `clean_cache_post` hook to reset the
 `WP_Customize_Manager::_changeset_data` property, we also had discussed
 removing the cached value entirely in the REST API endpoints repo:
 https://github.com/WP-API/wp-api-customize-
 endpoints/pull/5#discussion_r118804446.

 I went with the latter in this patch for its comparative simplicity and
 because core itself almost always calls
 `WP_Customize_Manager::get_changeset_post_data()`, and that already
 bypasses the property.

 Regarding the change to `WP_Customize_Changeset::from_post()`: Returning
 `null` would ensure that the two named constructors will return only
 changeset instances that contain at least a UUID so that
 `WP_Customize_Changeset::save()` can be called reliably.

 Returning `null` also matches the behavior of `get_post()`, and it removes
 the appearance of having retrieved a changeset by post ID when the lookup
 actually failed.

 Still, one alternative to returning `null` would be to still return a
 `WP_Customize_Changeset` instance as happened in [attachment:40527.diff],
 but then return a `WP_Error` early in `WP_Customize_Changeset::save()` if
 the instance doesn't have a post ID or UUID.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40527#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list