WordPress.org

Make WordPress Core

Ticket #29082: 29082.patch

File 29082.patch, 2.8 KB (added by jrf, 5 years ago)
  • src/wp-includes/meta.php

    From e408d8709a3d63f4d957d33bda76e47235b6f903 Mon Sep 17 00:00:00 2001
    From: jrfnl <github_nospam@adviesenzo.nl>
    Date: Thu, 10 Dec 2015 06:40:13 +0100
    Subject: [PATCH] Add $object_id parameter to
     `sanitize_{$meta_type}_meta_{$meta_key}` filter.
    
    Implement @sc0ttclark's suggestion.
    ---
     src/wp-includes/meta.php | 12 +++++++-----
     1 file changed, 7 insertions(+), 5 deletions(-)
    
    diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php
    index 2a5f45f..460a7b0 100644
    a b function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = 
    4949        // expected_slashed ($meta_key)
    5050        $meta_key = wp_unslash($meta_key);
    5151        $meta_value = wp_unslash($meta_value);
    52         $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
     52        $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $object_id );
    5353
    5454        /**
    5555         * Filter whether to add metadata of a specific type.
    function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v 
    164164        $meta_key = wp_unslash($meta_key);
    165165        $passed_value = $meta_value;
    166166        $meta_value = wp_unslash($meta_value);
    167         $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
     167        $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $object_id );
    168168
    169169        /**
    170170         * Filter whether to update metadata of a specific type.
    function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = 
    640640
    641641                // Sanitize the meta
    642642                $_meta_value = $meta_value;
    643                 $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
     643                $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type, $object_id );
    644644                $meta_value = maybe_serialize( $meta_value );
    645645
    646646                // Format the data query arguments.
    function is_protected_meta( $meta_key, $meta_type = null ) { 
    920920 * @param string $meta_key   Meta key
    921921 * @param mixed  $meta_value Meta value to sanitize
    922922 * @param string $meta_type  Type of meta
     923 * @param int    $object_id  ID of the object metadata is for
    923924 * @return mixed Sanitized $meta_value
    924925 */
    925 function sanitize_meta( $meta_key, $meta_value, $meta_type ) {
     926function sanitize_meta( $meta_key, $meta_value, $meta_type, $object_id ) {
    926927
    927928        /**
    928929         * Filter the sanitization of a specific meta key of a specific meta type.
    function sanitize_meta( $meta_key, $meta_value, $meta_type ) { 
    937938         * @param mixed  $meta_value Meta value to sanitize.
    938939         * @param string $meta_key   Meta key.
    939940         * @param string $meta_type  Meta type.
     941         * @param int    $object_id  ID of the object metadata is for.
    940942         */
    941         return apply_filters( "sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type );
     943        return apply_filters( "sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type, $object_id );
    942944}
    943945
    944946/**