Skip to content

Commit 363d96d

Browse files
authored
Merge pull request #54 from Akash-Raj-ST/fix/deprecation-issue
Fix: Add missing properties to class and add VIP phpcs standards
2 parents 45ab6d8 + 095329b commit 363d96d

18 files changed

Lines changed: 94 additions & 74 deletions

.circleci/phpcs.xml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717
<!-- Don't fail in CI if there are warnings. -->
1818
<config name="ignore_warnings_on_exit" value="1" />
1919

20-
<!-- Only worry about WordPress 5.0+. -->
21-
<config name="minimum_supported_wp_version" value="5.0" />
20+
<config name="minimum_supported_wp_version" value="6.6" />
2221

2322
<rule ref="WordPress">
2423
<exclude name="WordPress.WhiteSpace.PrecisionAlignment.Found" />
2524
</rule>
2625

27-
<rule ref="WordPress-Core"></rule>
26+
<rule ref="WordPress-Extra" />
27+
<rule ref="WordPress-VIP-Go" />
2828

29-
<rule ref="WordPress-VIP">
30-
<exclude name="WordPress.VIP.SuperGlobalInputUsage" />
31-
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog" />
32-
<exclude name="WordPress.VIP.RestrictedFunctions.get_page_by_title" />
33-
<exclude name="WordPress.VIP.RestrictedFunctions.get_page_by_title_get_page_by_title" />
29+
<rule ref="WordPress-Core">
30+
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
31+
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
3432
</rule>
3533

34+
<config name="testVersion" value="8.3-" />
35+
36+
<arg name="extensions" value="php"/>
37+
<arg value="sp"/>
38+
3639
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
3740
<exclude-pattern>/lib/*</exclude-pattern>
3841
<exclude-pattern>/src/*</exclude-pattern>

src/class-wordpress-options-panels.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class WordPress_Options_Panels {
2929
*/
3030
public $installed_url;
3131

32+
/**
33+
* Asset Directory URL
34+
*
35+
* @var string
36+
*/
37+
public $asset_dir_url = null;
38+
3239
/**
3340
* Load files required to use this utility.
3441
*
@@ -43,15 +50,15 @@ public function __construct(
4350
$plugin_basedir,
4451
$asset_dir_url = null
4552
) {
46-
$current_dir = dirname( __FILE__ );
53+
$current_dir = __DIR__;
4754
$relative_dir = str_replace( $plugin_basedir . '/', '', $current_dir );
4855

4956
$this->installed_dir = $plugin_basedir . '/' . $relative_dir;
5057
$this->installed_url = $plugins_installed_url . $relative_dir;
5158
$this->asset_dir_url = $asset_dir_url;
5259

5360
// Data api wrappers.
54-
foreach ( glob( trailingslashit( dirname( __FILE__ ) ) . 'inc/api/class-*.php' ) as $file ) {
61+
foreach ( glob( trailingslashit( __DIR__ ) . 'inc/api/class-*.php' ) as $file ) {
5562
include_once $file;
5663
}
5764

@@ -68,7 +75,7 @@ public function __construct(
6875
include_once 'inc/panel-parts/class-section.php';
6976

7077
// Load the individual parts.
71-
foreach ( glob( trailingslashit( dirname( __FILE__ ) ) . 'inc/fields/class-*.php' ) as $file ) {
78+
foreach ( glob( trailingslashit( __DIR__ ) . 'inc/fields/class-*.php' ) as $file ) {
7279
require_once $file;
7380
}
7481

@@ -99,5 +106,4 @@ public function register_page( $options_page_slug, $options_page_type, $parent_m
99106
$this->asset_dir_url
100107
);
101108
}
102-
103109
}

src/inc/api/class-mcrypt.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,4 @@ public static function mcrypt_decrypt( $encrypted_string ) {
105105
);
106106
// @codingStandardsIgnoreEnd
107107
}
108-
109108
}

src/inc/api/class-part.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function maybe_process_update() {
158158
if ( ! isset( $_POST['_wpnonce'] ) ) {
159159
return false;
160160
}
161-
$wpnonce = ( isset( $_POST['submit'] ) && isset( $_POST['_wpnonce'] ) ) ? filter_input( INPUT_POST, '_wpnonce' ) : null;
161+
$wpnonce = ( isset( $_POST['submit'] ) && isset( $_POST['_wpnonce'] ) ) ? sanitize_text_field( $_POST['_wpnonce'] ) : null;
162162

163163
// Only allow class to be used by panel OR encrypted pwds never updated after insert.
164164
if ( empty( $wpnonce ) || wp_verify_nonce( $wpnonce ) ) {
@@ -251,31 +251,32 @@ public function input_value( $type, $established_data, $use_data_value = false )
251251
* @return bool|string
252252
*/
253253
public function run_save_process() {
254-
$nonce = ( isset( $_POST['submit'] ) && isset( $_POST['_wpnonce'] ) ) ? filter_input( INPUT_POST, '_wpnonce' ) : null;
254+
$nonce = ( isset( $_POST['submit'] ) && isset( $_POST['_wpnonce'] ) ) ? sanitize_text_field( $_POST['_wpnonce'] ) : null;
255255
$page_slug_as_action = $this->section->panel->page->slug;
256256
if ( empty( $nonce ) || false === wp_verify_nonce( $nonce, $page_slug_as_action ) ) {
257257
return false; // Only run logic if asked to run & auth'd by nonce.
258258
}
259259

260260
$type = ( ! empty( $this->field_type ) ) ? $this->field_type : $this->input_type;
261261

262-
$field_input = isset( $_POST[ $this->id ] ) ? filter_input( INPUT_POST, $this->id ) : false;
262+
$field_input = isset( $_POST[ $this->id ] ) ? sanitize_text_field( $_POST[ $this->id ] ) : false;
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
/**
@@ -310,7 +311,7 @@ protected function sanitize_data_input( $input_type, $id, $value ) {
310311
if ( ! isset( $_POST['_wpnonce'] ) ) {
311312
return false;
312313
}
313-
$wpnonce = ( isset( $_POST['submit'] ) && isset( $_POST['_wpnonce'] ) ) ? filter_input( INPUT_POST, '_wpnonce' ) : null;
314+
$wpnonce = ( isset( $_POST['submit'] ) && isset( $_POST['_wpnonce'] ) ) ? sanitize_text_field( $_POST['_wpnonce'] ) : null;
314315

315316
// Only allow class to be used by panel OR encrypted pwds never updated after insert.
316317
if ( empty( $wpnonce ) || wp_verify_nonce( $wpnonce ) ) {
@@ -319,7 +320,7 @@ protected function sanitize_data_input( $input_type, $id, $value ) {
319320

320321
switch ( $input_type ) {
321322
case 'password':
322-
$hidden_pwd_field = isset( $_POST[ 'stored_' . $id ] ) ? filter_input( INPUT_POST, 'stored_' . $id ) : null;
323+
$hidden_pwd_field = isset( $_POST[ 'stored_' . $id ] ) ? sanitize_text_field( $_POST[ 'stored_' . $id ] ) : null;
323324

324325
if ( $hidden_pwd_field === $value && ! empty( $value ) ) {
325326
return '### wpop-encrypted-pwd-field-val-unchanged ###';
@@ -357,5 +358,4 @@ protected function sanitize_data_input( $input_type, $id, $value ) {
357358
* Render is an output placeholder for sub parts.
358359
*/
359360
abstract public function render();
360-
361361
}

