Skip to content

Commit b4b484c

Browse files
author
Soare Robert-Daniel
committed
dev: phpcs & phpstan
1 parent b810a35 commit b4b484c

5 files changed

Lines changed: 371 additions & 1364 deletions

File tree

backend/settings-panel.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,15 +947,15 @@ public function is_settings_page() {
947947
/**
948948
* Inserts an item into an array at a fixed position.
949949
*
950-
* @param array $array Source array.
950+
* @param array $items Source array.
951951
* @param array $item Item to insert.
952952
* @param int $position Numeric insertion offset.
953953
*
954954
* @return array
955955
*/
956-
public function insert_at( $array = array(), $item = array(), $position = 0 ) {
957-
$previous_items = array_slice( $array, 0, $position, true );
958-
$next_items = array_slice( $array, $position, null, true );
956+
public function insert_at( $items = array(), $item = array(), $position = 0 ) {
957+
$previous_items = array_slice( $items, 0, $position, true );
958+
$next_items = array_slice( $items, $position, null, true );
959959

960960
return $previous_items + $item + $next_items;
961961
}

inc/admin.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ function ppom_admin_show_notices() {
299299
*/
300300
function ppom_admin_save_form_meta() {
301301

302-
$db_version = floatval( get_option( 'personalizedproduct_db_version' ) );
302+
$db_version = floatval( get_option( 'personalizedproduct_db_version' ) );
303+
$ppom_form_nonce = isset( $_POST['ppom_form_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ppom_form_nonce'] ) ) : '';
303304

304305
if ( $db_version < 22.1 ) {
305306
$resp = array(
@@ -312,8 +313,8 @@ function ppom_admin_save_form_meta() {
312313

313314
// print_r($_REQUEST); exit;
314315

315-
if ( ! isset( $_POST['ppom_form_nonce'] )
316-
|| ! wp_verify_nonce( $_POST['ppom_form_nonce'], 'ppom_form_nonce_action' )
316+
if ( empty( $ppom_form_nonce )
317+
|| ! wp_verify_nonce( $ppom_form_nonce, 'ppom_form_nonce_action' )
317318
|| ! ppom_security_role()
318319
) {
319320
$resp = array(
@@ -482,8 +483,9 @@ function ( $pm ) {
482483
function ppom_admin_update_form_meta() {
483484

484485

485-
$return_page = isset( $_REQUEST['ppom_meta'] ) ? 'ppom-energy' : 'ppom';
486-
$productmeta_id = isset( $_REQUEST['productmeta_id'] ) ? sanitize_text_field( $_REQUEST['productmeta_id'] ) : '';
486+
$return_page = isset( $_REQUEST['ppom_meta'] ) ? 'ppom-energy' : 'ppom';
487+
$productmeta_id = isset( $_REQUEST['productmeta_id'] ) ? sanitize_text_field( $_REQUEST['productmeta_id'] ) : '';
488+
$ppom_form_nonce = isset( $_POST['ppom_form_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ppom_form_nonce'] ) ) : '';
487489

488490
$ppom_args = array(
489491
'page' => $return_page,
@@ -506,8 +508,8 @@ function ppom_admin_update_form_meta() {
506508
}
507509

508510

509-
if ( ! isset( $_POST['ppom_form_nonce'] )
510-
|| ! wp_verify_nonce( $_POST['ppom_form_nonce'], 'ppom_form_nonce_action' )
511+
if ( empty( $ppom_form_nonce )
512+
|| ! wp_verify_nonce( $ppom_form_nonce, 'ppom_form_nonce_action' )
511513
|| ! ppom_security_role()
512514
) {
513515
$resp = array(
@@ -683,8 +685,10 @@ function ppom_admin_update_ppom_meta_only( $ppom_id, $ppom_meta ) {
683685
*/
684686
function ppom_admin_delete_meta() {
685687

686-
if ( ! isset( $_POST['ppom_meta_nonce'] )
687-
|| ! wp_verify_nonce( $_POST['ppom_meta_nonce'], 'ppom_meta_nonce_action' )
688+
$ppom_meta_nonce = isset( $_POST['ppom_meta_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ppom_meta_nonce'] ) ) : '';
689+
690+
if ( empty( $ppom_meta_nonce )
691+
|| ! wp_verify_nonce( $ppom_meta_nonce, 'ppom_meta_nonce_action' )
688692
|| ! ppom_security_role()
689693
) {
690694
$response = array(
@@ -730,8 +734,10 @@ function ppom_admin_delete_meta() {
730734
*/
731735
function ppom_admin_delete_selected_meta() {
732736

733-
if ( ! isset( $_POST['ppom_meta_nonce'] )
734-
|| ! wp_verify_nonce( $_POST['ppom_meta_nonce'], 'ppom_meta_nonce_action' )
737+
$ppom_meta_nonce = isset( $_POST['ppom_meta_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ppom_meta_nonce'] ) ) : '';
738+
739+
if ( empty( $ppom_meta_nonce )
740+
|| ! wp_verify_nonce( $ppom_meta_nonce, 'ppom_meta_nonce_action' )
735741
|| ! ppom_security_role()
736742
|| ! array_key_exists( 'productmeta_ids', $_POST )
737743
|| ! is_array( $_POST['productmeta_ids'] )

inc/validation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,25 @@ function ppom_esc_html( $content ) {
100100
* Keys that allow stored HTML are sanitized with `ppom_esc_html()`. All other
101101
* scalar values are reduced to plain text.
102102
*
103-
* @param array $array Untrusted field-definition array.
103+
* @param array $data Untrusted field-definition array.
104104
*
105105
* @return array
106106
*
107107
* @see ppom_admin_save_form_meta()
108108
* @see ppom_admin_update_form_meta()
109109
*/
110-
function ppom_sanitize_array_data( $array ) {
111-
foreach ( $array as $key => &$value ) {
110+
function ppom_sanitize_array_data( $data ) {
111+
foreach ( $data as $key => &$value ) {
112112
if ( is_array( $value ) ) {
113113
$value = ppom_sanitize_array_data( $value );
114114
} elseif ( in_array( $key, ppom_fields_with_html(), true ) ) {
115-
$value = ppom_esc_html( $value );
115+
$value = ppom_esc_html( $value );
116116
} else {
117117
$value = sanitize_text_field( $value );
118118
}
119119
}
120120

121-
return $array;
121+
return $data;
122122
}
123123

124124

0 commit comments

Comments
 (0)