-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix #64581 - Display serialized option values instead of placeholder text #10853
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
base: trunk
Are you sure you want to change the base?
fix #64581 - Display serialized option values instead of placeholder text #10853
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| </form> | ||
| </div> | ||
|
|
||
| <script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we place this JavaScript in an external file and load it via wp_enqueue_script() for better maintainability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should first wait for a dev feedback on the feasibility of this overall concept. Then we can talk about the specific details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a native approach instead? Like relying on the <details> tag that basically does the same thing as this JS. I'll give it a try locally later anyway 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patch looks good, but I'm unsure if we want to unserialize the fields. I would stick to raw values thrown into a textarea but maybe_unserialize makes sense if we disable saving.
<details> version is decent enough for debugging purpose, but we can stick to the cooler "Show serialized value" button for a more native look and feel.
...
$value = $option->option_value;
$options_to_update[] = $option->option_name;
$is_serialized = false;
$class = 'all-options';
if ( is_serialized( $option->option_value ) ) {
$disabled = true;
$is_serialized = true;
$class .= ' disabled';
}
$name = esc_attr($option->option_name);
?>
<tr>
<th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html($option->option_name); ?></label></th>
<td>
<?php if ($is_serialized) : ?>
<details name="<?php echo $name; ?>" class="<?php echo $class; ?>">
<summary>SERIALIZED DATA</summary>
<textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5" disabled="disabled"><?php echo esc_textarea( $value ); ?></textarea>
</details>
<?php elseif ( str_contains( $value, "\n" ) ) : ?>
<textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5"><?php echo esc_textarea( $value ); ?></textarea>
<?php else : ?>
<input class="regular-text <?php echo $class; ?>" type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $value ); ?>"<?php disabled( $disabled, true ); ?> />
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>Similarly for network's site-settings.php:
$value = $option->option_value;
$is_serialized = false;
$disabled = false;
$class = 'all-options';
if ( is_serialized( $option->option_value ) ) {
$is_serialized = true;
$disabled = true;
$class .= ' disabled';
}
if ( $is_serialized ) {
?>
<tr class="form-field">
<th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>" class="code"><?php echo esc_html( $option->option_name ); ?></label></th>
<td>
<details name="<?php echo esc_attr( $option->option_name ); ?>" class="<?php echo $class; ?>">
<summary>SERIALIZED DATA</summary>
<textarea class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ); ?>]" id="<?php echo esc_attr( $option->option_name ); ?>" cols="30" rows="5" disabled="disabled"><?php echo esc_textarea( $value ); ?></textarea>
</details>
</td>
</tr>
<?php
} elseif ( str_contains( $value, "\n" ) ) {
?>
<tr class="form-field">
<th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>" class="code"><?php echo esc_html( $option->option_name ); ?></label></th>
<td><textarea class="<?php echo $class; ?>" rows="5" cols="40" name="option[<?php echo esc_attr( $option->option_name ); ?>]" id="<?php echo esc_attr( $option->option_name ); ?>"<?php disabled( $disabled ); ?>><?php echo esc_textarea( $value ); ?></textarea></td>
</tr>
<?php
} else {
?>
<tr class="form-field">
<th scope="row"><label for="<?php echo esc_attr( $option->option_name ); ?>" class="code"><?php echo esc_html( $option->option_name ); ?></label></th>
<?php if ( $is_main_site && in_array( $option->option_name, array( 'siteurl', 'home' ), true ) ) { ?>
<td><code><?php echo esc_html( $value ); ?></code></td>
<?php } else { ?>
<td><input class="<?php echo $class; ?>" name="option[<?php echo esc_attr( $option->option_name ); ?>]" type="text" id="<?php echo esc_attr( $option->option_name ); ?>" value="<?php echo esc_attr( $value ); ?>" size="40" <?php disabled( $disabled ); ?> /></td>
<?php } ?>
</tr>
<?php
}| @@ -438,11 +435,35 @@ | |||
| <tr> | |||
| <th scope="row"><label for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th> | |||
| <td> | |||
| <?php if ( str_contains( $value, "\n" ) ) : ?> | |||
| <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="30" rows="5"><?php echo esc_textarea( $value ); ?></textarea> | |||
| <?php else : ?> | |||
| <input class="regular-text <?php echo $class; ?>" type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $value ); ?>"<?php disabled( $disabled, true ); ?> /> | |||
| <?php endif; ?></td> | |||
| <?php if ( $is_serialized && ( is_array( $value ) || is_object( $value ) ) ) : ?> | |||
| <button | |||
| type="button" | |||
| class="toggle-serialized button button-secondary" | |||
| data-target="opt-<?php echo esc_attr( $name ); ?>"> | |||
| Show (SERIALIZED DATA) | |||
| </button> | |||
|
|
|||
| <pre | |||
| id="opt-<?php echo esc_attr( $name ); ?>" | |||
| style="display:none; margin-top:8px; max-height:300px; overflow:auto; background:#f6f7f7; padding:10px;"> | |||
| <?php echo esc_html( print_r( $value, true ) ); ?> | |||
| </pre> | |||
|
|
|||
| <?php elseif ( str_contains( (string) $value, "\n" ) ) : ?> | |||
| <textarea | |||
| class="<?php echo $class; ?>" | |||
| disabled="disabled" | |||
| cols="30" | |||
| rows="5"><?php echo esc_textarea( $value ); ?></textarea> | |||
|
|
|||
| <?php else : ?> | |||
| <input | |||
| class="regular-text <?php echo $class; ?>" | |||
| type="text" | |||
| value="<?php echo esc_attr( $value ); ?>" | |||
| disabled="disabled" /> | |||
| <?php endif; ?> | |||
|
|
|||
| </tr> | |||
| <?php endforeach; ?> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $value = $option->option_value; | |
| $options_to_update[] = $option->option_name; | |
| $is_serialized = false; | |
| if ( is_serialized( $option->option_value ) ) { | |
| $disabled = true; | |
| $is_serialized = true; | |
| } | |
| $class = 'all-options'; | |
| if ( $disabled ) { | |
| $class .= ' disabled'; | |
| } | |
| $name = esc_attr( $option->option_name ); | |
| ?> | |
| <tr> | |
| <th scope="row"><label | |
| for="<?php echo $name; ?>"><?php echo esc_html( $option->option_name ); ?></label></th> | |
| <td> | |
| <?php if ( $is_serialized ) : ?> | |
| <details name="<?php echo $name; ?>" class="<?php echo $class; ?>"> | |
| <summary>SERIALIZED DATA</summary> | |
| <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" | |
| id="<?php echo $name; ?>" cols="30" rows="5" | |
| disabled="disabled"><?php echo esc_textarea( $value ); ?></textarea> | |
| </details> | |
| <?php elseif ( str_contains( $value, "\n" ) ) : ?> | |
| <textarea class="<?php echo $class; ?>" name="<?php echo $name; ?>" | |
| id="<?php echo $name; ?>" cols="30" | |
| rows="5"><?php echo esc_textarea( $value ); ?></textarea> | |
| <?php else : ?> | |
| <input class="regular-text <?php echo $class; ?>" type="text" name="<?php echo $name; ?>" | |
| id="<?php echo $name; ?>" | |
| value="<?php echo esc_attr( $value ); ?>"<?php disabled( $disabled, true ); ?> /> | |
| <?php endif; ?> | |
| </td> | |
| </tr> | |
| <?php endforeach; ?> |
Fixes https://core.trac.wordpress.org/ticket/64581
This replaces the hard-coded "SERIALIZED DATA" placeholder in
wp-admin/options.phpwith a read-only display of the actualunserialized option value.