@@ -43,13 +43,18 @@ function perflab_add_server_timing_page() {
4343 * @since n.e.x.t
4444 */
4545function perflab_load_server_timing_page () {
46+ /*
47+ * This settings section technically includes a field, however it is directly rendered as part of the section
48+ * callback due to requiring custom markup.
49+ */
4650 add_settings_section (
4751 'output-buffering ' ,
4852 __ ( 'Output Buffering ' , 'performance-lab ' ),
49- 'perflab_render_server_timing_page_output_buffer_checkbox ' ,
53+ 'perflab_render_server_timing_page_output_buffering_section ' ,
5054 PERFLAB_SERVER_TIMING_SCREEN
5155 );
5256
57+ // Minor style tweaks to improve appearance similar to other core settings screen instances.
5358 add_action (
5459 'admin_print_styles ' ,
5560 static function () {
@@ -58,26 +63,8 @@ static function () {
5863 .wrap p {
5964 max-width: 800px;
6065 }
61-
62- /* The following styles are copied from core where they normally include `.form-table td` in the selectors. */
63- .output-buffering-field {
64- margin-bottom: 9px;
65- padding-bottom: 15px;
66- line-height: 1.3;
67- vertical-align: middle;
68- font-size: 14px;
69- }
70- .output-buffering-field label,
71- .output-buffering-field p {
72- line-height: 1.4;
73- }
74- .output-buffering-field label {
75- margin: 0.35em 0 0.5em !important;
76- display: inline-block;
77- vertical-align: middle;
78- }
79- .output-buffering-field p {
80- font-size: 14px;
66+ .wrap .form-table .td-full {
67+ padding-top: 0;
8168 }
8269 </style>
8370 <?php
@@ -214,59 +201,69 @@ class="large-text code"
214201}
215202
216203/**
217- * Renders a checkbox for enabling output buffering for Server-Timing.
204+ * Renders the section for enabling output buffering for Server-Timing.
218205 *
219206 * @since n.e.x.t
220207 */
221- function perflab_render_server_timing_page_output_buffer_checkbox () {
208+ function perflab_render_server_timing_page_output_buffering_section () {
222209 $ slug = 'output_buffering ' ;
223210 $ field_id = "server_timing_ {$ slug }" ;
224211 $ field_name = PERFLAB_SERVER_TIMING_SETTING . '[ ' . $ slug . '] ' ;
225212 $ description_id = "{$ field_id }_description " ;
226213 $ has_filter = has_filter ( 'perflab_server_timing_use_output_buffer ' );
227214 $ is_enabled = perflab_server_timing_use_output_buffer ();
228215
216+ /*
217+ * The hard-coded .form-table output here overall matches the WordPress core markup generated by
218+ * `do_settings_sections()` and `do_settings_fields()`, however since it is impossible to modify the CSS classes on
219+ * the `<td>` elements, it needs to be hard-coded to achieve the same appearance as e.g. the UI control for the
220+ * `uploads_use_yearmonth_folders` option in the _Settings > Media_ screen, which is hard-coded as well.
221+ */
229222 ?>
230- <div class="output-buffering-field">
231- <input
232- type="checkbox"
233- id="<?php echo esc_attr ( $ field_id ); ?> "
234- name="<?php echo esc_attr ( $ field_name ); ?> "
235- aria-describedby="<?php echo esc_attr ( $ description_id ); ?> "
236- <?php disabled ( $ has_filter ); ?>
237- <?php checked ( $ is_enabled ); ?>
238- >
239- <label for="<?php echo esc_attr ( $ field_id ); ?> ">
240- <?php esc_html_e ( 'Enable output buffering of template rendering. ' , 'performance-lab ' ); ?>
241- </label>
242- <p id="<?php echo esc_attr ( $ description_id ); ?> " class="description">
243- <?php if ( $ has_filter ) : ?>
244- <?php if ( $ is_enabled ) : ?>
245- <?php
246- echo wp_kses (
247- sprintf (
248- /* translators: %s: perflab_server_timing_use_output_buffer */
249- __ ( 'Output buffering has been forcibly enabled via the %s filter. ' , 'performance-lab ' ),
250- '<code>perflab_server_timing_use_output_buffer</code> '
251- ),
252- array ( 'code ' => array () )
253- );
254- ?>
255- <?php else : ?>
256- <?php
257- echo wp_kses (
258- sprintf (
259- /* translators: %s: perflab_server_timing_use_output_buffer */
260- __ ( 'Output buffering has been forcibly disabled via the %s filter. ' , 'performance-lab ' ),
261- '<code>perflab_server_timing_use_output_buffer</code> '
262- ),
263- array ( 'code ' => array () )
264- );
265- ?>
266- <?php endif ; ?>
267- <?php endif ; ?>
268- <?php esc_html_e ( 'Output buffering is needed to capture metrics after headers have been sent and while the template is being rendered. Note that output buffering may possibly cause an increase in TTFB if the response would be flushed multiple times. ' , 'performance-lab ' ); ?>
269- </p>
270- </div>
223+ <table class="form-table" role="presentation">
224+ <tr>
225+ <td class="td-full">
226+ <label for="<?php echo esc_attr ( $ field_id ); ?> ">
227+ <input
228+ type="checkbox"
229+ id="<?php echo esc_attr ( $ field_id ); ?> "
230+ name="<?php echo esc_attr ( $ field_name ); ?> "
231+ aria-describedby="<?php echo esc_attr ( $ description_id ); ?> "
232+ <?php disabled ( $ has_filter ); ?>
233+ <?php checked ( $ is_enabled ); ?>
234+ >
235+ <?php esc_html_e ( 'Enable output buffering of template rendering. ' , 'performance-lab ' ); ?>
236+ </label>
237+ <p id="<?php echo esc_attr ( $ description_id ); ?> " class="description">
238+ <?php if ( $ has_filter ) : ?>
239+ <?php if ( $ is_enabled ) : ?>
240+ <?php
241+ echo wp_kses (
242+ sprintf (
243+ /* translators: %s: perflab_server_timing_use_output_buffer */
244+ __ ( 'Output buffering has been forcibly enabled via the %s filter. ' , 'performance-lab ' ),
245+ '<code>perflab_server_timing_use_output_buffer</code> '
246+ ),
247+ array ( 'code ' => array () )
248+ );
249+ ?>
250+ <?php else : ?>
251+ <?php
252+ echo wp_kses (
253+ sprintf (
254+ /* translators: %s: perflab_server_timing_use_output_buffer */
255+ __ ( 'Output buffering has been forcibly disabled via the %s filter. ' , 'performance-lab ' ),
256+ '<code>perflab_server_timing_use_output_buffer</code> '
257+ ),
258+ array ( 'code ' => array () )
259+ );
260+ ?>
261+ <?php endif ; ?>
262+ <?php endif ; ?>
263+ <?php esc_html_e ( 'Output buffering is needed to capture metrics after headers have been sent and while the template is being rendered. Note that output buffering may possibly cause an increase in TTFB if the response would be flushed multiple times. ' , 'performance-lab ' ); ?>
264+ </p>
265+ </td>
266+ </tr>
267+ </table>
271268 <?php
272269}
0 commit comments