diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index c657c6c2e7af3..12cb518bbeaaa 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -120,12 +120,14 @@ function add_metadata( $meta_type, $object_id, $meta_key, $meta_value, $unique = * - `add_user_meta` * * @since 3.1.0 + * @since 7.2.0 The `$unique` parameter was added. * * @param int $object_id ID of the object metadata is for. * @param string $meta_key Metadata key. * @param mixed $_meta_value Metadata value. + * @param bool $unique Whether the specified meta key should be unique for the object. */ - do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value ); + do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value, $unique ); $result = $wpdb->insert( $table, @@ -159,13 +161,15 @@ function add_metadata( $meta_type, $object_id, $meta_key, $meta_value, $unique = * - `added_user_meta` * * @since 2.9.0 + * @since 7.2.0 The `$unique` parameter was added. * - * @param int $mid The meta ID after successful update. + * @param int $mid The meta ID after successful addition. * @param int $object_id ID of the object metadata is for. * @param string $meta_key Metadata key. * @param mixed $_meta_value Metadata value. + * @param bool $unique Whether the specified meta key should be unique for the object. */ - do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); + do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value, $unique ); return $mid; } diff --git a/tests/phpunit/tests/meta/addMetadata.php b/tests/phpunit/tests/meta/addMetadata.php new file mode 100644 index 0000000000000..bc9379aa700a4 --- /dev/null +++ b/tests/phpunit/tests/meta/addMetadata.php @@ -0,0 +1,43 @@ +get_args(); + $added_args = $added_action->get_args(); + + $this->assertSame( $unique, $add_args[0][3], 'The add_post_meta action should receive the value of $unique.' ); + $this->assertSame( $unique, $added_args[0][4], 'The added_post_meta action should receive the value of $unique.' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_actions_should_receive_unique() { + return array( + 'unique meta' => array( true ), + 'non-unique meta' => array( false ), + ); + } +}