Changeset 3231889
- Timestamp:
- 01/30/2025 09:28:11 AM (14 months ago)
- Location:
- all-images-ai/trunk
- Files:
-
- 4 edited
-
admin/class-all-images-ai-admin.php (modified) (7 diffs)
-
admin/js/all-images-ai-admin.js (modified) (1 diff)
-
all-images-ai.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
all-images-ai/trunk/admin/class-all-images-ai-admin.php
r3157522 r3231889 172 172 $page = 'all-images-ai'; 173 173 174 register_setting($page, 'all-images-ai-settings' );174 register_setting($page, 'all-images-ai-settings', array($this, 'general_settings_callback')); 175 175 register_setting($page, 'all-images-api-key', array($this, 'validate_api_key')); 176 176 … … 365 365 } 366 366 367 public function general_settings_callback($value) 368 { 369 $options = get_option('all-images-ai-settings'); 370 if (!empty($options['all_images_automatic'])) { 371 $value['all_images_automatic'] = $options['all_images_automatic']; 372 } 373 374 return $value; 375 } 376 367 377 public function validate_api_key($value) 368 378 { … … 452 462 if ($this->wpdb->rows_affected === 0) { 453 463 wp_send_json_error( 454 array(' message' => sprintf(__('No line updated for query: %s', 'all-images-ai'), $this->wpdb->last_query))464 array('error' => sprintf(__('No line updated for query: %s', 'all-images-ai'), $this->wpdb->last_query)) 455 465 ); 456 466 } else { … … 943 953 944 954 return wp_send_json_error(array( 945 ' message' => implode("\n", $this->errors),955 'error' => implode("\n", $this->errors), 946 956 ), 500); 947 957 } … … 1265 1275 'alt_text' => (!empty($params['alt_text'])) ? sanitize_text_field($params['alt_text']) : null 1266 1276 ); 1267 if ($params['provider'] == 'allimages' && $params['free'] == 0 && !empty($this->api_key)) {1277 if ($params['provider'] === 'allimages' && $params['free'] == 0 && !empty($this->api_key)) { 1268 1278 $library_image_id = $this->_get_image_buffer_by_id(sanitize_text_field($params['id']), null, $metadata); 1269 1279 } else { 1270 1280 $library_image_id = $this->_get_image_by_url(sanitize_text_field($params['id']), sanitize_url($params['url']), null, $metadata); 1271 1281 } 1272 if ( $library_image_id) {1282 if (!is_wp_error($library_image_id)) { 1273 1283 return wp_send_json_success(array( 1274 1284 'attachment_id' => $library_image_id … … 1276 1286 } else { 1277 1287 return wp_send_json_error(array( 1278 ' message' => 'upload_failed'1288 'error' => sprintf('upload error: %s', $library_image_id->get_error_message()) 1279 1289 ), 500); 1280 1290 } … … 1584 1594 private function _get_image_by_url($id, $url, $post_id = null, $metadata = null) 1585 1595 { 1586 $response = wp_remote_get($url); 1587 $body = wp_remote_retrieve_body($response); 1588 $mime = wp_remote_retrieve_header($response, 'content-type'); 1596 $result = download_url($url); 1597 1598 if (is_wp_error($result)) { 1599 @unlink($result); 1600 return $result; 1601 } 1602 1603 $mime = wp_get_image_mime($result); 1604 1605 if ($mime === false) { 1606 @unlink($result); 1607 return new WP_Error('mime_error', __('Type cannot be determined', 'all-images-ai')); 1608 } 1609 1589 1610 $extension = substr($mime, 6); 1590 1611 if (isset($metadata['file_name'])) { 1591 $filename = $this->tmp_folder . $metadata['file_name'] . '.' .$extension;1612 $filename = $this->tmp_folder.$metadata['file_name'].'.'.$extension; 1592 1613 } else { 1593 $filename = $this->tmp_folder . $id . '.' . $extension; 1594 } 1595 file_put_contents($filename, $body); 1614 $filename = $this->tmp_folder.$id.'.'.$extension; 1615 } 1616 1617 $move_new_file = @copy($result, $filename); 1618 @unlink($result); 1619 1620 if ($move_new_file === false) { 1621 return new WP_Error('copy_error', __('File cannot be moved', 'all-images-ai')); 1622 } 1596 1623 1597 1624 if ( -
all-images-ai/trunk/admin/js/all-images-ai-admin.js
r3157522 r3231889 219 219 } 220 220 221 $( document).on('submit', '.all-images-image-wrapper.bigform.modal-form', function(e) {221 $('.all-images-image-wrapper').on('submit', 'form.modal-form', function(e) { 222 222 import_callback(e, $(this).closest('.all-images-image-wrapper')); 223 223 }); 224 $( document).on('click', '.all-images-image-wrapper.big.trigger-download', function(e) {224 $('.all-images-image-wrapper').on('click', '.trigger-download', function(e) { 225 225 import_callback(e, $(this).closest('.all-images-image-wrapper')); 226 226 }); 227 227 228 $( document).on('click', '.all-images-image-wrappera.settings.open-modal', function (e) {228 $('.all-images-image-wrapper').on('click', 'a.settings.open-modal', function (e) { 229 229 e.preventDefault(); 230 230 $('.ai-modal-window.open').removeClass('open'); -
all-images-ai/trunk/all-images-ai.php
r3157522 r3231889 17 17 * Plugin URI: https://app.all-images.ai 18 18 * Description: Find or generate the best images for your posts 19 * Version: 1.0. 419 * Version: 1.0.5 20 20 * Author: Weable 21 21 * Author URI: https://weable.fr/ … … 34 34 * Currently plugin version. 35 35 */ 36 define('ALL_IMAGES_AI_VERSION', '1.0. 4');36 define('ALL_IMAGES_AI_VERSION', '1.0.5'); 37 37 38 38 /** -
all-images-ai/trunk/readme.txt
r3157522 r3231889 5 5 Requires at least: 5.0 6 6 Tested up to: 6.6.2 7 Stable tag: 1.0. 47 Stable tag: 1.0.5 8 8 License: GPLv2 9 9 … … 65 65 == Changelog == 66 66 67 = 1.0.5 = 68 * Bug fixes 69 67 70 = 1.0.4 = 68 71 * Bug fixes
Note: See TracChangeset
for help on using the changeset viewer.