Plugin Directory

Changeset 3231889


Ignore:
Timestamp:
01/30/2025 09:28:11 AM (14 months ago)
Author:
allimages
Message:

FIX 1.0.5

Location:
all-images-ai/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • all-images-ai/trunk/admin/class-all-images-ai-admin.php

    r3157522 r3231889  
    172172        $page = 'all-images-ai';
    173173
    174         register_setting($page, 'all-images-ai-settings');
     174        register_setting($page, 'all-images-ai-settings', array($this, 'general_settings_callback'));
    175175        register_setting($page, 'all-images-api-key', array($this, 'validate_api_key'));
    176176
     
    365365    }
    366366
     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
    367377    public function validate_api_key($value)
    368378    {
     
    452462        if ($this->wpdb->rows_affected === 0) {
    453463            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))
    455465            );
    456466        } else {
     
    943953
    944954        return wp_send_json_error(array(
    945             'message' => implode("\n", $this->errors),
     955            'error' => implode("\n", $this->errors),
    946956        ), 500);
    947957    }
     
    12651275            'alt_text' => (!empty($params['alt_text'])) ? sanitize_text_field($params['alt_text']) : null
    12661276        );
    1267         if ($params['provider'] == 'allimages' && $params['free'] == 0 && !empty($this->api_key)) {
     1277        if ($params['provider'] === 'allimages' && $params['free'] == 0 && !empty($this->api_key)) {
    12681278            $library_image_id = $this->_get_image_buffer_by_id(sanitize_text_field($params['id']), null, $metadata);
    12691279        } else {
    12701280            $library_image_id = $this->_get_image_by_url(sanitize_text_field($params['id']), sanitize_url($params['url']), null, $metadata);
    12711281        }
    1272         if ($library_image_id) {
     1282        if (!is_wp_error($library_image_id)) {
    12731283            return wp_send_json_success(array(
    12741284                'attachment_id' => $library_image_id
     
    12761286        } else {
    12771287            return wp_send_json_error(array(
    1278                 'message' => 'upload_failed'
     1288                'error' => sprintf('upload error: %s', $library_image_id->get_error_message())
    12791289            ), 500);
    12801290        }
     
    15841594    private function _get_image_by_url($id, $url, $post_id = null, $metadata = null)
    15851595    {
    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
    15891610        $extension = substr($mime, 6);
    15901611        if (isset($metadata['file_name'])) {
    1591             $filename = $this->tmp_folder . $metadata['file_name'] . '.' . $extension;
     1612            $filename = $this->tmp_folder.$metadata['file_name'].'.'.$extension;
    15921613        } 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        }
    15961623
    15971624        if (
  • all-images-ai/trunk/admin/js/all-images-ai-admin.js

    r3157522 r3231889  
    219219        }
    220220
    221         $(document).on('submit', '.all-images-image-wrapper.big form.modal-form', function(e) {
     221        $('.all-images-image-wrapper').on('submit', 'form.modal-form', function(e) {
    222222            import_callback(e, $(this).closest('.all-images-image-wrapper'));
    223223        });
    224         $(document).on('click', '.all-images-image-wrapper.big .trigger-download', function(e) {
     224        $('.all-images-image-wrapper').on('click', '.trigger-download', function(e) {
    225225            import_callback(e, $(this).closest('.all-images-image-wrapper'));
    226226        });
    227227
    228         $(document).on('click', '.all-images-image-wrapper a.settings.open-modal', function (e) {
     228        $('.all-images-image-wrapper').on('click', 'a.settings.open-modal', function (e) {
    229229            e.preventDefault();
    230230            $('.ai-modal-window.open').removeClass('open');
  • all-images-ai/trunk/all-images-ai.php

    r3157522 r3231889  
    1717 * Plugin URI:        https://app.all-images.ai
    1818 * Description:       Find or generate the best images for your posts
    19  * Version:           1.0.4
     19 * Version:           1.0.5
    2020 * Author:            Weable
    2121 * Author URI:        https://weable.fr/
     
    3434 * Currently plugin version.
    3535 */
    36 define('ALL_IMAGES_AI_VERSION', '1.0.4');
     36define('ALL_IMAGES_AI_VERSION', '1.0.5');
    3737
    3838/**
  • all-images-ai/trunk/readme.txt

    r3157522 r3231889  
    55Requires at least: 5.0
    66Tested up to: 6.6.2
    7 Stable tag: 1.0.4
     7Stable tag: 1.0.5
    88License: GPLv2
    99
     
    6565== Changelog ==
    6666
     67= 1.0.5 =
     68* Bug fixes
     69
    6770= 1.0.4 =
    6871* Bug fixes
Note: See TracChangeset for help on using the changeset viewer.