id summary reporter owner description type status priority milestone component version severity resolution keywords cc focuses 44467 Ensure meta wrapper functions do not contain additional logic flixos90 flixos90 "WordPress contains numerous wrapper functions for metadata that wrap the respective `add_metadata()` / `update_metadata()` / `get_metadata()` / `delete_metadata()` calls. Those are: * `*_post_meta()` * `*_term_meta()` * `*_comment_meta()` * `*_user_meta()` * `*_site_meta()` (on multisite) These are convenience wrappers that developers are encouraged to use in favor of the more low-level functions. However, it has become more and more common to also include small pieces of additional logic in the wrapper functions that will not be executed when calling the low-level functions. This is a problem, because the low-level functions are still called in numerous locations in core and also by plugins (usually by areas that deal with metadata in a more abstract way). Particularly, the REST API meta field classes make use of them, so here it becomes a significant problem already. This means that in those cases, crucial functionality does not get executed, for example preventing access in case of an old database version or clearing the cache. Therefore my suggestion is to remove all extra logic from all wrapper functions and instead run it via filters that become part of `default-filters.php`. This ensures consistency for all metadata functions and their wrappers. The following list shows all extra functionality that meta wrapper functions in core currently contain: * The writing post meta wrappers all ensure the metadata is only changed for the root post (not for a revision), and they all clear the cache for the respective post ID. * All term meta wrappers prevent access to the function if the database schema is too old. The writing term meta functions furthermore all clear the cache for the respective term ID. * The writing comment meta wrappers all clear the cache for the respective comment ID. * All site meta wrappers prevent access to the function if the database schema is too old. The writing site meta functions furthermore all clear the cache for the respective site ID. All of the above, except for the post revision bit, could easily become a filter or action hook: * Checks that possibly prevent access to metadata functions can use the `add_{$type}_metadata`, `update_{$type}_metadata` and `delete_{$type}_metadata` filters. * Caches for the respective objects can be cleared by using the `added_{$type}_meta`, `updated_{$type}_meta` and `deleted_{$type}_meta` actions." defect (bug) closed normal 5.0 Options, Meta APIs normal fixed 2nd-opinion has-patch has-unit-tests fixed-5.0 multisite, rest-api