Use register_meta()
correctly including full compatibility for the changes
#6700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
register_meta()
function in core has undergone several changes in the past:register_post_meta()
when registering metadata for posts. See https://core.trac.wordpress.org/changeset/43378.EDD should use that function correctly, depending on which WordPress version is currently in use.
Proposed Changes:
register_post_meta()
which handles the above changes correctly. It ensures that the function is always called correctly, depending on the WordPress version used. The post types to register metadata can be passed to it as a string or an array. Those of course will only take effect if WordPress version 5.0 or newer is being used. Otherwise, although somewhat sub-optimal, it will register the metadata for all posts of all post types, simply because previously there was no other way to do so (this is also what the plugin currently does).register_post_meta()
method in the plugin instead of calling core'sregister_meta()
directly. This makes its usage streamlined and also allows to get rid of the manual checks to add the sanitize filters in case of pre-4.6, which happens in the current code and is quite ugly.edd_download_metabox_post_types
filter is used. This filter was previously only run inedd_add_download_meta_box()
to see whether the download meta box should appear for a post type. By showing the download meta box, you essentially add support for that metadata to the respective post type, so it makes sense to use that data for metadata registration as well. For convenience, aedd_get_download_meta_post_types()
function is introduced that simply runs the filter.edd_payment
post type is used because that is the only place where that data needs to be present at this point.