WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 5 months ago

#37626 new enhancement

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

Reported by: implenton Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: General Keywords:
Focuses: administration Cc:
PR Number:

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 (1)

#1 @implenton
3 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.

Note: See TracTickets for help on using tickets.