Make WordPress Core


Ignore:
Timestamp:
10/15/2018 11:45:16 AM (8 years ago)
Author:
flixos90
Message:

REST API: Move object type-specific metadata integrations from the wrapper functions to the low-level Meta API functions.

Object type-specific actions that should happen before or after modification of metadata have so far been part of the respective wrapper functions. By using action and filter hooks, this changeset ensures they are always executed, even when calling the lower-level Meta API functions directly, which the REST API does as a prime example.

Props flixos90, spacedmonkey.
Fixes #44467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/comment.php

    r43468 r43729  
    423423 * @return int|bool Meta ID on success, false on failure.
    424424 */
    425 function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) {
    426         $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    427         if ( $added ) {
    428                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    429         }
    430         return $added;
     425function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
     426        return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    431427}
    432428
     
    446442 * @return bool True on success, false on failure.
    447443 */
    448 function delete_comment_meta($comment_id, $meta_key, $meta_value = '') {
    449         $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    450         if ( $deleted ) {
    451                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    452         }
    453         return $deleted;
     444function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
     445        return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    454446}
    455447
     
    466458 *  is true.
    467459 */
    468 function get_comment_meta($comment_id, $key = '', $single = false) {
    469         return get_metadata('comment', $comment_id, $key, $single);
     460function get_comment_meta( $comment_id, $key = '', $single = false ) {
     461        return get_metadata( 'comment', $comment_id, $key, $single );
    470462}
    471463
     
    487479 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
    488480 */
    489 function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') {
    490         $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    491         if ( $updated ) {
    492                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    493         }
    494         return $updated;
     481function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
     482        return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    495483}
    496484
     
    30623050                 */
    30633051                do_action( 'comment_on_draft', $comment_post_ID );
    3064                
     3052
    30653053                if ( current_user_can( 'read_post', $comment_post_ID ) ) {
    30663054                        return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 );
     
    33883376        );
    33893377}
     3378
     3379/**
     3380 * Sets the last changed time for the 'comment' cache group.
     3381 *
     3382 * @since 5.0.0
     3383 */
     3384function wp_cache_set_comments_last_changed() {
     3385        wp_cache_set( 'last_changed', microtime(), 'comment' );
     3386}
Note: See TracChangeset for help on using the changeset viewer.