Changeset 3267015
- Timestamp:
- 04/04/2025 04:13:58 PM (12 months ago)
- Location:
- hippoo/trunk
- Files:
-
- 3 edited
-
app/web_api_auth.php (modified) (1 diff)
-
hippoo.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hippoo/trunk/app/web_api_auth.php
r3249938 r3267015 152 152 } 153 153 154 function hippoo_media_upload() 155 { 156 // phpcs:ignore 157 $file = isset($_FILES['file']) ? sanitize_text_field($_FILES['file']) : ''; 158 159 if (empty($file)) { 160 return new WP_Error('invalid_file', 'Invalid file.', ['status' => 400]); 161 } 162 163 $upload = wp_upload_bits($file['name'], null, file_get_contents($file['tmp_name'])); 164 165 if (!$upload['error']) { 166 $attachment = array( 167 'post_mime_type' => $upload['type'], 168 'post_title' => sanitize_file_name($upload['file']), 169 'post_content' => '', 170 'post_status' => 'inherit' 171 ); 172 173 $attachment_id = wp_insert_attachment($attachment, $upload['file']); 174 175 if (!is_wp_error($attachment_id)) { 176 $attachment_data = wp_generate_attachment_metadata($attachment_id, $upload['file']); 177 wp_update_attachment_metadata($attachment_id, $attachment_data); 178 $media_url = wp_get_attachment_url($attachment_id); 179 $response = array( 180 'status' => 'success', 181 'media_url' => $media_url, 182 'attachment_id' => $attachment_id, 183 "attachment_data" => $attachment_data 184 ); 185 return new WP_REST_Response($response, 200); 186 } 187 } 188 189 return new WP_Error('upload_failed', 'Media upload failed.', ['status' => 500]); 190 } 154 function hippoo_media_upload() { 155 if (empty($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) { 156 return new WP_Error('invalid_file', 'Invalid or missing file.', ['status' => 400]); 157 } 158 159 $file = $_FILES['file']; 160 $file_name = sanitize_file_name($file['name']); 161 $file_tmp_path = $file['tmp_name']; 162 $file_mime_type = mime_content_type($file_tmp_path); 163 164 // Read file content 165 $file_content = file_get_contents($file_tmp_path); 166 if ($file_content === false) { 167 return new WP_Error('file_read_error', 'Failed to read file content.', ['status' => 500]); 168 } 169 170 // Upload the file 171 $upload = wp_upload_bits($file_name, null, $file_content); 172 173 if (!empty($upload['error'])) { 174 return new WP_Error('upload_failed', 'Media upload failed.', ['status' => 500]); 175 } 176 177 // Prepare attachment data 178 $attachment = [ 179 'post_mime_type' => $file_mime_type, 180 'post_title' => pathinfo($file_name, PATHINFO_FILENAME), 181 'post_content' => '', 182 'post_status' => 'inherit' 183 ]; 184 185 // Insert attachment into WordPress 186 $attachment_id = wp_insert_attachment($attachment, $upload['file']); 187 188 if (is_wp_error($attachment_id)) { 189 return new WP_Error('attachment_failed', 'Failed to create attachment.', ['status' => 500]); 190 } 191 192 // Generate metadata and update attachment 193 require_once ABSPATH . 'wp-admin/includes/image.php'; 194 $attachment_data = wp_generate_attachment_metadata($attachment_id, $upload['file']); 195 wp_update_attachment_metadata($attachment_id, $attachment_data); 196 197 // Get the media URL 198 $media_url = wp_get_attachment_url($attachment_id); 199 200 return new WP_REST_Response([ 201 'status' => 'success', 202 'media_url' => $media_url, 203 'attachment_id' => $attachment_id, 204 'attachment_data' => $attachment_data 205 ], 200); 206 } 207 191 208 192 209 function hippoo_media_delete($request) -
hippoo/trunk/hippoo.php
r3250700 r3267015 1 1 <?php 2 2 /** 3 * Plugin Name: Hippoo mobile app for woocommerce4 * Version: 1.5. 93 * Plugin Name: Hippoo Mobile app for WooCommerce 4 * Version: 1.5.10 5 5 * Plugin URI: https://Hippoo.app/ 6 6 * Description: Best WooCommerce App Alternative – Manage orders and products on the go with real-time notifications, seamless order and product management, and powerful add-ons. Available for Android & iOS. 🚀. -
hippoo/trunk/readme.txt
r3250700 r3267015 5 5 Requires at least: 5.3 6 6 Tested up to: 6.7 7 Stable tag: 1.5. 07 Stable tag: 1.5.10 8 8 License: GPL3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 71 71 72 72 == Changelog == 73 * 1.5.10 - Media Upload compatibale with new wordpress updates 73 74 * 1.5.9 - Minor Improvements. 74 75 * 1.5.8 - Minor Improvements.
Note: See TracChangeset
for help on using the changeset viewer.