/**
* Custom WooCommerce Checkout Workflow: Mandatory & Secure ID Upload with Auto-Compression
*/
// 1. Inject the Mandatory ID Upload Field right before the Order Review section
add_action( 'woocommerce_checkout_before_order_review', 'armor_storage_add_id_upload_field' );
function armor_storage_add_id_upload_field() {
echo '
';
echo '
⚠️ Government-Issued ID Required
';
echo '
To complete your online move-in, a valid photo ID (Driver\'s License, State ID, or Passport) must be uploaded. The file will be processed securely.
';
echo '';
echo '';
echo '
';
}
// 2. Validate Front-End: Prevent the checkout submission if the file field is empty
add_action( 'woocommerce_checkout_process', 'armor_storage_validate_id_upload' );
function armor_storage_validate_id_upload() {
if ( empty( $_FILES['customer_id_image']['name'] ) ) {
wc_add_notice( __( 'Required Field Missing: Please upload a valid photo ID to complete your rental move-in application.', 'woocommerce' ), 'error' );
}
}
// 3. Process, Auto-Compress, and Secure the Uploaded File to fix server storage constraints
add_action( 'woocommerce_checkout_update_order_meta', 'armor_storage_save_compressed_id' );
function armor_storage_save_compressed_id( $order_id ) {
if ( ! empty( $_FILES['customer_id_image']['name'] ) ) {
// Define paths inside standard uploads directory
$wp_upload_dir = wp_upload_dir();
$secure_dir = $wp_upload_dir['basedir'] . '/secure_customer_ids';
// Create the directory securely if it doesn't exist
if ( ! file_exists( $secure_dir ) ) {
wp_mkdir_p( $secure_dir );
// Inject an .htaccess file to completely block public web URL directory browsing access
file_put_contents( $secure_dir . '/.htaccess', "Deny from all" );
}
$file_tmp = $_FILES['customer_id_image']['tmp_name'];
$file_ext = pathinfo( $_FILES['customer_id_image']['name'], PATHINFO_EXTENSION );
$unique_filename = 'order_' . $order_id . '_' . bin2hex( random_bytes( 8 ) ) . '.jpg';
$target_path = $secure_dir . '/' . $unique_filename;
// AUTO-COMPRESSION MECHANISM (Compresses massive smartphone pics down to ~150KB)
$image_info = getimagesize( $file_tmp );
if ( $image_info ) {
switch ( $image_info['mime'] ) {
case 'image/jpeg': $src_img = imagecreatefromjpeg( $file_tmp ); break;
case 'image/png': $src_img = imagecreatefrompng( $file_tmp ); break;
case 'image/gif': $src_img = imagecreatefromgif( $file_tmp ); break;
default: $src_img = false;
}
if ( $src_img ) {
$max_width = 1200;
$orig_width = imagesx( $src_img );
$orig_height = imagesy( $src_img );
// Scale calculations to preserve proportions while lowering file size weight
if ( $orig_width > $max_width ) {
$new_width = $max_width;
$new_height = floor( $orig_height * ( $max_width / $orig_width ) );
$dst_img = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $dst_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $orig_width, $orig_height );
// Save as optimized JPEG (70% Quality)
imagejpeg( $dst_img, $target_path, 70 );
imagedestroy( $dst_img );
} else {
imagejpeg( $src_img, $target_path, 70 );
}
imagedestroy( $src_img );
// Save unique path reference link securely inside the Order Metadata instead of public URLs
update_post_meta( $order_id, '_secure_customer_id_file', $target_path );
} else {
// Fallback to basic copy if manipulation library errors out
move_uploaded_file( $file_tmp, $target_path );
update_post_meta( $order_id, '_secure_customer_id_file', $target_path );
}
}
}
}
https://aswssapi.yournewsite.rocks/post-sitemap.xml2026-06-30T23:09:10+00:00https://aswssapi.yournewsite.rocks/page-sitemap.xml2026-07-08T19:18:21+00:00https://aswssapi.yournewsite.rocks/location-sitemap.xml2026-05-29T17:57:28+00:00https://aswssapi.yournewsite.rocks/bricks_template-sitemap.xml2026-07-20T13:48:13+00:00https://aswssapi.yournewsite.rocks/category-sitemap.xml2026-06-30T23:09:10+00:00https://aswssapi.yournewsite.rocks/location-state-sitemap.xml2026-05-29T17:57:28+00:00https://aswssapi.yournewsite.rocks/author-sitemap.xml2025-12-18T22:14:08+00:00