Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add label argument to register_meta function #7298

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wp-includes/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,7 @@ function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype =
* the meta key will be registered on the entire object type. Default empty.
* @type string $type The type of data associated with this meta key.
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
* @type string $label A human-readable label of the data attached to this meta key.
SantosGuillamot marked this conversation as resolved.
Show resolved Hide resolved
* @type string $description A description of the data attached to this meta key.
* @type bool $single Whether the meta key has one value per object, or an array of values per object.
* @type mixed $default The default value returned from get_metadata() if no value has been set yet.
Expand Down Expand Up @@ -1411,6 +1412,7 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) {
$defaults = array(
'object_subtype' => '',
'type' => 'string',
'label' => '',
'description' => '',
'default' => '',
'single' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ protected function get_registered_fields() {

$default_schema = array(
'type' => $default_args['type'],
'label' => empty( $args['label'] ) ? '' : $args['label'],
gziolo marked this conversation as resolved.
Show resolved Hide resolved
'description' => empty( $args['description'] ) ? '' : $args['description'],
'default' => isset( $args['default'] ) ? $args['default'] : null,
);
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/tests/meta/registerMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function test_register_meta_with_post_object_type_populates_wp_meta_keys(
'' => array(
'flight_number' => array(
'type' => 'string',
'label' => '',
'description' => '',
'single' => false,
'sanitize_callback' => null,
Expand All @@ -117,6 +118,7 @@ public function test_register_meta_with_term_object_type_populates_wp_meta_keys(
'' => array(
'category_icon' => array(
'type' => 'string',
'label' => '',
'description' => '',
'single' => false,
'sanitize_callback' => null,
Expand Down Expand Up @@ -172,6 +174,7 @@ public function test_register_meta_with_current_sanitize_callback_populates_wp_m
'' => array(
'flight_number' => array(
'type' => 'string',
'label' => '',
'description' => '',
'single' => false,
'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ),
Expand Down Expand Up @@ -256,6 +259,16 @@ public function test_get_registered_meta_keys_with_invalid_type_is_empty() {
$this->assertEmpty( $meta_keys );
}

public function test_get_registered_meta_keys_label_arg() {
SantosGuillamot marked this conversation as resolved.
Show resolved Hide resolved
register_meta( 'post', 'registered_key1', array( 'label' => 'Field label' ) );

$meta_keys = get_registered_meta_keys( 'post' );

unregister_meta_key( 'post', 'registered_key1' );

$this->assertSame( 'Field label', $meta_keys['registered_key1']['label'] );
}

public function test_get_registered_meta_keys_description_arg() {
register_meta( 'post', 'registered_key1', array( 'description' => 'I\'m just a field, take a good look at me' ) );

Expand Down Expand Up @@ -340,6 +353,7 @@ public function test_register_meta_with_subtype_populates_wp_meta_keys( $type, $
$subtype => array(
'flight_number' => array(
'type' => 'string',
'label' => '',
'description' => '',
'single' => false,
'sanitize_callback' => null,
Expand Down Expand Up @@ -394,6 +408,7 @@ public function test_unregister_meta_without_subtype_keeps_subtype_meta_key( $ty
$subtype => array(
'flight_number' => array(
'type' => 'string',
'label' => '',
'description' => '',
'single' => false,
'sanitize_callback' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function test_should_register_persisted_preferences_meta() {
$this->assertSame(
array(
'type' => 'object',
'label' => '',
'description' => '',
'single' => true,
'sanitize_callback' => null,
Expand Down
Loading