Post Meta API Cleanup

Description

delete_meta() , get_post_meta_by_id(), has_meta(), update_meta(), delete_post_meta_by_key() should be wrappers around the metadata API. The metadata functions may need to emit *_postmeta actions for back compat.

Calling the new functions now. Also added the legacy *_postmeta actions to them.

Is there a plan to add way in the meta API to get a lot of meta with the ids? With that I could move the logic out of has_meta() and make it a wrapper. Alternatively, the query in there could just be ported to the meta API?

WPTestPostMeta and WPTestIncludesMeta unit tests pass except for test_delete_post_meta_by_key(). delete_post_meta_by_key() is failing. This is due to a bug in update_metadata() where the cache is not cleared for all posts when doing $delete_all. It needs to fetch all object IDs and do a wp_cache_delete() for each similar to what delete_post_meta_by_key() did.

Please provide update_postmeta, updated_postmeta, delete_postmeta and deleted_postmeta filters for other metadata types too. Of course include proper metadata name in filter name instead of 'post' (e.g. update_usermeta, and so on). This will allow to create new types of plugins.

There are some more places where we can make better use of the metadata API.

Patched:

do_all_pings() can use delete_metadata_by_mid() and we don't need to perform the second query to retrieve the meta_id since we already get it.

Other possibilities which didn't work out straight away:

do_enclose(): unfortunately the code could produce an array of meta IDs to delete... but I'm mentioning it because in it's current state this doesn't work anyway as preparing the implode will produce something like IN('1,2,3')

The metadata addition also uses a direct query, maybe this could be swapped for add_post_meta or add_metadata (though this would require back compat _postmeta actions)

wp_delete_post() and wp_delete_attachment(): both delete an array of meta IDs.

_publish_post_hook(): adding post meta with a query, see above for note about switching to add_post_meta or add_metadata

Splitting some of the above out into separate tickets for discussion, particularly do_enclose() which really needs a clean up, might be best.