-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.0 code cleanup #456
2.0 code cleanup #456
Changes from all commits
899f944
6bf43de
2c447b8
54aea35
15f831a
5b25d2e
736f34a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,9 @@ class Settings { | |
public function __construct() { | ||
$this->options = tour_operator()->options; | ||
|
||
// @phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
if ( isset( $_GET['welcome-page'] ) ) { | ||
// @phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
$display_page = sanitize_text_field( $_GET['welcome-page'] ); | ||
$display_page = ! empty( $display_page ) ? $display_page : ''; | ||
} | ||
|
@@ -530,8 +532,9 @@ public function save_settings() { | |
if ( 'post_types' !== $section ) { | ||
foreach ( $fields as $key => $field ) { | ||
$save = ''; | ||
// @phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
if ( isset( $_POST[ $key ] ) ) { | ||
$save = $_POST[ $key ]; | ||
$save = sanitize_text_field( $_POST[ $key ] ); | ||
Comment on lines
+535
to
+537
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, ignoring nonce verification is not recommended. It's better to add nonce verification to enhance security. - // @phpcs:ignore WordPress.Security.NonceVerification.Recommended
- if ( isset( $_POST[ $key ] ) ) {
+ if ( isset( $_POST[ $key ] ) && check_admin_referer('post_nonce_action', 'post_nonce_field') ) {
$save = sanitize_text_field( $_POST[ $key ] );
} else if ( isset( $field['default'] ) ) {
$save = $field['default'];
} |
||
} else if ( isset( $field['default'] ) ) { | ||
$save = $field['default']; | ||
} | ||
|
@@ -551,8 +554,9 @@ public function save_settings() { | |
//Loop through each of the fields in the section. | ||
foreach ( $fields as $key => $field ) { | ||
$save = ''; | ||
// @phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
if ( isset( $_POST[ $tab_index . '_' . $key ] ) ) { | ||
$save = $_POST[ $tab_index . '_' . $key ]; | ||
$save = wp_unslash( $_POST[ $tab_index . '_' . $key ] ); | ||
Comment on lines
+557
to
+559
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, ignoring nonce verification is not a good practice. Please consider adding nonce verification. - // @phpcs:ignore WordPress.Security.NonceVerification.Recommended
- if ( isset( $_POST[ $tab_index . '_' . $key ] ) ) {
+ if ( isset( $_POST[ $tab_index . '_' . $key ] ) && check_admin_referer('tab_nonce_action', 'tab_nonce_field') ) {
$save = wp_unslash( $_POST[ $tab_index . '_' . $key ] );
} else if ( isset( $field['default'] ) ) {
$save = $field['default'];
} |
||
} else if ( isset( $field['default'] ) ) { | ||
$save = $field['default']; | ||
} | ||
|
@@ -565,6 +569,7 @@ public function save_settings() { | |
if ( ! empty( $settings_values ) ) { | ||
update_option( 'lsx_to_settings', $settings_values ); | ||
|
||
// @phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
wp_safe_redirect( $_POST[ '_wp_http_referer' ] ); | ||
exit; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,47 +77,47 @@ public function register_block_bindings() { | |
register_block_bindings_source( | ||
'lsx/post-connection', | ||
array( | ||
'label' => __( 'Post Connection', 'lsx-wetu-importer' ), | ||
'label' => __( 'Post Connection', 'tour-operator' ), | ||
'get_value_callback' => array( $this, 'post_connections_callback' ) | ||
) | ||
); | ||
|
||
register_block_bindings_source( | ||
'lsx/post-meta', | ||
array( | ||
'label' => __( 'Post Meta', 'lsx-wetu-importer' ), | ||
'label' => __( 'Post Meta', 'tour-operator' ), | ||
'get_value_callback' => array( $this, 'post_meta_callback' ) | ||
) | ||
); | ||
|
||
register_block_bindings_source( | ||
'lsx/tour-itinerary', | ||
array( | ||
'label' => __( 'Itinerary', 'lsx-wetu-importer' ), | ||
'label' => __( 'Itinerary', 'tour-operator' ), | ||
'get_value_callback' => array( $this, 'empty_callback' ) | ||
) | ||
); | ||
|
||
register_block_bindings_source( | ||
'lsx/accommodation-units', | ||
array( | ||
'label' => __( 'Units', 'lsx-wetu-importer' ), | ||
'label' => __( 'Units', 'tour-operator' ), | ||
'get_value_callback' => array( $this, 'empty_callback' ) | ||
) | ||
); | ||
|
||
register_block_bindings_source( | ||
'lsx/gallery', | ||
array( | ||
'label' => __( 'Gallery', 'lsx-wetu-importer' ), | ||
'label' => __( 'Gallery', 'tour-operator' ), | ||
'get_value_callback' => array( $this, 'empty_callback' ) | ||
) | ||
); | ||
|
||
register_block_bindings_source( | ||
'lsx/map', | ||
array( | ||
'label' => __( 'Map', 'lsx-wetu-importer' ), | ||
'label' => __( 'Map', 'tour-operator' ), | ||
'get_value_callback' => array( $this, 'empty_callback' ) | ||
) | ||
); | ||
|
@@ -474,7 +474,7 @@ public function build_unit_field( $build = '', $field = '', $count = 1 ) { | |
|
||
switch ( $field ) { | ||
case 'title': | ||
$value = strip_tags( $rooms->item_title( '', '', false ) ); | ||
$value = wp_strip_all_tags( $rooms->item_title( '', '', false ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job replacing - $value = strip_tags( $rooms->item_title( '', '', false ) );
+ $value = wp_strip_all_tags( $rooms->item_title( '', '', false ) ); |
||
$pattern = '/(<h[1-6]\s+[^>]*\bclass="[^"]*\bunit-title\b[^"]*"[^>]*>).*?(<\/h[1-6]>)/is'; | ||
break; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,6 +432,7 @@ protected function post_ids_exist( $ids ) { | |
AND ID IN (%s) | ||
AND post_status IN ('draft', 'publish')"; | ||
|
||
// @phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of Instead of ignoring the warning, you should properly prepare the SQL statement. The Here's how you can do it: - AND ID IN (%s)
+ AND ID IN (" . implode(',', array_fill(0, count($ids), '%s')) . ")
- // @phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
- return (int) $wpdb->get_var( $wpdb->prepare( $query, $ids ) );
+ return (int) $wpdb->get_var( $wpdb->prepare( $query, ...$ids ) ); This way, each id in the |
||
return (int) $wpdb->get_var( $wpdb->prepare( $query, $ids ) ); | ||
} | ||
|
||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the use of
@phpcs:ignore WordPress.Security.NonceVerification.Recommended
is understandable to suppress warnings from PHP CodeSniffer, it's not a good practice to ignore nonce verification. Nonce verification is crucial for security as it helps protect against certain types of misuse, malicious or otherwise. Consider adding nonce verification here.