Plugin Directory

Changeset 3423116


Ignore:
Timestamp:
12/18/2025 04:52:43 PM (3 months ago)
Author:
andrejdivi
Message:

Update to version 1.4.2 from GitHub

Location:
alt-text-imagerr-ai
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • alt-text-imagerr-ai/tags/1.4.2/assets/imagerr-attachment.js

    r3371087 r3423116  
    7070                    var attachment_wrapper = $this.closest('.attachment-info');
    7171                    $('[data-setting="alt"] textarea', attachment_wrapper).val(response.alt_text);
    72                     $('[data-setting="title"] input[type="text"]', attachment_wrapper).val(response.title);
    73                     $('[data-setting="caption"] textarea', attachment_wrapper).val(response.caption);
    74                     $('[data-setting="description"] textarea', attachment_wrapper).val(response.description);   
     72                    if (response.title !== undefined) {
     73                        $('[data-setting="title"] input[type="text"]', attachment_wrapper).val(response.title);
     74                    }
     75                    if (response.caption !== undefined) {
     76                        $('[data-setting="caption"] textarea', attachment_wrapper).val(response.caption);
     77                    }
     78                    if (response.description !== undefined) {
     79                        $('[data-setting="description"] textarea', attachment_wrapper).val(response.description);
     80                    }
    7581                }
    7682
  • alt-text-imagerr-ai/tags/1.4.2/imagerr.php

    r3409077 r3423116  
    33 * Plugin Name: AI Image Alt Text Generator – Imagerr AI
    44 * Description: Generate alt text, titles, descriptions, and captions for your images automatically with AI.
    5  * Version: 1.4.1
     5 * Version: 1.4.2
    66 * Text Domain: alt-text-imagerr-ai
    77 * Domain Path: /languages
     
    667667            array(
    668668                'type'              => 'string',
    669                 'sanitize_callback' => function ( $value ) {
    670                     return sanitize_text_field( $value );
    671                 },
     669                'sanitize_callback' => array( $this, 'sanitize_language_setting' ),
    672670                'default'           => get_locale(),
    673671            )
     
    707705    public function sanitize_checkbox( $value ) {
    708706        return ( isset( $value ) && true === (bool) $value ) ? true : false;
     707    }
     708
     709    /**
     710     * Sanitize language setting to prevent injection attacks
     711     * Only allow valid WordPress locale codes from available translations
     712     *
     713     * @param  string $value The language value to sanitize.
     714     * @return string The sanitized language code.
     715     */
     716    public function sanitize_language_setting( $value ) {
     717        // First sanitize the text field to remove any dangerous characters
     718        $value = sanitize_text_field( $value );
     719       
     720        // If empty, default to site locale
     721        if ( empty( $value ) ) {
     722            return get_locale();
     723        }
     724
     725        // Get available WordPress translations
     726        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     727        $languages = wp_get_available_translations();
     728       
     729        // Build whitelist of valid language codes
     730        // Add English (US) as it's not always included in wp_get_available_translations()
     731        $valid_languages = array( 'en_US' );
     732        foreach ( $languages as $lang ) {
     733            if ( isset( $lang['language'] ) ) {
     734                $valid_languages[] = $lang['language'];
     735            }
     736        }
     737
     738        // Only return the value if it's in the whitelist, otherwise default to site locale
     739        if ( ! in_array( $value, $valid_languages, true ) ) {
     740            return get_locale();
     741        }
     742
     743        return $value;
    709744    }
    710745
  • alt-text-imagerr-ai/tags/1.4.2/readme.txt

    r3409077 r3423116  
    55Requires PHP: 5.2
    66Requires at least: 4.6
    7 Stable tag: 1.4.1
     7Stable tag: 1.4.2
    88Tested up to: 6.9
    99License: GPLv2 or later
     
    7171
    7272== Changelog ==
     73= 1.4.2 =
     74* Fixed issue with image file paths
     75* Fixed issue when image description was overriding the description with a blank description
     76
    7377= 1.4.1 =
    7478* Changed URLs to new faster API server
  • alt-text-imagerr-ai/tags/1.4.2/src/Meta.php

    r3409077 r3423116  
    5656        $this->log( "> $image_id" );
    5757
    58         $ai_fields = $this->api_generate_meta( $image_url );
     58        $ai_fields = $this->api_generate_meta( $image_id, $image_url );
    5959
    6060        if ( is_wp_error( $ai_fields ) ) {
     
    272272     * API generate meta.
    273273     *
    274      * @param string $image_url The image URL.
     274     * @param int    $image_id The image ID.
     275     * @param string $image_url The image URL (used for IMAGERR_UPLOADS_URL replacement and logging).
    275276     * @return array|\WP_Error The AI fields or a WP_Error object.
    276277     */
    277     private function api_generate_meta( $image_url ) {
     278    private function api_generate_meta( $image_id, $image_url ) {
     279        // Get the actual file path using WordPress's built-in function
     280        // This works reliably regardless of CDN, custom upload directories, or multisite setups
     281        $image_path = get_attached_file( $image_id );
     282
     283        // Check if file exists locally
     284        if ( ! $image_path || ! file_exists( $image_path ) ) {
     285            return new \WP_Error( 'imagerr_error', 'Image file not found for attachment ID: ' . $image_id );
     286        }
     287
     288        // If IMAGERR_UPLOADS_URL is defined, we need to adjust the URL for external access
    278289        if ( defined( 'IMAGERR_UPLOADS_URL' ) ) {
    279290            $wp_upload_dir = wp_upload_dir();
    280291            $base_url      = $wp_upload_dir['baseurl'];
    281292            $image_url     = str_replace( $base_url, rtrim( IMAGERR_UPLOADS_URL, '/' ), $image_url );
    282         }
    283 
    284         // Get the image file path from URL
    285         $upload_dir = wp_upload_dir();
    286         $image_path = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $image_url );
    287 
    288         // Check if file exists locally
    289         if ( ! file_exists( $image_path ) ) {
    290             return new \WP_Error( 'imagerr_error', 'Image file not found: ' . $image_path );
    291293        }
    292294
     
    303305
    304306        $site_url  = get_site_url();
    305         $language  = get_option( 'imagerr_generation_language', get_locale() );
     307        $language  = $this->validate_language( get_option( 'imagerr_generation_language', get_locale() ) );
    306308
    307309        // Prepare multipart form data
     
    442444        $credits = json_decode( wp_remote_retrieve_body( $response ), true );
    443445
    444 
    445         if ( isset( $credits['data']['credits'] ) && $credits['data']['credits'] > 0 ) {
     446        $credits = $credits['data']['credits'] ?? $credits['credits'] ?? 0;
     447
     448        if ( $credits > 0 ) {
    446449            $dismissed_notice = get_option( 'imagerr_dismissed_notice' );
    447450            if ( ! $dismissed_notice ) {
     
    450453        }
    451454
    452         return $credits['data']['credits'] ?? 0;
     455        return $credits;
     456    }
     457
     458    /**
     459     * Validate language code to prevent injection attacks
     460     * Only allow valid WordPress locale codes from available translations
     461     *
     462     * @param  string $language The language code to validate.
     463     * @return string The validated language code.
     464     */
     465    private function validate_language( $language ) {
     466        // If empty, default to site locale
     467        if ( empty( $language ) ) {
     468            return get_locale();
     469        }
     470
     471        // Get available WordPress translations
     472        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     473        $languages = wp_get_available_translations();
     474       
     475        // Build whitelist of valid language codes
     476        // Add English (US) as it's not always included in wp_get_available_translations()
     477        $valid_languages = array( 'en_US' );
     478        foreach ( $languages as $lang ) {
     479            if ( isset( $lang['language'] ) ) {
     480                $valid_languages[] = $lang['language'];
     481            }
     482        }
     483
     484        // Only return the value if it's in the whitelist, otherwise default to site locale
     485        if ( ! in_array( $language, $valid_languages, true ) ) {
     486            return get_locale();
     487        }
     488
     489        return $language;
    453490    }
    454491
  • alt-text-imagerr-ai/trunk/assets/imagerr-attachment.js

    r3371087 r3423116  
    7070                    var attachment_wrapper = $this.closest('.attachment-info');
    7171                    $('[data-setting="alt"] textarea', attachment_wrapper).val(response.alt_text);
    72                     $('[data-setting="title"] input[type="text"]', attachment_wrapper).val(response.title);
    73                     $('[data-setting="caption"] textarea', attachment_wrapper).val(response.caption);
    74                     $('[data-setting="description"] textarea', attachment_wrapper).val(response.description);   
     72                    if (response.title !== undefined) {
     73                        $('[data-setting="title"] input[type="text"]', attachment_wrapper).val(response.title);
     74                    }
     75                    if (response.caption !== undefined) {
     76                        $('[data-setting="caption"] textarea', attachment_wrapper).val(response.caption);
     77                    }
     78                    if (response.description !== undefined) {
     79                        $('[data-setting="description"] textarea', attachment_wrapper).val(response.description);
     80                    }
    7581                }
    7682
  • alt-text-imagerr-ai/trunk/imagerr.php

    r3409077 r3423116  
    33 * Plugin Name: AI Image Alt Text Generator – Imagerr AI
    44 * Description: Generate alt text, titles, descriptions, and captions for your images automatically with AI.
    5  * Version: 1.4.1
     5 * Version: 1.4.2
    66 * Text Domain: alt-text-imagerr-ai
    77 * Domain Path: /languages
     
    667667            array(
    668668                'type'              => 'string',
    669                 'sanitize_callback' => function ( $value ) {
    670                     return sanitize_text_field( $value );
    671                 },
     669                'sanitize_callback' => array( $this, 'sanitize_language_setting' ),
    672670                'default'           => get_locale(),
    673671            )
     
    707705    public function sanitize_checkbox( $value ) {
    708706        return ( isset( $value ) && true === (bool) $value ) ? true : false;
     707    }
     708
     709    /**
     710     * Sanitize language setting to prevent injection attacks
     711     * Only allow valid WordPress locale codes from available translations
     712     *
     713     * @param  string $value The language value to sanitize.
     714     * @return string The sanitized language code.
     715     */
     716    public function sanitize_language_setting( $value ) {
     717        // First sanitize the text field to remove any dangerous characters
     718        $value = sanitize_text_field( $value );
     719       
     720        // If empty, default to site locale
     721        if ( empty( $value ) ) {
     722            return get_locale();
     723        }
     724
     725        // Get available WordPress translations
     726        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     727        $languages = wp_get_available_translations();
     728       
     729        // Build whitelist of valid language codes
     730        // Add English (US) as it's not always included in wp_get_available_translations()
     731        $valid_languages = array( 'en_US' );
     732        foreach ( $languages as $lang ) {
     733            if ( isset( $lang['language'] ) ) {
     734                $valid_languages[] = $lang['language'];
     735            }
     736        }
     737
     738        // Only return the value if it's in the whitelist, otherwise default to site locale
     739        if ( ! in_array( $value, $valid_languages, true ) ) {
     740            return get_locale();
     741        }
     742
     743        return $value;
    709744    }
    710745
  • alt-text-imagerr-ai/trunk/readme.txt

    r3409077 r3423116  
    55Requires PHP: 5.2
    66Requires at least: 4.6
    7 Stable tag: 1.4.1
     7Stable tag: 1.4.2
    88Tested up to: 6.9
    99License: GPLv2 or later
     
    7171
    7272== Changelog ==
     73= 1.4.2 =
     74* Fixed issue with image file paths
     75* Fixed issue when image description was overriding the description with a blank description
     76
    7377= 1.4.1 =
    7478* Changed URLs to new faster API server
  • alt-text-imagerr-ai/trunk/src/Meta.php

    r3409077 r3423116  
    5656        $this->log( "> $image_id" );
    5757
    58         $ai_fields = $this->api_generate_meta( $image_url );
     58        $ai_fields = $this->api_generate_meta( $image_id, $image_url );
    5959
    6060        if ( is_wp_error( $ai_fields ) ) {
     
    272272     * API generate meta.
    273273     *
    274      * @param string $image_url The image URL.
     274     * @param int    $image_id The image ID.
     275     * @param string $image_url The image URL (used for IMAGERR_UPLOADS_URL replacement and logging).
    275276     * @return array|\WP_Error The AI fields or a WP_Error object.
    276277     */
    277     private function api_generate_meta( $image_url ) {
     278    private function api_generate_meta( $image_id, $image_url ) {
     279        // Get the actual file path using WordPress's built-in function
     280        // This works reliably regardless of CDN, custom upload directories, or multisite setups
     281        $image_path = get_attached_file( $image_id );
     282
     283        // Check if file exists locally
     284        if ( ! $image_path || ! file_exists( $image_path ) ) {
     285            return new \WP_Error( 'imagerr_error', 'Image file not found for attachment ID: ' . $image_id );
     286        }
     287
     288        // If IMAGERR_UPLOADS_URL is defined, we need to adjust the URL for external access
    278289        if ( defined( 'IMAGERR_UPLOADS_URL' ) ) {
    279290            $wp_upload_dir = wp_upload_dir();
    280291            $base_url      = $wp_upload_dir['baseurl'];
    281292            $image_url     = str_replace( $base_url, rtrim( IMAGERR_UPLOADS_URL, '/' ), $image_url );
    282         }
    283 
    284         // Get the image file path from URL
    285         $upload_dir = wp_upload_dir();
    286         $image_path = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $image_url );
    287 
    288         // Check if file exists locally
    289         if ( ! file_exists( $image_path ) ) {
    290             return new \WP_Error( 'imagerr_error', 'Image file not found: ' . $image_path );
    291293        }
    292294
     
    303305
    304306        $site_url  = get_site_url();
    305         $language  = get_option( 'imagerr_generation_language', get_locale() );
     307        $language  = $this->validate_language( get_option( 'imagerr_generation_language', get_locale() ) );
    306308
    307309        // Prepare multipart form data
     
    442444        $credits = json_decode( wp_remote_retrieve_body( $response ), true );
    443445
    444 
    445         if ( isset( $credits['data']['credits'] ) && $credits['data']['credits'] > 0 ) {
     446        $credits = $credits['data']['credits'] ?? $credits['credits'] ?? 0;
     447
     448        if ( $credits > 0 ) {
    446449            $dismissed_notice = get_option( 'imagerr_dismissed_notice' );
    447450            if ( ! $dismissed_notice ) {
     
    450453        }
    451454
    452         return $credits['data']['credits'] ?? 0;
     455        return $credits;
     456    }
     457
     458    /**
     459     * Validate language code to prevent injection attacks
     460     * Only allow valid WordPress locale codes from available translations
     461     *
     462     * @param  string $language The language code to validate.
     463     * @return string The validated language code.
     464     */
     465    private function validate_language( $language ) {
     466        // If empty, default to site locale
     467        if ( empty( $language ) ) {
     468            return get_locale();
     469        }
     470
     471        // Get available WordPress translations
     472        require_once ABSPATH . 'wp-admin/includes/translation-install.php';
     473        $languages = wp_get_available_translations();
     474       
     475        // Build whitelist of valid language codes
     476        // Add English (US) as it's not always included in wp_get_available_translations()
     477        $valid_languages = array( 'en_US' );
     478        foreach ( $languages as $lang ) {
     479            if ( isset( $lang['language'] ) ) {
     480                $valid_languages[] = $lang['language'];
     481            }
     482        }
     483
     484        // Only return the value if it's in the whitelist, otherwise default to site locale
     485        if ( ! in_array( $language, $valid_languages, true ) ) {
     486            return get_locale();
     487        }
     488
     489        return $language;
    453490    }
    454491
Note: See TracChangeset for help on using the changeset viewer.