Skip to content

Commit

Permalink
fix: Gallery image restriction was not working
Browse files Browse the repository at this point in the history
  • Loading branch information
devAsadNur committed Dec 20, 2024
1 parent a04c74b commit 0ecb790
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions includes/Dashboard/Templates/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ public function handle_product_update() {
$field_value = $field->sanitize( wp_unslash( $_POST[ $field_name ] ), $original_stock, $product ); //phpcs:ignore
break;

case ProductFormElements::GALLERY_IMAGE_IDS:
$attachment_ids = isset( $_POST['gallery_image_ids'] ) ? apply_filters( 'dokan_restrict_product_gallery_images_on_edit', wp_unslash( $_POST['gallery_image_ids'] ) ) : '';

Check failure on line 494 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of a non-sanitized input variable: $_POST['gallery_image_ids']
$attachment_ids = array_filter( explode( ',', wc_clean( $attachment_ids ) ) );
$field_value = $field->sanitize( implode( ',', $attachment_ids ), $product ); //phpcs:ignore
break;

default:
// give a chance to other plugins to sanitize their data
$field_value = apply_filters( 'dokan_product_update_field_value', null, $field, wp_unslash( $_POST[ $field_name ] ), $product ); // phpcs:ignore
Expand Down
12 changes: 6 additions & 6 deletions includes/wc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function dokan_process_product_meta( int $post_id, array $data = [] ) {
update_post_meta( $post_id, '_virtual', $is_virtual );

// Gallery Images
if ( isset( $data['product_image_gallery'] ) ) {
$data = apply_filters( 'dokan_restrict_product_image_gallery_on_edit', $data );
if ( isset( $data['gallery_image_ids'] ) ) {
$data = apply_filters( 'dokan_restrict_product_gallery_images_on_edit', wp_unslash( $data['gallery_image_ids'] ) );

$attachment_ids = array_filter( explode( ',', wc_clean( $data['product_image_gallery'] ) ) );
$attachment_ids = array_filter( explode( ',', wc_clean( $data ) ) );
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) );
}

Expand Down Expand Up @@ -302,7 +302,7 @@ function ( $value ) {
$manage_stock = $data['_manage_stock'];
$backorders = wc_clean( $data['_backorders'] );
}

update_post_meta( $post_id, '_manage_stock', $manage_stock );
update_post_meta( $post_id, '_backorders', $backorders );
if ( $stock_status ) {
Expand All @@ -312,7 +312,7 @@ function ( $value ) {
dokan_log( 'product stock update exception' );
}
}

// Retrieve original stock value from the hidden field
$original_stock = isset( $data['_original_stock'] ) ? wc_stock_amount( wc_clean( $data['_original_stock'] ) ) : '';
// Clean the current stock value
Expand All @@ -326,7 +326,7 @@ function ( $value ) {
wc_update_product_stock( $post_id, $stock_amount );
}
}

// Update low stock amount regardless of stock changes
$_low_stock_amount = isset( $data['_low_stock_amount'] ) ? wc_clean( $data['_low_stock_amount'] ) : '';
$_low_stock_amount = 'yes' === $manage_stock ? wc_stock_amount( wp_unslash( $_low_stock_amount ) ) : '';
Expand Down

0 comments on commit 0ecb790

Please sign in to comment.