WordPress.org

Make WordPress Core

Ticket #38323: 38323.7.wrappers.diff

File 38323.7.wrappers.diff, 6.4 KB (added by flixos90, 2 years ago)

wrappers for register_meta() ease of use

  • src/wp-includes/comment.php

     
    513513}
    514514
    515515/**
     516 * Registers a meta key for comments.
     517 *
     518 * @since 5.0.0
     519 *
     520 * @param string $comment_type Comment type to register a meta key for. Pass an empty string
     521 *                             to register the meta key across all existing comment types.
     522 * @param string $meta_key     The meta key to register.
     523 * @param array  $args         Data used to describe the meta key when registered. See
     524 *                             {@see register_meta()} for a list of supported arguments.
     525 * @return bool True if the meta key was successfully registered, false if not.
     526 */
     527function register_comment_meta( $comment_type, $meta_key, array $args ) {
     528        $args['object_subtype'] = $comment_type;
     529
     530        return register_meta( 'comment', $meta_key, $args );
     531}
     532
     533/**
     534 * Unregisters a meta key for comments.
     535 *
     536 * @since 5.0.0
     537 *
     538 * @param string $comment_type Comment type the meta key is currently registered for. Pass
     539 *                             an empty string if the meta key is registered across all
     540 *                             existing comment types.
     541 * @param string $meta_key     The meta key to unregister.
     542 * @return bool True on success, false if the meta key was not previously registered.
     543 */
     544function unregister_comment_meta( $comment_type, $meta_key ) {
     545        return unregister_meta_key( 'comment', $meta_key, $comment_type );
     546}
     547
     548/**
    516549 * Queues comments for metadata lazy-loading.
    517550 *
    518551 * @since 4.5.0
  • src/wp-includes/post.php

     
    19901990}
    19911991
    19921992/**
     1993 * Registers a meta key for posts.
     1994 *
     1995 * @since 5.0.0
     1996 *
     1997 * @param string $post_type Post type to register a meta key for. Pass an empty string
     1998 *                          to register the meta key across all existing post types.
     1999 * @param string $meta_key  The meta key to register.
     2000 * @param array  $args      Data used to describe the meta key when registered. See
     2001 *                          {@see register_meta()} for a list of supported arguments.
     2002 * @return bool True if the meta key was successfully registered, false if not.
     2003 */
     2004function register_post_meta( $post_type, $meta_key, array $args ) {
     2005        $args['object_subtype'] = $post_type;
     2006
     2007        return register_meta( 'post', $meta_key, $args );
     2008}
     2009
     2010/**
     2011 * Unregisters a meta key for posts.
     2012 *
     2013 * @since 5.0.0
     2014 *
     2015 * @param string $post_type Post type the meta key is currently registered for. Pass
     2016 *                          an empty string if the meta key is registered across all
     2017 *                          existing post types.
     2018 * @param string $meta_key  The meta key to unregister.
     2019 * @return bool True on success, false if the meta key was not previously registered.
     2020 */
     2021function unregister_post_meta( $post_type, $meta_key ) {
     2022        return unregister_meta_key( 'post', $meta_key, $post_type );
     2023}
     2024
     2025/**
    19932026 * Retrieve post meta fields, based on post ID.
    19942027 *
    19952028 * The post meta fields are retrieved from the cache where possible,
  • src/wp-includes/taxonomy.php

     
    13231323}
    13241324
    13251325/**
     1326 * Registers a meta key for terms.
     1327 *
     1328 * @since 5.0.0
     1329 *
     1330 * @param string $taxonomy Taxonomy to register a meta key for. Pass an empty string
     1331 *                         to register the meta key across all existing taxonomies.
     1332 * @param string $meta_key The meta key to register.
     1333 * @param array  $args     Data used to describe the meta key when registered. See
     1334 *                         {@see register_meta()} for a list of supported arguments.
     1335 * @return bool True if the meta key was successfully registered, false if not.
     1336 */
     1337function register_term_meta( $taxonomy, $meta_key, array $args ) {
     1338        $args['object_subtype'] = $taxonomy;
     1339
     1340        return register_meta( 'term', $meta_key, $args );
     1341}
     1342
     1343/**
     1344 * Unregisters a meta key for terms.
     1345 *
     1346 * @since 5.0.0
     1347 *
     1348 * @param string $taxonomy Taxonomy the meta key is currently registered for. Pass
     1349 *                         an empty string if the meta key is registered across all
     1350 *                         existing taxonomies.
     1351 * @param string $meta_key The meta key to unregister.
     1352 * @return bool True on success, false if the meta key was not previously registered.
     1353 */
     1354function unregister_term_meta( $taxonomy, $meta_key ) {
     1355        return unregister_meta_key( 'term', $meta_key, $taxonomy );
     1356}
     1357
     1358/**
    13261359 * Determines whether a term exists.
    13271360 *
    13281361 * Formerly is_term(), introduced in 2.3.0.
  • src/wp-includes/user.php

     
    857857}
    858858
    859859/**
     860 * Registers a meta key for users.
     861 *
     862 * @since 5.0.0
     863 *
     864 * @param string $user_type User type to register a meta key for. Pass an empty string
     865 *                          to register the meta key across all existing user types.
     866 * @param string $meta_key  The meta key to register.
     867 * @param array  $args      Data used to describe the meta key when registered. See
     868 *                          {@see register_meta()} for a list of supported arguments.
     869 * @return bool True if the meta key was successfully registered, false if not.
     870 */
     871function register_user_meta( $user_type, $meta_key, array $args ) {
     872        $args['object_subtype'] = $user_type;
     873
     874        return register_meta( 'user', $meta_key, $args );
     875}
     876
     877/**
     878 * Unregisters a meta key for users.
     879 *
     880 * @since 5.0.0
     881 *
     882 * @param string $user_type User type the meta key is currently registered for. Pass
     883 *                          an empty string if the meta key is registered across all
     884 *                          existing user types.
     885 * @param string $meta_key  The meta key to unregister.
     886 * @return bool True on success, false if the meta key was not previously registered.
     887 */
     888function unregister_user_meta( $user_type, $meta_key ) {
     889        return unregister_meta_key( 'user', $meta_key, $user_type );
     890}
     891
     892/**
    860893 * Count number of users who have each of the user roles.
    861894 *
    862895 * Assumes there are neither duplicated nor orphaned capabilities meta_values.