diff --git a/includes/admin/class-wc-accommodation-booking-admin-panels.php b/includes/admin/class-wc-accommodation-booking-admin-panels.php index b8eade1a..138f5323 100644 --- a/includes/admin/class-wc-accommodation-booking-admin-panels.php +++ b/includes/admin/class-wc-accommodation-booking-admin-panels.php @@ -170,7 +170,7 @@ public function save_product_data( $post_id ) { ); foreach ( $meta_to_save as $meta_key => $sanitize ) { - $value = ! empty( $_POST[ $meta_key ] ) ? $_POST[ $meta_key ] : ''; + $value = sanitize_text_field( wp_unslash( $_POST[ $meta_key ] ?? '' ) ); switch ( $sanitize ) { case 'int' : $value = $value ? absint( $value ) : ''; @@ -190,8 +190,6 @@ public function save_product_data( $post_id ) { $value = 1; } break; - default : - $value = sanitize_text_field( $value ); } $meta_key = str_replace( '_wc_accommodation_booking_', '_wc_booking_', $meta_key ); @@ -242,11 +240,34 @@ public function save_product_data( $post_id ) { // Resources if ( isset( $_POST['resource_id'] ) && isset( $_POST['_wc_booking_has_resources'] ) ) { - $resource_ids = $_POST['resource_id']; - $resource_menu_order = $_POST['resource_menu_order']; - $resource_base_cost = $_POST['resource_cost']; - $resource_block_cost = $_POST['resource_block_cost']; - $max_loop = max( array_keys( $_POST['resource_id'] ) ); + $resource_data = filter_input_array( + INPUT_POST, + array( + 'resource_id' => array( + 'filter' => FILTER_VALIDATE_INT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'resource_menu_order' => array( + 'filter' => FILTER_VALIDATE_INT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'resource_cost' => array( + 'filter' => FILTER_VALIDATE_FLOAT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'resource_block_cost' => array( + 'filter' => FILTER_VALIDATE_FLOAT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + ) + ); + $resource_ids = $resource_data['resource_id']; + $resource_menu_order = $resource_data['resource_menu_order']; + $resource_base_cost = $resource_data['resource_cost']; + $resource_block_cost = $resource_data['resource_block_cost']; + + $max_loop = max( array_keys( $resource_ids ) ); + $resource_base_costs = array(); $resource_block_costs = array(); @@ -260,11 +281,11 @@ public function save_product_data( $post_id ) { $wpdb->update( "{$wpdb->prefix}wc_booking_relationships", array( - 'sort_order' => $resource_menu_order[ $i ] + 'sort_order' => absint( $resource_menu_order[ $i ] ), ), array( 'product_id' => $post_id, - 'resource_id' => $resource_id + 'resource_id' => $resource_id, ) ); @@ -314,16 +335,53 @@ public function save_product_data( $post_id ) { // Person Types if ( isset( $_POST['person_id'] ) && isset( $_POST['_wc_booking_has_persons'] ) ) { - $person_ids = $_POST['person_id']; - $person_menu_order = $_POST['person_menu_order']; - $person_name = $_POST['person_name']; - $person_cost = $_POST['person_cost']; - $person_block_cost = $_POST['person_block_cost']; - $person_description = $_POST['person_description']; - $person_min = $_POST['person_min']; - $person_max = $_POST['person_max']; - - $max_loop = max( array_keys( $_POST['person_id'] ) ); + $person_data = filter_input_array( + INPUT_POST, + array( + 'person_id' => array( + 'filter' => FILTER_VALIDATE_INT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_menu_order' => array( + 'filter' => FILTER_VALIDATE_INT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_name' => array( + 'filter' => FILTER_DEFAULT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_cost' => array( + 'filter' => FILTER_VALIDATE_FLOAT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_block_cost' => array( + 'filter' => FILTER_VALIDATE_FLOAT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_description' => array( + 'filter' => FILTER_DEFAULT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_min' => array( + 'filter' => FILTER_VALIDATE_INT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + 'person_max' => array( + 'filter' => FILTER_VALIDATE_INT, + 'flags' => FILTER_REQUIRE_ARRAY, + ), + ) + ); + $person_ids = $person_data['person_id']; + $person_menu_order = $person_data['person_menu_order']; + $person_name = $person_data['person_name']; + $person_cost = $person_data['person_cost']; + $person_block_cost = $person_data['person_block_cost']; + $person_description = $person_data['person_description']; + $person_min = $person_data['person_min']; + $person_max = $person_data['person_max']; + + $max_loop = max( array_keys( $person_ids ) ); for ( $i = 0; $i <= $max_loop; $i ++ ) { if ( ! isset( $person_ids[ $i ] ) ) { @@ -336,21 +394,13 @@ public function save_product_data( $post_id ) { $person_name[ $i ] = sprintf( __( 'Person Type #%d', 'woocommerce-bookings' ), ( $i + 1 ) ); } - $wpdb->update( - $wpdb->posts, + wp_update_post( array( + 'ID' => $person_id, 'post_title' => stripslashes( $person_name[ $i ] ), 'post_excerpt' => stripslashes( $person_description[ $i ] ), - 'menu_order' => $person_menu_order[ $i ] ), - array( - 'ID' => $person_id - ), - array( - '%s', - '%s', - '%d' - ), - array( '%d' ) + 'menu_order' => $person_menu_order[ $i ], + ) ); update_post_meta( $person_id, 'cost', wc_clean( $person_cost[ $i ] ) ); diff --git a/includes/admin/class-wc-accommodation-booking-admin-product-settings.php b/includes/admin/class-wc-accommodation-booking-admin-product-settings.php index 63a74d86..4fbc4af9 100644 --- a/includes/admin/class-wc-accommodation-booking-admin-product-settings.php +++ b/includes/admin/class-wc-accommodation-booking-admin-product-settings.php @@ -218,7 +218,7 @@ public function generate_accommodation_time_html( $key, $value ) { - +
@@ -105,8 +105,8 @@
diff --git a/includes/admin/views/html-accommodation-booking-availability.php b/includes/admin/views/html-accommodation-booking-availability.php index f81f9030..85ef82da 100644 --- a/includes/admin/views/html-accommodation-booking-availability.php +++ b/includes/admin/views/html-accommodation-booking-availability.php @@ -9,13 +9,13 @@ $min_date_unit = get_post_meta( $post_id, '_wc_booking_min_date_unit', true ); ?>

- + + + + +

- + + + + +

- - > + + > - \ No newline at end of file + diff --git a/includes/admin/views/html-accommodation-booking-data.php b/includes/admin/views/html-accommodation-booking-data.php index a99bb25c..a7c89239 100644 --- a/includes/admin/views/html-accommodation-booking-data.php +++ b/includes/admin/views/html-accommodation-booking-data.php @@ -62,15 +62,15 @@ $cancel_limit_unit = get_post_meta( $post_id, '_wc_booking_cancel_limit_unit', true ); ?>

- + - +