Skip to content

Commit cc92392

Browse files
committed
fix: Refactor Update class and improve data sanitization in various classes
1 parent 22f474a commit cc92392

6 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/inc/api/class-part.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,20 @@ public function run_save_process() {
263263

264264
$sanitize_input = $this->sanitize_data_input( $type, $this->id, $field_input );
265265

266-
$updated = new Update(
266+
$update_obj = new Update();
267+
$updated = $update_obj->get_save_data(
267268
$this->section->panel->page->slug, // Used to check nonce.
268269
$this->data_api, // Doing this way to allow multi-api saving from single section down-the-road.
269270
$this->id, // This is the data storage key in the database.
270271
$sanitize_input, // Sanitized input (maybe empty, triggering delete).
271272
isset( $this->obj_id ) ? $this->obj_id : null // Maybe an object ID needed for metadata API.
272273
);
273274

274-
if ( $updated ) {
275-
return $this->id;
275+
if ( empty( $updated ) || is_wp_error( $updated ) ) {
276+
return false;
276277
}
277278

278-
return false;
279+
return $this->id;
279280
}
280281

281282
/**

src/inc/api/class-read.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,21 @@ class Read {
5353
/**
5454
* Read constructor.
5555
*
56-
* @param string $panel_id Panel ID is a string slug.
57-
* @param string $type Type.
58-
* @param string $key Key.
59-
* @param null $default Default.
60-
* @param null $obj_id Object ID.
61-
* @param bool $single Is single object type status.
62-
*
63-
* @return array|int|string|null|bool
56+
* @param string $panel_id Panel ID is a string slug.
57+
* @param string $type Type.
58+
* @param string $key Key.
59+
* @param null $default_val Default.
60+
* @param null $obj_id Object ID.
61+
* @param bool $single Is single object type status.
6462
*/
65-
public function __construct( $panel_id, $type, $key, $default = null, $obj_id = null, $single = true ) {
63+
public function __construct( $panel_id, $type, $key, $default_val = null, $obj_id = null, $single = true ) {
6664
$this->type = $type;
6765
$this->key = $key;
6866
$this->obj_id = $obj_id;
6967
$this->single = $single;
7068

7169
// 1. Data API switchboard
7270
$this->get_data();
73-
74-
// 2. Return data for use by field.
75-
return $this->response;
7671
}
7772

7873
/**

src/inc/api/class-update.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ class Update {
2323
* @param string $value Value.
2424
* @param null $obj_id Object ID.
2525
* @param bool $autoload Autoload status.
26+
*
27+
* @return bool|int|\WP_Error
2628
*/
27-
public function __construct( $page_slug, $type, $key, $value, $obj_id = null, $autoload = true ) {
29+
public function get_save_data( $page_slug, $type, $key, $value, $obj_id = null, $autoload = true ) {
2830
// Confirms both that POST is happening and that _wpnonce was sent, otherwise returns false to not try updates.
2931
if ( ! isset( $_POST['_wpnonce'] ) ) {
3032
return false;

src/inc/class-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public function page_footer() {
333333
do_action( 'wpop_page_footer' );
334334
?>
335335
<ul>
336-
<li>Stored in: <code><?php echo esc_attr( $this->get_storage_table() ); ?></code></li>
336+
<li>Stored in: <code><?php echo esc_html( $this->get_storage_table() ); ?></code></li>
337337
</ul>
338338
</div>
339339
</div>

src/inc/fields/class-multiselect.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,21 @@ public function run_save_process() {
8787
$field_input = isset( $_POST[ $this->id ] ) ? filter_input( INPUT_POST, $this->id, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) : false;
8888

8989
$sanitize_input = $this->sanitize_data_input( $type, $this->id, $field_input );
90-
$updated = new Update(
90+
91+
$update_obj = new Update();
92+
$updated = $update_obj->get_save_data(
9193
$this->section->panel->page->slug, // Used to check nonce.
9294
$this->data_api, // Doing this way to allow multi-api saving from single panel down-the-road.
9395
$this->id, // This is the data storage key in the database.
9496
$sanitize_input, // Sanitized input (maybe empty, triggering delete).
9597
isset( $this->obj_id ) ? $this->obj_id : null // Maybe an object ID needed for metadata API.
9698
);
9799

98-
if ( $updated ) {
99-
return $this->id;
100+
if ( empty( $updated ) || is_wp_error( $updated ) ) {
101+
return false;
100102
}
101103

102-
return false;
104+
return $this->id;
103105
}
104106

105107
/**

src/inc/page-parts/class-panel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function content_sidebar() {
160160
foreach ( $this->parts as $key => $section ) :
161161
?>
162162
<li id="<?php echo esc_attr( $section->slug . '-nav' ); ?>" class="pure-menu-item">
163-
<a href="<?php echo esc_attr( '#' . $section->slug ); ?>" class="pure-menu-link">
163+
<a href="<?php echo esc_url( '#' . $section->slug ); ?>" class="pure-menu-link">
164164
<?php if ( ! empty( $section->dashicon ) ) : ?>
165165
<span class="dashicons <?php echo sanitize_html_class( $section->dashicon ); ?> menu-icon"></span>
166166
<?php endif; ?>
@@ -308,9 +308,9 @@ public function get_clean_classname() {
308308
public function callback_footer_html() {
309309
?>
310310
<ul>
311-
<li>Sections: <code><?php echo esc_attr( $this->section_count ); ?></code></li>
312-
<li>Total Data Parts: <code><?php echo esc_attr( $this->data_count ); ?></code></li>
313-
<li>Total Parts: <code><?php echo esc_attr( $this->part_count ); ?></code></li>
311+
<li>Sections: <code><?php echo esc_html( $this->section_count ); ?></code></li>
312+
<li>Total Data Parts: <code><?php echo esc_html( $this->data_count ); ?></code></li>
313+
<li>Total Parts: <code><?php echo esc_html( $this->part_count ); ?></code></li>
314314
</ul>
315315
<?php
316316
}

0 commit comments

Comments
 (0)