src/inc/api/class-read.php

Lines changed: 7 additions & 13 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
/**
@@ -106,5 +101,4 @@ public function get_data() {
106101
break;
107102
}
108103
}
109-
110104
}

src/inc/api/class-update.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@
1515
*/
1616
class Update {
1717
/**
18-
* Update constructor.
18+
* Save data wrapper for nonce check.
1919
*
2020
* @param string $page_slug Page URL.
2121
* @param string $type Type.
2222
* @param string $key Key.
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;
3133
}
32-
$wpnonce = isset( $_POST['_wpnonce'] ) ? filter_input( INPUT_POST, '_wpnonce' ) : null;
34+
$wpnonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : null;
3335

3436
// Only allow class to be used by panel OR encrypted pwds never updated after insert.
3537
if ( ! wp_verify_nonce( $wpnonce, $page_slug ) || '### wpop-encrypted-pwd-field-val-unchanged ###' === $value ) {
@@ -150,5 +152,4 @@ private static function handle_term_meta_save( $id, $key, $value ) {
150152
private static function handle_post_meta_save( $id, $key, $value ) {
151153
return empty( $value ) ? delete_post_meta( $id, $key ) : update_post_meta( $id, $key, $value );
152154
}
153-
154155
}

src/inc/class-page.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ class Page {
113113
*/
114114
public $installed_dir_uri = null;
115115

116+
/**
117+
* Asset Directory URL
118+
*
119+
* @var string
120+
*/
121+
public $asset_dir_url = null;
122+
123+
/**
124+
* Menu Position
125+
*
126+
* @var int|float
127+
*/
128+
public $position = null;
129+
116130
/**
117131
* Update Counts
118132
*
@@ -225,8 +239,12 @@ public function build_parts() {
225239
/**
226240
* Print WordPress Notices with Panel Information
227241
*/
228-
if ( ! empty( filter_input( INPUT_GET, 'submit' ) ) ) {
229-
$this->echo_notifications();
242+
if ( isset( $_GET['submit'] ) && isset( $_GET['_wpnonce'] ) ) {
243+
$nonce = sanitize_text_field( $_GET['_wpnonce'] );
244+
245+
if ( wp_verify_nonce( $nonce, $this->slug ) ) {
246+
$this->echo_notifications();
247+
}
230248
}
231249

232250
$this->page_header();
@@ -319,7 +337,7 @@ public function page_footer() {
319337
do_action( 'wpop_page_footer' );
320338
?>
321339
<ul>
322-
<li>Stored in: <code><?php echo esc_attr( $this->get_storage_table() ); ?></code></li>
340+
<li>Stored in: <code><?php echo esc_html( $this->get_storage_table() ); ?></code></li>
323341
</ul>
324342
</div>
325343
</div>

src/inc/fields/class-checkbox.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ public function render() {
6363
</div>
6464
<?php
6565
}
66-
6766
}

src/inc/fields/class-include-partial.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ public function render() {
5757
</li>
5858
<?php
5959
}
60-
6160
}

src/inc/fields/class-media.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ class="button button-hero img-upload"
8383
</a>
8484
<?php
8585
}
86-
8786
}

0 commit comments

Comments
 (0)