Make WordPress Core

Ticket #25826: 25826.2.diff

File 25826.2.diff, 16.6 KB (added by raamdev, 11 years ago)

Uses git diff --no-prefix

  • wp-includes/meta.php

    diff --git wp-includes/meta.php wp-includes/meta.php
    index 4066781..c55290d 100644
    function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = 
    4747        $meta_value = wp_unslash($meta_value);
    4848        $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
    4949
     50        /**
     51         * Filter to apply before adding the metadata to the database to allow overriding what is
     52         * returned by add_metadata().
     53         *
     54         * @since 3.1.0
     55         *
     56         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     57         * @param int|null null The value add_metadata() should return. The meta ID on successful update, false on failure.
     58         * @param int $object_id ID of the object metadata is for.
     59         * @param string $meta_key Metadata key.
     60         * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
     61         * @param bool $unique Optional, default is false. Whether the specified metadata key should be
     62         *              unique for the object. If true, and the object already has a value for the specified
     63         *              metadata key, no change will be made.
     64         */
    5065        $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
    5166        if ( null !== $check )
    5267                return $check;
    function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = 
    5974        $_meta_value = $meta_value;
    6075        $meta_value = maybe_serialize( $meta_value );
    6176
     77        /**
     78         * Fires before adding metadata to the database.
     79         *
     80         * @since 3.1.0
     81         *
     82         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     83         * @param int $object_id ID of the object metadata is for.
     84         * @param string $meta_key Metadata key.
     85         * @param mixed $_meta_value Metadata value.
     86         */
    6287        do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
    6388
    6489        $result = $wpdb->insert( $table, array(
    function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = 
    7499
    75100        wp_cache_delete($object_id, $meta_type . '_meta');
    76101
     102        /**
     103         * Fires after adding metadata to the database.
     104         *
     105         * @since 2.9.0
     106         *
     107         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     108         * @param int $object_id ID of the object metadata is for.
     109         * @param string $meta_key Metadata key.
     110         * @param mixed $_meta_value Metadata value.
     111         * @param int $mid The meta ID after successful update.
     112         */
    77113        do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
    78114
    79115        return $mid;
    function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v 
    119155        $meta_value = wp_unslash($meta_value);
    120156        $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
    121157
     158        /**
     159         * Filter before updating the metadata in the database to allow overriding what is returned by update_metadata().
     160         *
     161         * @since 3.1.0
     162         *
     163         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     164         * @param bool|null null The value update_metadata() should return. True on successful update, false on failure.
     165         * @param int $object_id ID of the object metadata is for.
     166         * @param string $meta_key Metadata key.
     167         * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
     168         * @param mixed $prev_value Optional. If specified, only update existing metadata entries with
     169         *              the specified value. Otherwise, update all entries.
     170         */
    122171        $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
    123172        if ( null !== $check )
    124173                return (bool) $check;
    function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v 
    146195                $where['meta_value'] = $prev_value;
    147196        }
    148197
     198        /**
     199         * Fires before updating metadata in the database.
     200         *
     201         * @since 2.9.0
     202         *
     203         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     204         * @param int $meta_id of metadata entry to update
     205         * @param int $object_id ID of the object metadata is for
     206         * @param string $meta_key Metadata key
     207         * @param mixed $_meta_value Metadata value.
     208         */
    149209        do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
    150210
    151211        if ( 'post' == $meta_type )
     212                /**
     213                 * Fires before updating metadata in the database when Meta Type is 'post'.
     214                 *
     215                 * @since 3.3.0
     216                 *
     217                 * @param int $meta_id of metadata entry to update
     218                 * @param int $object_id ID of the object metadata is for
     219                 * @param string $meta_key Metadata key
     220                 * @param mixed $meta_value Metadata value.
     221                 */
    152222                do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    153223
    154224        $result = $wpdb->update( $table, $data, $where );
    function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v 
    157227
    158228        wp_cache_delete($object_id, $meta_type . '_meta');
    159229
     230        /**
     231         * Fires after updating metadata in the database.
     232         *
     233         * @since 2.9.0
     234         *
     235         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     236         * @param int $meta_id of updated metadata entry.
     237         * @param int $object_id ID of the object metadata is for.
     238         * @param string $meta_key Metadata key.
     239         * @param mixed $_meta_value Metadata value.
     240         */
    160241        do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
    161242
    162243        if ( 'post' == $meta_type )
     244                /**
     245                 * Fires after updating metadata in the database when meta type is 'post'.
     246                 *
     247                 * @since 3.3.0
     248                 *
     249                 * @param int $meta_id of updated metadata entry.
     250                 * @param int $object_id ID of the object metadata is for.
     251                 * @param string $meta_key Metadata key.
     252                 * @param mixed $meta_value Metadata value.
     253                 */
    163254                do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    164255
    165256        return true;
    function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d 
    201292        $meta_key = wp_unslash($meta_key);
    202293        $meta_value = wp_unslash($meta_value);
    203294
     295        /**
     296         * Filter before deleting the metadata from the database. If filter is applied, delete_metadata()
     297         * immediately returns the value returned by the filter and does not delete metadata from database.
     298         *
     299         * @since 3.1.0
     300         *
     301         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     302         * @param bool|null null The value delete_metadata() should return.
     303         * @param int $object_id ID of the object metadata is for.
     304         * @param string $meta_key Metadata key.
     305         * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
     306         * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries
     307         *              for all objects, ignoring the specified object_id. Otherwise, only delete matching
     308         *              metadata entries for the specified object_id.
     309         */
    204310        $check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all );
    205311        if ( null !== $check )
    206312                return (bool) $check;
    function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d 
    223329        if ( $delete_all )
    224330                $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) );
    225331
     332        /**
     333         * Fires before deleting metadata from the database.
     334         *
     335         * @since 3.1.0
     336         *
     337         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     338         * @param array $meta_ids Array of metadata entry IDs to delete.
     339         * @param int $object_id ID of the object metadata is for.
     340         * @param string $meta_key Metadata key.
     341         * @param mixed $_meta_value Metadata value.
     342         */
    226343        do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    227344
    228345        // Old-style action.
    229346        if ( 'post' == $meta_type )
     347                /**
     348                 * Fires before deleting metadata from the database when meta type is 'post'.
     349                 *
     350                 * @since 3.3.0
     351                 *
     352                 * @param array $meta_ids Array of metadata entry IDs to delete.
     353                 */
    230354                do_action( 'delete_postmeta', $meta_ids );
    231355
    232356        $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )";
    function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d 
    244368                wp_cache_delete($object_id, $meta_type . '_meta');
    245369        }
    246370
     371        /**
     372         * Fires after deleting metadata from the database.
     373         *
     374         * @since 2.9.0
     375         *
     376         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     377         * @param array $meta_ids Array of deleted metadata entries.
     378         * @param int $object_id ID of the object metadata is for.
     379         * @param string $meta_key Metadata key.
     380         * @param mixed $_meta_value Metadata value.
     381         */
    247382        do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    248383
    249384        // Old-style action.
    250385        if ( 'post' == $meta_type )
     386                /**
     387                 * Fires after deleting metadata from the database when meta type is 'post'.
     388                 *
     389                 * @since 3.3.0
     390                 *
     391                 * @param array $meta_ids Array of deleted metadata entry IDs.
     392                 */
    251393                do_action( 'deleted_postmeta', $meta_ids );
    252394
    253395        return true;
    function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { 
    273415        if ( !$object_id = absint($object_id) )
    274416                return false;
    275417
     418        /**
     419         * Filter metadata retrieval.
     420         *
     421         * @since 3.1.0
     422         *
     423         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     424         * @param string|array|null null The value get_metadata() should return. Single metadata value, or array of values.
     425         * @param int $object_id ID of the object metadata is for.
     426         * @param string $meta_key Metadata key.
     427         * @param string|array Single metadata value, or array of values
     428         */
    276429        $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
    277430        if ( null !== $check ) {
    278431                if ( $single && is_array( $check ) )
    function metadata_exists( $meta_type, $object_id, $meta_key ) { 
    321474        if ( ! $object_id = absint( $object_id ) )
    322475                return false;
    323476
     477        /**
     478         * Filter the check if metadata exists. If non-null is returned, metadata_exists() returns true.
     479         *
     480         * @since 3.1.0
     481         *
     482         * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     483         * @param bool|null null The value returned by metadata_exists(); if non-null, true is returned.
     484         * @param int $object_id ID of the object metadata is for.
     485         * @param string $meta_key Metadata key.
     486         * @param boolean true if the key is set, false if not.
     487         */
    324488        $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true );
    325489        if ( null !== $check )
    326490                return true;
    function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = 
    431595                $where = array();
    432596                $where[$id_column] = $meta_id;
    433597
     598                /**
     599                 * Fires before updating metadata in the database.
     600                 *
     601                 * @since 2.9.0
     602                 *
     603                 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     604                 * @param int $meta_id of metadata entry to update
     605                 * @param int $object_id ID of the object metadata is for
     606                 * @param string $meta_key Metadata key
     607                 * @param mixed $_meta_value Metadata value.
     608                 */
    434609                do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
    435610
    436611                if ( 'post' == $meta_type )
     612                        /**
     613                         * Fires before updating metadata in the database when Meta Type is 'post'.
     614                         *
     615                         * @since 3.3.0
     616                         *
     617                         * @param int $meta_id of metadata entry to update
     618                         * @param int $object_id ID of the object metadata is for
     619                         * @param string $meta_key Metadata key
     620                         * @param mixed $meta_value Metadata value.
     621                         */
    437622                        do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    438623
    439624                // Run the update query, all fields in $data are %s, $where is a %d.
    function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = 
    444629                // Clear the caches.
    445630                wp_cache_delete($object_id, $meta_type . '_meta');
    446631
     632                /**
     633                 * Fires after updating metadata in the database.
     634                 *
     635                 * @since 2.9.0
     636                 *
     637                 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     638                 * @param int $meta_id of updated metadata entry.
     639                 * @param int $object_id ID of the object metadata is for.
     640                 * @param string $meta_key Metadata key.
     641                 * @param mixed $_meta_value Metadata value.
     642                 */
    447643                do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
    448644
    449645                if ( 'post' == $meta_type )
     646                        /**
     647                         * Fires after updating metadata in the database when meta type is 'post'.
     648                         *
     649                         * @since 3.3.0
     650                         *
     651                         * @param int $meta_id of updated metadata entry.
     652                         * @param int $object_id ID of the object metadata is for.
     653                         * @param string $meta_key Metadata key.
     654                         * @param mixed $meta_value Metadata value.
     655                         */
    450656                        do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    451657
    452658                return true;
    function delete_metadata_by_mid( $meta_type, $meta_id ) { 
    489695        if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
    490696                $object_id = $meta->{$column};
    491697
     698                /**
     699                 * Fires before deleting metadata from the database.
     700                 *
     701                 * @since 3.1.0
     702                 *
     703                 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     704                 * @param array $meta_id Array with single metadata entry ID to delete.
     705                 * @param int $object_id ID of the object metadata is for.
     706                 * @param string $meta->meta_key Metadata key.
     707                 * @param mixed $meta->meta_value Metadata value.
     708                 */
    492709                do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    493710
    494711                // Old-style action.
    495712                if ( 'post' == $meta_type || 'comment' == $meta_type )
     713                        /**
     714                         * Fires before deleting metadata from the database when meta type is 'post'.
     715                         *
     716                         * @since 3.3.0
     717                         *
     718                         * @param int $meta_id ID of metadata entry to delete.
     719                         */
    496720                        do_action( "delete_{$meta_type}meta", $meta_id );
    497721
    498722                // Run the query, will return true if deleted, false otherwise
    function delete_metadata_by_mid( $meta_type, $meta_id ) { 
    501725                // Clear the caches.
    502726                wp_cache_delete($object_id, $meta_type . '_meta');
    503727
     728                /**
     729                 * Fires after deleting metadata from the database.
     730                 *
     731                 * @since 2.9.0
     732                 *
     733                 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user).
     734                 * @param array $meta_id Array with single deleted metadata entry ID.
     735                 * @param int $object_id ID of the object metadata is for.
     736                 * @param string $meta->meta_key Metadata key.
     737                 * @param mixed $meta->meta_value Metadata value.
     738                 */
    504739                do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    505740
    506741                // Old-style action.
    507742                if ( 'post' == $meta_type || 'comment' == $meta_type )
     743                        /**
     744                         * Fires after deleting metadata from the database when meta type is 'post'.
     745                         *
     746                         * @since 3.3.0
     747                         *
     748                         * @param array $meta_ids ID of deleted metadata entry.
     749                         */
    508750                        do_action( "deleted_{$meta_type}meta", $meta_id );
    509751
    510752                return $result;
    class WP_Meta_Query { 
    8591101                if ( ! empty( $join ) )
    8601102                        $join = ' ' . $join;
    8611103
     1104                /**
     1105                 * Filter the generated SQL clauses to be appended to a main query.
     1106                 *
     1107                 * @since 3.1.0
     1108                 *
     1109                 * @param array $args {
     1110                 *     Short description about this hash.
     1111                 *
     1112                 *     @type type $var Description.
     1113                 *     @type type $var Description.
     1114                 *     @param string $type Type of meta
     1115                 *     @param string $primary_table
     1116                 *     @param string $primary_id_column
     1117                 *     @param object $context (optional) The main query object
     1118                 *     @return array( 'join' => $join_sql, 'where' => $where_sql
     1119                 * }
     1120                 */
    8621121                return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $this->queries, $type, $primary_table, $primary_id_column, $context ) );
    8631122        }
    8641123}
    function _get_meta_table($type) { 
    8941153function is_protected_meta( $meta_key, $meta_type = null ) {
    8951154        $protected = ( '_' == $meta_key[0] );
    8961155
     1156        /**
     1157         * Filter whether a meta key is protected.
     1158         *
     1159         * @since 3.2.0
     1160         *
     1161         * @param bool $protected True if the key is protected, false otherwise.
     1162         * @param string $meta_key Meta key.
     1163         * @param string $meta_type Type of meta.
     1164         */
    8971165        return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
    8981166}
    8991167
    function is_protected_meta( $meta_key, $meta_type = null ) { 
    9081176 * @return mixed Sanitized $meta_value
    9091177 */
    9101178function sanitize_meta( $meta_key, $meta_value, $meta_type ) {
     1179        /**
     1180         * Filter meta sanitation.
     1181         *
     1182         * @since 3.3.0
     1183         *
     1184         * @param string $meta_type Type of meta.
     1185         * @param string $meta_key Meta key.
     1186         * @param mixed $meta_value Meta value to sanitize.
     1187         */
    9111188        return apply_filters( "sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type );
    9121189}
    9131190