Make WordPress Core

Opened 8 years ago

Closed 5 years ago

Last modified 5 years ago

#37626 closed enhancement (maybelater)

Filter for _list_meta_row function to show the serialized array/object in the admin

Reported by: implenton's profile implenton Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: Posts, Post Types Keywords:
Focuses: administration Cc:

Description

At the moment when the meta_value is a serialized object or array it does not show up in the Admin Custom Fields.

While I understand that editing a serialized array/object is not the same as editing a string, I also find it useful to quickly peek at the meta value.

If the rationality behind this decision was not letting the user edit by mistake the serialized value, then by using a filter we could show the meta row with the textarea field set with the readonly attribute.

https://cldup.com/W-7mNEs_Vk.png

Something like this:

wp-admin/includes/template.php:544

$skip_serialized_array_or_object_on_list_meta_row = apply_filters( 'skip_serialized_array_or_object_on_list_meta_row', '__return_true' );

if ( true == $skip_serialized_array_or_object_on_list_meta_row ) {
    --$count;
    return '';
}

and adding the readonly attribute for the textarea

if ( is_serialized( $entry['meta_value'] ) && ! is_serialized_string( $entry['meta_value'] ) ) {

    $skip_serialized_array_or_object_on_list_meta_row = apply_filters( 'skip_serialized_array_or_object_on_list_meta_row', '__return_true' );

    if ( true == $skip_serialized_array_or_object_on_list_meta_row ) {

        $r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __( 'Value' ) . "</label><textarea readonly name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";

    }

} else {

    $r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";

}

This implementation is just a quick prototype. In case this is considered by the community something useful, then I could provide some variations or somebody else.

Change History (4)

#1 @implenton
8 years ago

Just remembered, what I am suggesting is not something that is esoteric or unknown for WordPress, in wp-admin/options.php when the data is a serialized array/object you get "SERIALIZED DATA" with a disabled input.

What I am looking for is an option for something like this, but instead the "SERIALIZED DATA" the real data.

This ticket was mentioned in Slack in #core by noisysocks. View the logs.


5 years ago

#3 follow-up: @whyisjake
5 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

@implenton Thanks for contributing this ticket. While a great idea, there are some practical problems here with how a user could interact with unserialized data that needs to be serialized again before it hits the DB.

A misplaced comma, quote, or more could destroy the data. Going to close with a wontfix. For those that want to take it further, I would look into the https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/ API.

#4 in reply to: ↑ 3 @SergeyBiryukov
5 years ago

  • Component changed from General to Posts, Post Types
  • Resolution changed from wontfix to maybelater

Replying to whyisjake:

A misplaced comma, quote, or more could destroy the data.

Hence the suggested readonly attribute on the input. If understand the ticket correctly, it's not about editing the value, but about viewing it.

Changing the resolution to maybelater in case someone wants to pick this up.

Note: See TracTickets for help on using tickets.