WordPress.org

Make WordPress Core

Ticket #43941: 43941.17.diff

File 43941.17.diff, 5.7 KB (added by SergeyBiryukov, 5 months ago)
  • src/wp-includes/meta.php

     
    508508                return $value;
    509509        }
    510510
    511         return get_metadata_default( $meta_type, $meta_key, $single, $object_id );
     511        return get_metadata_default( $meta_type, $object_id, $meta_key, $single );
    512512}
    513513
    514514/**
     
    544544         * Returning a non-null value will effectively short-circuit the function.
    545545         *
    546546         * @since 3.1.0
     547         * @since 5.5.0 Added the `$meta_type` parameter.
    547548         *
    548549         * @param mixed  $value     The value to return, either a single metadata value or an array
    549550         *                          of values depending on the value of `$single`. Default null.
     
    550551         * @param int    $object_id ID of the object metadata is for.
    551552         * @param string $meta_key  Metadata key.
    552553         * @param bool   $single    Whether to return only the first value of the specified `$meta_key`.
     554         * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
     555         *                          or any other object type with an associated meta table.
    553556         */
    554         $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
     557        $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single, $meta_type );
    555558        if ( null !== $check ) {
    556559                if ( $single && is_array( $check ) ) {
    557560                        return $check[0];
     
    595598 *
    596599 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
    597600 *                          or any other object type with an associated meta table.
    598  * @param string $meta_key  Metadata key.
     601 * @param int    $object_id ID of the object metadata is for.
     602 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
     603 *                          the specified object. Default empty.
    599604 * @param bool   $single    Optional. If true, return only the first value of the specified meta_key.
    600605 *                          This parameter has no effect if meta_key is not specified. Default false.
    601  * @param int    $object_id Optional. ID of the object metadata is for. Default 0.
    602606 * @return mixed Single metadata value, or array of values.
    603607 */
    604 function get_metadata_default( $meta_type, $meta_key, $single = false, $object_id = 0 ) {
     608function get_metadata_default( $meta_type, $object_id, $meta_key = '', $single = false ) {
    605609        if ( $single ) {
    606610                $value = '';
    607611        } else {
     
    618622         *
    619623         * @param mixed  $value     The value to return, either a single metadata value or an array
    620624         *                          of values depending on the value of `$single`.
     625         * @param int    $object_id ID of the object metadata is for.
     626         * @param string $meta_key  Metadata key.
     627         * @param bool   $single    Whether to return only the first value of the specified `$meta_key`.
    621628         * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
    622629         *                          or any other object type with an associated meta table.
    623          * @param string $meta_key  Metadata key.
    624          * @param bool   $single    Whether to return only the first value of the specified `$meta_key`.
    625          * @param int    $object_id ID of the object metadata is for.
    626630         */
    627         $value = apply_filters( "default_{$meta_type}_metadata", $value, $meta_type, $meta_key, $single, $object_id );
     631        $value = apply_filters( "default_{$meta_type}_metadata", $value, $object_id, $meta_key, $single, $meta_type );
    628632
    629633        if ( ! $single && ! wp_is_numeric_array( $value ) ) {
    630634                $value = array( $value );
     
    13791383 * @since 5.5.0
    13801384 *
    13811385 * @param mixed  $value     Current value passed to filter.
    1382  * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
    1383  *                          or any other object type with an associated meta table.
     1386 * @param int    $object_id ID of the object metadata is for.
    13841387 * @param string $meta_key  Metadata key.
    13851388 * @param bool   $single    If true, return only the first value of the specified meta_key.
    13861389 *                          This parameter has no effect if meta_key is not specified.
    1387  * @param int    $object_id ID of the object metadata is for.
     1390 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
     1391 *                          or any other object type with an associated meta table.
    13881392 * @return mixed Single metadata default, or array of defaults.
    13891393 */
    1390 function filter_default_metadata( $value, $meta_type, $meta_key, $single, $object_id ) {
     1394function filter_default_metadata( $value, $object_id, $meta_key, $single, $meta_type ) {
    13911395        global $wp_meta_keys;
    13921396
    13931397        if ( wp_installing() ) {
  • tests/phpunit/tests/meta/registerMeta.php

     
    520520
    521521                $object_property_name = $object_type . '_id';
    522522                $object_id            = self::$$object_property_name;
    523                 $default_value        = get_metadata_default( $object_type, $meta_key, $single, $object_id );
     523                $default_value        = get_metadata_default( $object_type, $object_id, $meta_key, $single );
    524524                $this->assertSame( $default_value, $expected );
    525525
    526526                // Check for default value.
     
    567567
    568568                $object_property_name = $object_type . '_id';
    569569                $object_id            = self::$$object_property_name;
    570                 $default_value        = get_metadata_default( $object_type, $meta_key, $single, $object_id );
     570                $default_value        = get_metadata_default( $object_type, $object_id, $meta_key, $single );
    571571                $this->assertSame( $default_value, $expected );
    572572        }
    573573