Skip to content

Commit caf4e65

Browse files
committed
Refactor: Remove unnecessary ob buffering in Settings API, reformat repeater wrapper
- Remove ob_start()/ob_get_clean() from plugin_settings() and show_form() — direct output is sufficient - Reformat repeater wrapper div to multi-line for readability - Extract data attributes into named variables before output
1 parent 727447f commit caf4e65

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

includes/admin/settings/class-settings-api.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,6 @@ public function settings_sanitize( $input ) {
917917
* Render the settings page.
918918
*/
919919
public function plugin_settings() {
920-
ob_start();
921920
?>
922921
<div class="wrap">
923922
<?php do_action( $this->prefix . '_settings_page_header_before' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound ?>
@@ -961,7 +960,6 @@ public function plugin_settings() {
961960
</div><!-- /.wrap -->
962961

963962
<?php
964-
echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
965963
}
966964

967965
/**
@@ -1006,7 +1004,6 @@ public function show_navigation() {
10061004
* This public function displays every sections in a different form
10071005
*/
10081006
public function show_form() {
1009-
ob_start();
10101007
?>
10111008

10121009
<form method="post" action="options.php" id="<?php echo esc_attr( "{$this->prefix}-settings-form" ); ?>">
@@ -1064,7 +1061,6 @@ public function show_form() {
10641061
</form>
10651062

10661063
<?php
1067-
echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
10681064
}
10691065

10701066
/**

includes/admin/settings/class-settings-form.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,19 @@ public function callback_repeater( $args ) {
945945
$attributes .= sprintf( ' %1$s="%2$s"', sanitize_key( $attribute ), esc_attr( $val ) );
946946
}
947947

948+
$data_index = (string) count( $value );
949+
$live_update_field = ! empty( $args['live_update_field'] ) ? $args['live_update_field'] : 'name';
950+
$fallback_title = ! empty( $args['new_item_text'] ) ? $args['new_item_text'] : $this->translation_strings['repeater_new_item'];
951+
948952
ob_start();
949953
?>
950-
<div class="<?php echo esc_attr( $class ); ?> wz-repeater-wrapper" id="<?php echo esc_attr( $args['id'] ); ?>-wrapper" data-index="<?php echo esc_attr( (string) count( $value ) ); ?>" data-live-update-field="<?php echo esc_attr( ! empty( $args['live_update_field'] ) ? $args['live_update_field'] : 'name' ); ?>" data-fallback-title="<?php echo esc_attr( ! empty( $args['new_item_text'] ) ? $args['new_item_text'] : $this->translation_strings['repeater_new_item'] ); ?>" <?php echo $attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
954+
<div class="<?php echo esc_attr( $class ); ?> wz-repeater-wrapper"
955+
id="<?php echo esc_attr( $args['id'] ); ?>-wrapper"
956+
data-index="<?php echo esc_attr( $data_index ); ?>"
957+
data-live-update-field="<?php echo esc_attr( $live_update_field ); ?>"
958+
data-fallback-title="<?php echo esc_attr( $fallback_title ); ?>"
959+
<?php echo $attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
960+
951961
<div class="<?php echo esc_attr( $args['id'] ); ?>-items wz-repeater-items">
952962
<?php
953963
if ( ! empty( $value ) ) {

0 commit comments

Comments
 (0)