Plugin Directory

Changeset 3826946


Ignore:
Timestamp:
11/26/2026 12:41:24 PM (less than one hour ago)
Author:
robskinn
Message:

Update to version 1.0.13 from GitHub

Location:
altification
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • altification/tags/1.0.13/altification.php

    r3826858 r3826946  
    44 * Plugin URI:        https://altification.ai/plugin
    55 * Description:       AI-powered alt text, caption and description generator for WordPress media.
    6  * Version:           1.0.12
     6 * Version:           1.0.13
    77 * Requires at least: 6.0
    88 * Requires PHP:      7.4
    … …  
    1818}
    1919
    20 define( 'ALTIFICATION_VERSION', '1.0.12' );
     20define( 'ALTIFICATION_VERSION', '1.0.13' );
    2121define( 'ALTIFICATION_DIR', plugin_dir_path( __FILE__ ) );
    2222define( 'ALTIFICATION_URL', plugin_dir_url( __FILE__ ) );
  • altification/tags/1.0.13/includes/ajax.php

    r3826858 r3826946  
    404404    $keyword_mismatch  = $has_alt_after && $saved_keyword !== '' && ! $is_reviewed_after;
    405405
    406     // Missing alt text is tracked by membership of missing_alt_ids — the list the Media Library
    407     // notice counts and its filter shows — so a save moves this image on or off it the way the
    408     // next Site Scan would. It comes off once it has alt text (or is decorative). It goes on
    409     // only when this save cleared alt text it had: an image that had none and isn't listed
    410     // was left out by the scan on purpose (an SVG, or a file it can't resolve).
    411     $is_decorative_after   = get_post_meta( $attachment_id, '_altification_decorative', true ) === '1';
    412     $missing_listed_before = isset( $stats['missing_alt_ids'] )
    413         && in_array( $attachment_id, array_map( 'intval', $stats['missing_alt_ids'] ), true );
    414     $missing_listed_after  = $missing_listed_before
    415         ? ( ! $has_alt_after && ! $is_decorative_after )
    416         : ( $had_alt_before && ! $has_alt_after && ! $is_decorative_after
    417             && get_post_mime_type( $attachment_id ) !== 'image/svg+xml'
    418             && altification_image_is_counted( $attachment_id ) );
    419 
    420     // Applied to the in-memory copy only; it is written back below along with the SEO gap and
    421     // improvable updates, for counted images.
    422     if ( $stats !== false ) {
    423         if ( isset( $stats['missing_alt_ids'] ) ) {
    424             if ( $missing_listed_before !== $missing_listed_after ) {
    425                 $stats['missing_alt_ids'] = $missing_listed_after
    426                     ? array_merge( array_map( 'intval', $stats['missing_alt_ids'] ), [ $attachment_id ] )
    427                     : array_values( array_diff( array_map( 'intval', $stats['missing_alt_ids'] ), [ $attachment_id ] ) );
    428                 $stats['missing_alt']     = count( $stats['missing_alt_ids'] );
    429             }
    430         } elseif ( altification_image_is_counted( $attachment_id ) && ! $had_alt_before && $has_alt_after ) {
    431             // Stats cached before missing_alt_ids existed — the count alone, as before.
    432             $stats['missing_alt'] = max( 0, (int) $stats['missing_alt'] - 1 );
     406    // Missing alt text, captions and descriptions are tracked by membership of the cached
     407    // missing_*_ids lists — what the Media Library notice counts and its filters show — so a
     408    // save moves this image on or off each list the way the next Site Scan would. The rule is
     409    // altification_missing_list_after_save().
     410    $is_decorative_after = get_post_meta( $attachment_id, '_altification_decorative', true ) === '1';
     411    $has_cap_after       = $write_caption     ? ! empty( $caption_value )     : $had_cap_before;
     412    $has_desc_after      = $write_description ? ! empty( $description_value ) : $had_desc_before;
     413    $missing_fields      = [
     414        // list key => [ count key, field filled before, field filled after ]
     415        'missing_alt_ids'  => [ 'missing_alt',  $had_alt_before,  $has_alt_after ],
     416        'missing_cap_ids'  => [ 'missing_cap',  $had_cap_before,  $has_cap_after ],
     417        'missing_desc_ids' => [ 'missing_desc', $had_desc_before, $has_desc_after ],
     418    ];
     419    $missing_listed = []; // list key => [ listed before, listed after ]
     420    foreach ( $missing_fields as $list_key => [ $count_key, $had_field, $has_field ] ) {
     421        $listed_before = altification_site_stats_has( $stats, $list_key, $attachment_id );
     422        $listed_after  = altification_missing_list_after_save( $attachment_id, $listed_before, $had_field, $has_field, $was_decorative_before, $is_decorative_after );
     423        $missing_listed[ $list_key ] = [ $listed_before, $listed_after ];
     424        // Applied to the in-memory copy only; it is written back below along with the SEO gap
     425        // and improvable updates, for counted images.
     426        if ( isset( $stats[ $list_key ] ) && $listed_before !== $listed_after ) {
     427            altification_site_stats_set_listed( $stats, $list_key, $count_key, $attachment_id, $listed_after );
    433428        }
     429    }
     430    if ( $stats !== false && ! isset( $stats['missing_alt_ids'] )
     431        && altification_image_is_counted( $attachment_id ) && ! $had_alt_before && $has_alt_after ) {
     432        // Stats cached before missing_alt_ids existed — the count alone, as before.
     433        $stats['missing_alt'] = max( 0, (int) $stats['missing_alt'] - 1 );
    434434    }
    435435
    … …  
    474474    // moved out of that bucket), +1 means it climbs. JS applies these to the on-screen
    475475    // counter spans so the notice ticks live without a page reload.
    476     $has_cap_after        = $write_caption     ? ! empty( $caption_value )     : $had_cap_before;
    477     $has_desc_after       = $write_description ? ! empty( $description_value ) : $had_desc_before;
    478476    $is_improvable_after  = altification_is_image_improvable( $attachment_id );
    479477    // If the ignore-unattached toggle is on and this image has no parent, it contributes
    480478    // 0 to every counter — zero out all deltas so the JS notice doesn't tick on something
    481     // the SQL queries are excluding.
     479    // the cached counts are excluding.
    482480    $is_counted = altification_image_is_counted( $attachment_id );
    483481    if ( $is_counted ) {
    484         // The notice's missing alt count is the length of missing_alt_ids, so it moves exactly
    485         // when this save moved the image on or off that list (worked out above). Without the
    486         // list — stats cached by an older version — fall back to the old rule: no alt text and
    487         // not decorative.
    488         if ( isset( $stats['missing_alt_ids'] ) ) {
    489             $contrib_missing_before = $missing_listed_before ? 1 : 0;
    490             $contrib_missing_after  = $missing_listed_after  ? 1 : 0;
    491         } else {
    492             $contrib_missing_before = ( ! $had_alt_before && ! $was_decorative_before ) ? 1 : 0;
    493             $contrib_missing_after  = ( ! $has_alt_after  && ! $is_decorative_after )  ? 1 : 0;
    494         }
     482        // The notice's missing counts are the lengths of the missing_*_ids lists, so each moves
     483        // exactly when this save moved the image on or off that list (worked out above).
     484        // Without the lists — stats cached by an older version — fall back to the old rules.
     485        $list_delta = function ( $list_key, $fallback ) use ( $stats, $missing_listed ) {
     486            if ( ! isset( $stats[ $list_key ] ) ) {
     487                return $fallback;
     488            }
     489            return (int) $missing_listed[ $list_key ][1] - (int) $missing_listed[ $list_key ][0];
     490        };
    495491        $notice_delta = [
    496             'missing_alt'  => $contrib_missing_after - $contrib_missing_before,
     492            'missing_alt'  => $list_delta( 'missing_alt_ids',
     493                ( ( ! $has_alt_after && ! $is_decorative_after ) ? 1 : 0 ) - ( ( ! $had_alt_before && ! $was_decorative_before ) ? 1 : 0 ) ),
    497494            'decorative'   => ( $is_decorative_after ? 1 : 0 ) - ( $was_decorative_before ? 1 : 0 ),
    498             'missing_cap'  => ( $has_cap_after  ? 0 : 1 ) - ( $had_cap_before  ? 0 : 1 ),
    499             'missing_desc' => ( $has_desc_after ? 0 : 1 ) - ( $had_desc_before ? 0 : 1 ),
     495            'missing_cap'  => $list_delta( 'missing_cap_ids',  ( $has_cap_after  ? 0 : 1 ) - ( $had_cap_before  ? 0 : 1 ) ),
     496            'missing_desc' => $list_delta( 'missing_desc_ids', ( $has_desc_after ? 0 : 1 ) - ( $had_desc_before ? 0 : 1 ) ),
    500497            'improvable'   => ( $is_improvable_after ? 1 : 0 ) - ( $was_improvable_before ? 1 : 0 ),
    501498            'seo_gap'      => ( $has_seo_gap_after ? 1 : 0 ) - ( $had_seo_gap_before ? 1 : 0 ),
    … …  
    680677    } else {
    681678        // After: alt is empty, decorative=1, no SEO gap, not improvable.
    682         // The notice's missing alt count is the length of missing_alt_ids, so this drops it
    683         // only when the image was on that list. Stats cached without the list fall back to the
    684         // old rule: no alt text and not already decorative.
    685         $missing_listed_before  = isset( $stats['missing_alt_ids'] )
    686             && in_array( $attachment_id, array_map( 'intval', $stats['missing_alt_ids'] ), true );
     679        // Decorative is a finished state, so the image comes off all three missing lists, and
     680        // each notice count drops only if it was on that list. Stats cached without the lists
     681        // fall back to the old rule for alt text, and leave captions and descriptions alone.
    687682        $contrib_missing_before = isset( $stats['missing_alt_ids'] )
    688             ? ( $missing_listed_before ? 1 : 0 )
     683            ? ( altification_site_stats_has( $stats, 'missing_alt_ids', $attachment_id ) ? 1 : 0 )
    689684            : ( ( ! $had_alt_before && ! $was_decorative_before ) ? 1 : 0 );
    690685        // contribution after: alt empty + decorative=1 → 0 (decoratives are excluded from missing_alt)
    … …  
    692687            'missing_alt'  => 0 - $contrib_missing_before,
    693688            'decorative'   => 1 - ( $was_decorative_before ? 1 : 0 ),
    694             'missing_cap'  => 0,
    695             'missing_desc' => 0,
     689            'missing_cap'  => altification_site_stats_has( $stats, 'missing_cap_ids', $attachment_id ) ? -1 : 0,
     690            'missing_desc' => altification_site_stats_has( $stats, 'missing_desc_ids', $attachment_id ) ? -1 : 0,
    696691            'improvable'   => 0 - ( $was_improvable_before ? 1 : 0 ),
    697692            'seo_gap'      => 0 - ( $had_seo_gap_before ? 1 : 0 ),
    … …  
    700695        // Keep the site-stats transient in sync — admin bar reads from it.
    701696        if ( $stats !== false ) {
    702             if ( isset( $stats['missing_alt_ids'] ) ) {
    703                 $stats['missing_alt_ids'] = array_values( array_diff( array_map( 'intval', $stats['missing_alt_ids'] ), [ $attachment_id ] ) );
    704                 $stats['missing_alt']     = count( $stats['missing_alt_ids'] );
    705             } else {
     697            foreach ( [ 'missing_alt_ids' => 'missing_alt', 'missing_cap_ids' => 'missing_cap', 'missing_desc_ids' => 'missing_desc' ] as $list_key => $count_key ) {
     698                if ( isset( $stats[ $list_key ] ) ) {
     699                    altification_site_stats_set_listed( $stats, $list_key, $count_key, $attachment_id, false );
     700                }
     701            }
     702            if ( ! isset( $stats['missing_alt_ids'] ) ) {
    706703                $stats['missing_alt'] = max( 0, (int) $stats['missing_alt'] + $notice_delta['missing_alt'] );
    707704            }
  • altification/tags/1.0.13/includes/bulk.php

    r3826858 r3826946  
    130130    $missing_alt      = count( array_filter( $all_images, fn( $i ) => ! $i['has_alt'] && ! $i['is_svg'] && ! $i['is_decorative'] ) );
    131131    $decorative_count = count( array_filter( $all_images, fn( $i ) => $i['is_decorative'] ) );
    132     $missing_cap  = $enable_caption     ? count( array_filter( $all_images, fn( $i ) => ! $i['has_caption'] ) ) : 0;
    133     $missing_desc = $enable_description ? count( array_filter( $all_images, fn( $i ) => ! $i['has_desc'] ) )    : 0;
     132    // Same exclusions as $missing_alt, and as altification_summarise_site_images() and the JS
     133    // recounts below. These used to count decorative images and SVGs, so the cards and tabs
     134    // dropped to a different number the first time the JS recounted them.
     135    $missing_cap  = $enable_caption     ? count( array_filter( $all_images, fn( $i ) => ! $i['has_caption'] && ! $i['is_svg'] && ! $i['is_decorative'] ) ) : 0;
     136    $missing_desc = $enable_description ? count( array_filter( $all_images, fn( $i ) => ! $i['has_desc']    && ! $i['is_svg'] && ! $i['is_decorative'] ) ) : 0;
    134137    // Same exclusions as $missing_alt above, and as the JS recount in
    135138    // altificationUpdateFilterCredits(): an SVG can't be generated and a decorative image is
    … …  
    913916
    914917                var isDecorative = $row.attr('data-decorative') === '1';
     918                // The missing filters list what the counts count: decorative images and SVGs
     919                // are never missing anything (see altificationUpdateFilterCredits()).
     920                var countable    = ! isDecorative && $row.attr('data-svg') !== '1';
    915921                if      ( filter === 'all' )          show = true;
    916                 else if ( filter === 'missing_any' )  show = ( ! hasAlt && ! isDecorative ) || ( altificationEnableCaption && ! hasCap ) || ( altificationEnableDescription && ! hasDesc );
    917                 else if ( filter === 'missing_alt' )  show = ! hasAlt && ! isDecorative;
     922                else if ( filter === 'missing_any' )  show = countable && ( ! hasAlt || ( altificationEnableCaption && ! hasCap ) || ( altificationEnableDescription && ! hasDesc ) );
     923                else if ( filter === 'missing_alt' )  show = countable && ! hasAlt;
    918924                else if ( filter === 'decorative' )   show = isDecorative;
    919                 else if ( filter === 'missing_cap' )  show = ! hasCap;
    920                 else if ( filter === 'missing_desc' ) show = ! hasDesc;
     925                else if ( filter === 'missing_cap' )  show = countable && ! hasCap;
     926                else if ( filter === 'missing_desc' ) show = countable && ! hasDesc;
    921927                else if ( filter === 'improvable' )        show = $row.attr('data-improvable')       === '1';
    922928                else if ( filter === 'keyword_mismatch' )  show = $row.attr('data-keyword-mismatch') === '1';
  • altification/tags/1.0.13/includes/helpers.php

    r3826858 r3826946  
    864864        'max_tokens'          => 600,
    865865        'credits'             => $credits_cost,
     866        // The platform prices alt_text / caption / description at 1 credit and 'all' at 3
     867        // whatever credits says, and takes credits (clamped 1–3) only for 'both'. Until
     868        // 1.0.13 this was never sent, and from June 2026 the platform read a missing mode as
     869        // 'alt_text' — so multi-field generations were charged 1 credit instead of 2 or 3.
     870        'mode'                => $mode,
    866871        'site_id'             => altification_get_site_id(),
    867872        'site_url'            => get_bloginfo( 'url' ),
    … …  
    25162521
    25172522// Project a Site Scan image set down to the shape used by the cached stats transient:
    2518 // {missing_alt, missing_alt_ids, decorative, seo_gap, seo_gap_ids, improvable, improvable_ids}.
     2523// {missing_alt, missing_alt_ids, missing_cap, missing_cap_ids, missing_desc, missing_desc_ids,
     2524// decorative, seo_gap, seo_gap_ids, improvable, improvable_ids}.
    25192525// Every writer of the transient goes through here, and readers that need a key an older
    25202526// cached copy may lack recompute via altification_get_site_stats().
     2527//
     2528// One rule for every "missing" count: the field is empty, and the image is neither an SVG
     2529// (it can't be generated) nor decorative (a finished state, not a gap). The caption and
     2530// description counts are kept whether or not those fields are turned on — the notice only
     2531// shows a count for a field that is.
    25212532function altification_summarise_site_images( array $images ) {
    2522     $missing_alt     = 0;
    2523     $missing_alt_ids = [];
    2524     $decorative      = 0;
    2525     $seo_gap         = 0;
    2526     $seo_gap_ids     = [];
    2527     $improvable      = 0;
    2528     $improvable_ids  = [];
     2533    $missing_alt      = 0;
     2534    $missing_alt_ids  = [];
     2535    $missing_cap      = 0;
     2536    $missing_cap_ids  = [];
     2537    $missing_desc     = 0;
     2538    $missing_desc_ids = [];
     2539    $decorative       = 0;
     2540    $seo_gap          = 0;
     2541    $seo_gap_ids      = [];
     2542    $improvable       = 0;
     2543    $improvable_ids   = [];
    25292544    foreach ( $images as $i ) {
    25302545        if ( $i['is_decorative'] ) $decorative++;
    2531         if ( ! $i['has_alt'] && ! $i['is_svg'] && ! $i['is_decorative'] ) {
     2546        $countable = ! $i['is_svg'] && ! $i['is_decorative'];
     2547        if ( $countable && ! $i['has_alt'] ) {
    25322548            $missing_alt++;
    25332549            $missing_alt_ids[] = (int) $i['id'];
     2550        }
     2551        if ( $countable && ! $i['has_caption'] ) {
     2552            $missing_cap++;
     2553            $missing_cap_ids[] = (int) $i['id'];
     2554        }
     2555        if ( $countable && ! $i['has_desc'] ) {
     2556            $missing_desc++;
     2557            $missing_desc_ids[] = (int) $i['id'];
    25342558        }
    25352559        if ( $i['keyword_mismatch'] ) {
    … …  
    25502574        // filtered list would show.
    25512575        'missing_alt_ids' => $missing_alt_ids,
     2576        // The same for captions and descriptions, which the notice also counted with its own
     2577        // SQL until 1.0.13 — decorative images and SVGs included.
     2578        'missing_cap'      => $missing_cap,
     2579        'missing_cap_ids'  => $missing_cap_ids,
     2580        'missing_desc'     => $missing_desc,
     2581        'missing_desc_ids' => $missing_desc_ids,
    25522582        'decorative'     => $decorative,
    25532583        'seo_gap'        => $seo_gap,
    … …  
    25832613}
    25842614
     2615// Whether $attachment_id is on one of the cached stats' id lists. $stats may be false.
     2616function altification_site_stats_has( $stats, $list_key, $attachment_id ) {
     2617    return is_array( $stats ) && isset( $stats[ $list_key ] )
     2618        && in_array( (int) $attachment_id, array_map( 'intval', $stats[ $list_key ] ), true );
     2619}
     2620
     2621// Put $attachment_id on, or take it off, one of the cached stats' id lists, and keep the
     2622// matching count ($count_key) equal to the list's length.
     2623function altification_site_stats_set_listed( array &$stats, $list_key, $count_key, $attachment_id, $listed ) {
     2624    $ids = array_values( array_diff( array_map( 'intval', $stats[ $list_key ] ?? [] ), [ (int) $attachment_id ] ) );
     2625    if ( $listed ) {
     2626        $ids[] = (int) $attachment_id;
     2627    }
     2628    $stats[ $list_key ]  = $ids;
     2629    $stats[ $count_key ] = count( $ids );
     2630}
     2631
     2632// Whether a save leaves an image on one of the cached missing-field lists (missing_alt_ids,
     2633// missing_cap_ids, missing_desc_ids) — what the Media Library notice counts and its filters
     2634// list — so the save handlers keep them in step with what the next Site Scan would find.
     2635//
     2636// An image with the field filled, or marked decorative, is never on the list. One already on
     2637// it stays on while the field is still empty. One not on it goes on only when this save made
     2638// it missing: it cleared the field, or it stopped being decorative with the field still
     2639// empty. An image that was already missing the field without being listed was left out by
     2640// the scan on purpose — an SVG, a file the scan can't resolve, or an unattached image the
     2641// "Only count images that are used on a page or post" setting excludes.
     2642function altification_missing_list_after_save( $attachment_id, $listed_before, $had_field, $has_field, $was_decorative, $is_decorative ) {
     2643    if ( $has_field || $is_decorative ) {
     2644        return false;
     2645    }
     2646    if ( $listed_before ) {
     2647        return true;
     2648    }
     2649    return ( $had_field || $was_decorative )
     2650        && get_post_mime_type( $attachment_id ) !== 'image/svg+xml'
     2651        && altification_image_is_counted( $attachment_id );
     2652}
     2653
    25852654function altification_clear_site_stats() {
    25862655    delete_transient( 'altification_site_stats' );
  • altification/tags/1.0.13/includes/media.php

    r3826858 r3826946  
    413413    $query->set( 'post_mime_type', 'image' );
    414414
    415     // Keep the click-through view consistent with the counters that produced it — if the
    416     // notice excluded unattached images from the count, the resulting list must too. That
    417     // applies to the filters the notice still counts with SQL. missing_alt, improvable and
    418     // seo_gap list the exact ids the cached Site Scan counted, which already applied the
    419     // setting its own way (an unattached image found on a page still counts), so narrowing
    420     // them again here could leave the list shorter than the number that linked to it.
    421     $id_filters = [ 'missing_alt', 'improvable', 'seo_gap' ];
     415    // Keep the click-through view consistent with the counters that produced it. Every filter
     416    // but "complete" lists the exact ids the cached Site Scan counted, which already applied
     417    // the "Only count images that are used on a page or post" setting its own way (an
     418    // unattached image found on a page still counts) — narrowing them again here could leave
     419    // the list shorter than the number that linked to it. "complete" is still a query, so it
     420    // still gets the same narrowing.
     421    $id_filters = [ 'missing_alt', 'missing_cap', 'missing_desc', 'missing_any', 'improvable', 'seo_gap' ];
    422422    if ( altification_ignore_unattached() && ! in_array( $filter, $id_filters, true ) ) {
    423423        add_filter( 'posts_where', 'altification_media_filter_attached_only' );
    424424    }
    425425
     426    // The missing-field filters list the sets the notice counted: the cached Site Scan's
     427    // missing_*_ids, which leave out decorative images and SVGs. The queries these replaced
     428    // listed every image with the field empty, so they never matched the counts either.
     429    $missing_ids = function ( $list_keys ) {
     430        $stats = altification_get_site_stats( 'missing_cap_ids' );
     431        $ids   = [];
     432        foreach ( $list_keys as $list_key ) {
     433            $ids = array_merge( $ids, array_map( 'intval', $stats[ $list_key ] ?? [] ) );
     434        }
     435        return $ids ? array_values( array_unique( $ids ) ) : [ 0 ];
     436    };
     437
    426438    switch ( $filter ) {
    427439
    428440        case 'missing_alt':
    429             // The set the notice counted: the cached Site Scan's missing_alt_ids. The meta
    430             // query this replaced listed every image with an empty alt, decorative ones and
    431             // SVGs included, so it never matched the count either.
    432             $stats = altification_get_site_stats( 'missing_alt_ids' );
    433             $ids   = ! empty( $stats['missing_alt_ids'] ) ? array_map( 'intval', $stats['missing_alt_ids'] ) : [ 0 ];
    434             $query->set( 'post__in', $ids );
     441            $query->set( 'post__in', $missing_ids( [ 'missing_alt_ids' ] ) );
    435442            break;
    436443
    437444        case 'missing_cap':
    438             // post_excerpt holds the caption — filter via posts_where
    439             add_filter( 'posts_where', 'altification_media_filter_missing_cap' );
     445            $query->set( 'post__in', $missing_ids( [ 'missing_cap_ids' ] ) );
    440446            break;
    441447
    442448        case 'missing_desc':
    443             add_filter( 'posts_where', 'altification_media_filter_missing_desc' );
     449            $query->set( 'post__in', $missing_ids( [ 'missing_desc_ids' ] ) );
    444450            break;
    445451
    446452        case 'missing_any':
    447             // Handle entirely in posts_where to avoid meta_query parenthesis conflicts
    448             add_filter( 'posts_where', 'altification_media_filter_missing_any' );
     453            // Missing alt text, or a caption or description when that field is turned on —
     454            // the Site Scan's "Missing any". The query this replaced counted captions and
     455            // descriptions even with those fields turned off.
     456            $any_lists = [ 'missing_alt_ids' ];
     457            if ( altification_field_enabled( 'caption' ) )     $any_lists[] = 'missing_cap_ids';
     458            if ( altification_field_enabled( 'description' ) ) $any_lists[] = 'missing_desc_ids';
     459            $query->set( 'post__in', $missing_ids( $any_lists ) );
    449460            break;
    450461
    … …  
    474485} );
    475486
    476 function altification_media_filter_missing_cap( $where ) {
    477     global $wpdb;
    478     remove_filter( 'posts_where', 'altification_media_filter_missing_cap' );
    479     // No user input — table names are from $wpdb object, values are hardcoded literals
    480     return $where . " AND ({$wpdb->posts}.post_excerpt IS NULL OR {$wpdb->posts}.post_excerpt = '')";
    481 }
    482 
    483487function altification_media_filter_attached_only( $where ) {
    484488    global $wpdb;
    485489    remove_filter( 'posts_where', 'altification_media_filter_attached_only' );
    486490    return $where . " AND {$wpdb->posts}.post_parent > 0";
    487 }
    488 
    489 function altification_media_filter_missing_desc( $where ) {
    490     global $wpdb;
    491     remove_filter( 'posts_where', 'altification_media_filter_missing_desc' );
    492     return $where . " AND ({$wpdb->posts}.post_content IS NULL OR {$wpdb->posts}.post_content = '')";
    493 }
    494 
    495 function altification_media_filter_missing_any( $where ) {
    496     global $wpdb;
    497     remove_filter( 'posts_where', 'altification_media_filter_missing_any' );
    498     // The meta_key literal is hardcoded — use prepare() to make intent explicit
    499     $meta_key = '_wp_attachment_image_alt';
    500     return $where . $wpdb->prepare(
    501         " AND (
    502             NOT EXISTS (
    503                 SELECT 1 FROM {$wpdb->postmeta} pm
    504                 WHERE pm.post_id = {$wpdb->posts}.ID
    505                   AND pm.meta_key = %s
    506                   AND pm.meta_value != ''
    507             )
    508             OR ({$wpdb->posts}.post_excerpt IS NULL OR {$wpdb->posts}.post_excerpt = '')
    509             OR ({$wpdb->posts}.post_content IS NULL OR {$wpdb->posts}.post_content = '')
    510         )",
    511         $meta_key
    512     );
    513491}
    514492
    … …  
    534512    // list it linked to would show. Decorative images are not counted or shown here at all:
    535513    // marked decorative is a finished state, not something to fix.
    536     $stats       = altification_get_site_stats( 'missing_alt_ids' );
    537     $missing_alt = (int) ( $stats['missing_alt'] ?? 0 );
    538 
    539     // Captions and descriptions are still counted with SQL — the Site Scan's cached stats
    540     // don't carry them. The toggle uses a threshold value of 0 (filter orphans) or -1 (allow
    541     // all, since post_parent is always >= 0). This keeps the SQL string literal and the
    542     // variable value bound through %d, so PluginCheck doesn't flag string interpolation.
    543     global $wpdb;
    544     $parent_threshold = altification_ignore_unattached() ? 0 : -1;
    545     $missing_cap = altification_field_enabled( 'caption' ) ? (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    546         $wpdb->prepare(
    547             "SELECT COUNT(ID) FROM {$wpdb->posts}
    548              WHERE post_type = %s
    549                AND post_status = %s
    550                AND post_mime_type LIKE %s
    551                AND (post_excerpt IS NULL OR post_excerpt = '')
    552                AND post_parent > %d",
    553             'attachment', 'inherit', 'image/%', $parent_threshold
    554         )
    555     ) : 0;
    556     $missing_desc = altification_field_enabled( 'description' ) ? (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    557         $wpdb->prepare(
    558             "SELECT COUNT(ID) FROM {$wpdb->posts}
    559              WHERE post_type = %s
    560                AND post_status = %s
    561                AND post_mime_type LIKE %s
    562                AND (post_content IS NULL OR post_content = '')
    563                AND post_parent > %d",
    564             'attachment', 'inherit', 'image/%', $parent_threshold
    565         )
    566     ) : 0;
     514    //
     515    // Missing captions and descriptions come from the same place, for the same reasons. Until
     516    // 1.0.13 each had its own SQL, which counted decorative images and SVGs too. They are shown
     517    // only while that field is turned on in Settings.
     518    $stats        = altification_get_site_stats( 'missing_cap_ids' );
     519    $missing_alt  = (int) ( $stats['missing_alt'] ?? 0 );
     520    $missing_cap  = altification_field_enabled( 'caption' )     ? (int) ( $stats['missing_cap'] ?? 0 )  : 0;
     521    $missing_desc = altification_field_enabled( 'description' ) ? (int) ( $stats['missing_desc'] ?? 0 ) : 0;
    567522
    568523    // SEO gap and improvable counts — from the same cached scan as missing alt text above.
  • altification/tags/1.0.13/includes/metabox.php

    r3826858 r3826946  
    438438        });
    439439
    440         // Bulk generate all missing
     440        // Bulk generate all missing. Decorative images and SVGs are skipped, as the Page Scanner
     441        // and Site Scan skip them: an SVG can't be generated, and generating for a decorative
     442        // image would end its decorative status when the result was saved.
    441443        $(document).on('click', '.altification-mb-generate-all', function() {
    442444            var $rows = $('.altification-mb-row').filter(function() {
    443445                var $r = $(this);
     446                if ( $r.attr('data-svg') === '1' || $r.attr('data-decorative') === '1' ) return false;
    444447                if ( shouldSkip( $r ) ) return false;
    445448                return $r.data('has-alt') == '0' ||
    … …  
    587590        $keyword_mismatch = ! $is_svg && ! $is_decorative && $gap_eligible && ( ! $has_alt || ( ! empty( $gap_keyword ) && ! $keyword_reviewed ) );
    588591
    589         if ( ! $has_alt )                          $missing_alt++;
    590         if ( $enable_caption     && ! $has_cap )   $missing_cap++;
    591         if ( $enable_description && ! $has_desc )  $missing_desc++;
     592        // Decorative images and SVGs are never missing anything — the rule every count in the
     593        // plugin uses (altification_summarise_site_images()). These counted them, so a page
     594        // with a decorative image could never show "All complete".
     595        $countable = ! $is_svg && ! $is_decorative;
     596        if ( $countable && ! $has_alt )                          $missing_alt++;
     597        if ( $countable && $enable_caption     && ! $has_cap )   $missing_cap++;
     598        if ( $countable && $enable_description && ! $has_desc )  $missing_desc++;
    592599
    593600        $images[] = compact( 'attachment_id', 'img_src', 'img_url', 'alt_text', 'caption', 'description', 'has_alt', 'has_cap', 'has_desc', 'improvable', 'keyword_mismatch', 'gap_eligible', 'shared_count', 'shared_titles', 'card_keyword', 'altified', 'is_svg', 'is_decorative' );
    … …  
    596603    $total        = count( $images );
    597604    $missing_any  = count( array_filter( $images, fn( $i ) =>
    598         ! $i['has_alt'] ||
    599         ( $enable_caption     && ! $i['has_cap'] ) ||
    600         ( $enable_description && ! $i['has_desc'] )
     605        ! $i['is_svg'] && ! $i['is_decorative'] && (
     606            ! $i['has_alt'] ||
     607            ( $enable_caption     && ! $i['has_cap'] ) ||
     608            ( $enable_description && ! $i['has_desc'] )
     609        )
    601610    ) );
    602611    $improvable_any       = count( array_filter( $images, fn( $i ) => $i['improvable'] ) );
  • altification/tags/1.0.13/includes/settings.php

    r3680063 r3826946  
    386386                            <?php esc_html_e( 'Automatically generate alt text when an image is uploaded', 'altification' ); ?>
    387387                        </label>
    388                         <p class="description"><?php esc_html_e( 'When enabled, every uploaded image is generated automatically. Images uploaded into a page or post use that page\'s title and SEO keyphrase. Images uploaded directly to the media library use the Default keyword (if set) or your site name as the keyword, with your About your business context applied — so no image is ever left without alt text.', 'altification' ); ?> <?php esc_html_e( 'Note: if a media-library image is later added to a product or page, the Site Scan will flag it as an SEO gap — because the alt text was generated without that page\'s keyword. Regenerating from the Site Scan fixes it instantly.', 'altification' ); ?></p>
     388                        <p class="description"><?php esc_html_e( 'When enabled, the fields turned on here are generated as soon as an image is uploaded. An image uploaded into a page or post uses that page\'s title and SEO keyphrase. An image uploaded straight to the media library uses your Default keyword, with your About your business context applied — if no Default keyword is set, it isn\'t generated, so set one to cover those uploads too. SVGs are always skipped, as they can\'t be generated.', 'altification' ); ?> <?php esc_html_e( 'Note: if an image is later used on a different page from the one it was uploaded to, the Site Scan can flag it — as Improvable or as an SEO gap — so you can regenerate it with that page\'s keyword.', 'altification' ); ?></p>
    389389                    </td>
    390390                </tr>
  • altification/tags/1.0.13/readme.txt

    r3826858 r3826946  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 1.0.12
     7Stable tag: 1.0.13
    88License: GPL-2.0-or-later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    110110
    111111== Changelog ==
     112
     113= 1.0.13 =
     114* Fixed: the Media Library banner's missing captions and missing descriptions counts included decorative images and SVGs, so they didn't match the Site Scan. They now come from the Site Scan, and their links list exactly those images. "Missing any field" now counts captions and descriptions only when those fields are turned on
     115* Fixed: the Site Scan's caption and description counts and tabs included decorative images and SVGs when the page first loaded, then changed after your first action. SVGs no longer appear on the No alt tab either, which never counted them
     116* Fixed: the editor sidebar counted decorative images as missing alt text, captions and descriptions, so a page with one never showed "All complete", and "Generate missing" generated for them. Decorative images and SVGs are now skipped, as they are in the Page Scanner and Site Scan
     117* Corrected the help text for generating alt text on upload: images uploaded straight to the media library are generated only when a Default keyword is set, and SVGs are skipped
     118* Each generation request now tells altification.ai which fields it is for, so it is charged one credit per field as listed
    112119
    113120= 1.0.12 =
    … …  
    212219== Upgrade Notice ==
    213220
     221= 1.0.13 =
     222Caption and description counts now match the Site Scan everywhere, and decorative images are no longer counted as missing anything, or generated for, in the editor sidebar.
     223
    214224= 1.0.12 =
    215225Images used on more than one page now show their SEO gaps on every screen, and the Media Library banner's missing alt text count now matches the Site Scan. Decorative images no longer count. Also prepares auto-generate on upload for WordPress 7.2.
  • altification/trunk/altification.php

    r3826858 r3826946  
    44 * Plugin URI:        https://altification.ai/plugin
    55 * Description:       AI-powered alt text, caption and description generator for WordPress media.
    6  * Version:           1.0.12
     6 * Version:           1.0.13
    77 * Requires at least: 6.0
    88 * Requires PHP:      7.4
    … …  
    1818}
    1919
    20 define( 'ALTIFICATION_VERSION', '1.0.12' );
     20define( 'ALTIFICATION_VERSION', '1.0.13' );
    2121define( 'ALTIFICATION_DIR', plugin_dir_path( __FILE__ ) );
    2222define( 'ALTIFICATION_URL', plugin_dir_url( __FILE__ ) );
  • altification/trunk/includes/ajax.php

    r3826858 r3826946  
    404404    $keyword_mismatch  = $has_alt_after && $saved_keyword !== '' && ! $is_reviewed_after;
    405405
    406     // Missing alt text is tracked by membership of missing_alt_ids — the list the Media Library
    407     // notice counts and its filter shows — so a save moves this image on or off it the way the
    408     // next Site Scan would. It comes off once it has alt text (or is decorative). It goes on
    409     // only when this save cleared alt text it had: an image that had none and isn't listed
    410     // was left out by the scan on purpose (an SVG, or a file it can't resolve).
    411     $is_decorative_after   = get_post_meta( $attachment_id, '_altification_decorative', true ) === '1';
    412     $missing_listed_before = isset( $stats['missing_alt_ids'] )
    413         && in_array( $attachment_id, array_map( 'intval', $stats['missing_alt_ids'] ), true );
    414     $missing_listed_after  = $missing_listed_before
    415         ? ( ! $has_alt_after && ! $is_decorative_after )
    416         : ( $had_alt_before && ! $has_alt_after && ! $is_decorative_after
    417             && get_post_mime_type( $attachment_id ) !== 'image/svg+xml'
    418             && altification_image_is_counted( $attachment_id ) );
    419 
    420     // Applied to the in-memory copy only; it is written back below along with the SEO gap and
    421     // improvable updates, for counted images.
    422     if ( $stats !== false ) {
    423         if ( isset( $stats['missing_alt_ids'] ) ) {
    424             if ( $missing_listed_before !== $missing_listed_after ) {
    425                 $stats['missing_alt_ids'] = $missing_listed_after
    426                     ? array_merge( array_map( 'intval', $stats['missing_alt_ids'] ), [ $attachment_id ] )
    427                     : array_values( array_diff( array_map( 'intval', $stats['missing_alt_ids'] ), [ $attachment_id ] ) );
    428                 $stats['missing_alt']     = count( $stats['missing_alt_ids'] );
    429             }
    430         } elseif ( altification_image_is_counted( $attachment_id ) && ! $had_alt_before && $has_alt_after ) {
    431             // Stats cached before missing_alt_ids existed — the count alone, as before.
    432             $stats['missing_alt'] = max( 0, (int) $stats['missing_alt'] - 1 );
     406    // Missing alt text, captions and descriptions are tracked by membership of the cached
     407    // missing_*_ids lists — what the Media Library notice counts and its filters show — so a
     408    // save moves this image on or off each list the way the next Site Scan would. The rule is
     409    // altification_missing_list_after_save().
     410    $is_decorative_after = get_post_meta( $attachment_id, '_altification_decorative', true ) === '1';
     411    $has_cap_after       = $write_caption     ? ! empty( $caption_value )     : $had_cap_before;
     412    $has_desc_after      = $write_description ? ! empty( $description_value ) : $had_desc_before;
     413    $missing_fields      = [
     414        // list key => [ count key, field filled before, field filled after ]
     415        'missing_alt_ids'  => [ 'missing_alt',  $had_alt_before,  $has_alt_after ],
     416        'missing_cap_ids'  => [ 'missing_cap',  $had_cap_before,  $has_cap_after ],
     417        'missing_desc_ids' => [ 'missing_desc', $had_desc_before, $has_desc_after ],
     418    ];
     419    $missing_listed = []; // list key => [ listed before, listed after ]
     420    foreach ( $missing_fields as $list_key => [ $count_key, $had_field, $has_field ] ) {
     421        $listed_before = altification_site_stats_has( $stats, $list_key, $attachment_id );
     422        $listed_after  = altification_missing_list_after_save( $attachment_id, $listed_before, $had_field, $has_field, $was_decorative_before, $is_decorative_after );
     423        $missing_listed[ $list_key ] = [ $listed_before, $listed_after ];
     424        // Applied to the in-memory copy only; it is written back below along with the SEO gap
     425        // and improvable updates, for counted images.
     426        if ( isset( $stats[ $list_key ] ) && $listed_before !== $listed_after ) {
     427            altification_site_stats_set_listed( $stats, $list_key, $count_key, $attachment_id, $listed_after );
    433428        }
     429    }
     430    if ( $stats !== false && ! isset( $stats['missing_alt_ids'] )
     431        && altification_image_is_counted( $attachment_id ) && ! $had_alt_before && $has_alt_after ) {
     432        // Stats cached before missing_alt_ids existed — the count alone, as before.
     433        $stats['missing_alt'] = max( 0, (int) $stats['missing_alt'] - 1 );
    434434    }
    435435
    … …  
    474474    // moved out of that bucket), +1 means it climbs. JS applies these to the on-screen
    475475    // counter spans so the notice ticks live without a page reload.
    476     $has_cap_after        = $write_caption     ? ! empty( $caption_value )     : $had_cap_before;
    477     $has_desc_after       = $write_description ? ! empty( $description_value ) : $had_desc_before;
    478476    $is_improvable_after  = altification_is_image_improvable( $attachment_id );
    479477    // If the ignore-unattached toggle is on and this image has no parent, it contributes
    480478    // 0 to every counter — zero out all deltas so the JS notice doesn't tick on something
    481     // the SQL queries are excluding.
     479    // the cached counts are excluding.
    482480    $is_counted = altification_image_is_counted( $attachment_id );
    483481    if ( $is_counted ) {
    484         // The notice's missing alt count is the length of missing_alt_ids, so it moves exactly
    485         // when this save moved the image on or off that list (worked out above). Without the
    486         // list — stats cached by an older version — fall back to the old rule: no alt text and
    487         // not decorative.
    488         if ( isset( $stats['missing_alt_ids'] ) ) {
    489             $contrib_missing_before = $missing_listed_before ? 1 : 0;
    490             $contrib_missing_after  = $missing_listed_after  ? 1 : 0;
    491         } else {
    492             $contrib_missing_before = ( ! $had_alt_before && ! $was_decorative_before ) ? 1 : 0;
    493             $contrib_missing_after  = ( ! $has_alt_after  && ! $is_decorative_after )  ? 1 : 0;
    494         }
     482        // The notice's missing counts are the lengths of the missing_*_ids lists, so each moves
     483        // exactly when this save moved the image on or off that list (worked out above).
     484        // Without the lists — stats cached by an older version — fall back to the old rules.
     485        $list_delta = function ( $list_key, $fallback ) use ( $stats, $missing_listed ) {
     486            if ( ! isset( $stats[ $list_key ] ) ) {
     487                return $fallback;
     488            }
     489            return (int) $missing_listed[ $list_key ][1] - (int) $missing_listed[ $list_key ][0];
     490        };
    495491        $notice_delta = [
    496             'missing_alt'  => $contrib_missing_after - $contrib_missing_before,
     492            'missing_alt'  => $list_delta( 'missing_alt_ids',
     493                ( ( ! $has_alt_after && ! $is_decorative_after ) ? 1 : 0 ) - ( ( ! $had_alt_before && ! $was_decorative_before ) ? 1 : 0 ) ),
    497494            'decorative'   => ( $is_decorative_after ? 1 : 0 ) - ( $was_decorative_before ? 1 : 0 ),
    498             'missing_cap'  => ( $has_cap_after  ? 0 : 1 ) - ( $had_cap_before  ? 0 : 1 ),
    499             'missing_desc' => ( $has_desc_after ? 0 : 1 ) - ( $had_desc_before ? 0 : 1 ),
     495            'missing_cap'  => $list_delta( 'missing_cap_ids',  ( $has_cap_after  ? 0 : 1 ) - ( $had_cap_before  ? 0 : 1 ) ),
     496            'missing_desc' => $list_delta( 'missing_desc_ids', ( $has_desc_after ? 0 : 1 ) - ( $had_desc_before ? 0 : 1 ) ),
    500497            'improvable'   => ( $is_improvable_after ? 1 : 0 ) - ( $was_improvable_before ? 1 : 0 ),
    501498            'seo_gap'      => ( $has_seo_gap_after ? 1 : 0 ) - ( $had_seo_gap_before ? 1 : 0 ),
    … …  
    680677    } else {
    681678        // After: alt is empty, decorative=1, no SEO gap, not improvable.
    682         // The notice's missing alt count is the length of missing_alt_ids, so this drops it
    683         // only when the image was on that list. Stats cached without the list fall back to the
    684         // old rule: no alt text and not already decorative.
    685         $missing_listed_before  = isset( $stats['missing_alt_ids'] )
    686             && in_array( $attachment_id, array_map( 'intval', $stats['missing_alt_ids'] ), true );
     679        // Decorative is a finished state, so the image comes off all three missing lists, and
     680        // each notice count drops only if it was on that list. Stats cached without the lists
     681        // fall back to the old rule for alt text, and leave captions and descriptions alone.
    687682        $contrib_missing_before = isset( $stats['missing_alt_ids'] )
    688             ? ( $missing_listed_before ? 1 : 0 )
     683            ? ( altification_site_stats_has( $stats, 'missing_alt_ids', $attachment_id ) ? 1 : 0 )
    689684            : ( ( ! $had_alt_before && ! $was_decorative_before ) ? 1 : 0 );
    690685        // contribution after: alt empty + decorative=1 → 0 (decoratives are excluded from missing_alt)
    … …  
    692687            'missing_alt'  => 0 - $contrib_missing_before,
    693688            'decorative'   => 1 - ( $was_decorative_before ? 1 : 0 ),
    694             'missing_cap'  => 0,
    695             'missing_desc' => 0,
     689            'missing_cap'  => altification_site_stats_has( $stats, 'missing_cap_ids', $attachment_id ) ? -1 : 0,
     690            'missing_desc' => altification_site_stats_has( $stats, 'missing_desc_ids', $attachment_id ) ? -1 : 0,
    696691            'improvable'   => 0 - ( $was_improvable_before ? 1 : 0 ),
    697692            'seo_gap'      => 0 - ( $had_seo_gap_before ? 1 : 0 ),
    … …  
    700695        // Keep the site-stats transient in sync — admin bar reads from it.
    701696        if ( $stats !== false ) {
    702             if ( isset( $stats['missing_alt_ids'] ) ) {
    703                 $stats['missing_alt_ids'] = array_values( array_diff( array_map( 'intval', $stats['missing_alt_ids'] ), [ $attachment_id ] ) );
    704                 $stats['missing_alt']     = count( $stats['missing_alt_ids'] );
    705             } else {
     697            foreach ( [ 'missing_alt_ids' => 'missing_alt', 'missing_cap_ids' => 'missing_cap', 'missing_desc_ids' => 'missing_desc' ] as $list_key => $count_key ) {
     698                if ( isset( $stats[ $list_key ] ) ) {
     699                    altification_site_stats_set_listed( $stats, $list_key, $count_key, $attachment_id, false );
     700                }
     701            }
     702            if ( ! isset( $stats['missing_alt_ids'] ) ) {
    706703                $stats['missing_alt'] = max( 0, (int) $stats['missing_alt'] + $notice_delta['missing_alt'] );
    707704            }
  • altification/trunk/includes/bulk.php

    r3826858 r3826946  
    130130    $missing_alt      = count( array_filter( $all_images, fn( $i ) => ! $i['has_alt'] && ! $i['is_svg'] && ! $i['is_decorative'] ) );
    131131    $decorative_count = count( array_filter( $all_images, fn( $i ) => $i['is_decorative'] ) );
    132     $missing_cap  = $enable_caption     ? count( array_filter( $all_images, fn( $i ) => ! $i['has_caption'] ) ) : 0;
    133     $missing_desc = $enable_description ? count( array_filter( $all_images, fn( $i ) => ! $i['has_desc'] ) )    : 0;
     132    // Same exclusions as $missing_alt, and as altification_summarise_site_images() and the JS
     133    // recounts below. These used to count decorative images and SVGs, so the cards and tabs
     134    // dropped to a different number the first time the JS recounted them.
     135    $missing_cap  = $enable_caption     ? count( array_filter( $all_images, fn( $i ) => ! $i['has_caption'] && ! $i['is_svg'] && ! $i['is_decorative'] ) ) : 0;
     136    $missing_desc = $enable_description ? count( array_filter( $all_images, fn( $i ) => ! $i['has_desc']    && ! $i['is_svg'] && ! $i['is_decorative'] ) ) : 0;
    134137    // Same exclusions as $missing_alt above, and as the JS recount in
    135138    // altificationUpdateFilterCredits(): an SVG can't be generated and a decorative image is
    … …  
    913916
    914917                var isDecorative = $row.attr('data-decorative') === '1';
     918                // The missing filters list what the counts count: decorative images and SVGs
     919                // are never missing anything (see altificationUpdateFilterCredits()).
     920                var countable    = ! isDecorative && $row.attr('data-svg') !== '1';
    915921                if      ( filter === 'all' )          show = true;
    916                 else if ( filter === 'missing_any' )  show = ( ! hasAlt && ! isDecorative ) || ( altificationEnableCaption && ! hasCap ) || ( altificationEnableDescription && ! hasDesc );
    917                 else if ( filter === 'missing_alt' )  show = ! hasAlt && ! isDecorative;
     922                else if ( filter === 'missing_any' )  show = countable && ( ! hasAlt || ( altificationEnableCaption && ! hasCap ) || ( altificationEnableDescription && ! hasDesc ) );
     923                else if ( filter === 'missing_alt' )  show = countable && ! hasAlt;
    918924                else if ( filter === 'decorative' )   show = isDecorative;
    919                 else if ( filter === 'missing_cap' )  show = ! hasCap;
    920                 else if ( filter === 'missing_desc' ) show = ! hasDesc;
     925                else if ( filter === 'missing_cap' )  show = countable && ! hasCap;
     926                else if ( filter === 'missing_desc' ) show = countable && ! hasDesc;
    921927                else if ( filter === 'improvable' )        show = $row.attr('data-improvable')       === '1';
    922928                else if ( filter === 'keyword_mismatch' )  show = $row.attr('data-keyword-mismatch') === '1';
  • altification/trunk/includes/helpers.php

    r3826858 r3826946  
    864864        'max_tokens'          => 600,
    865865        'credits'             => $credits_cost,
     866        // The platform prices alt_text / caption / description at 1 credit and 'all' at 3
     867        // whatever credits says, and takes credits (clamped 1–3) only for 'both'. Until
     868        // 1.0.13 this was never sent, and from June 2026 the platform read a missing mode as
     869        // 'alt_text' — so multi-field generations were charged 1 credit instead of 2 or 3.
     870        'mode'                => $mode,
    866871        'site_id'             => altification_get_site_id(),
    867872        'site_url'            => get_bloginfo( 'url' ),
    … …  
    25162521
    25172522// Project a Site Scan image set down to the shape used by the cached stats transient:
    2518 // {missing_alt, missing_alt_ids, decorative, seo_gap, seo_gap_ids, improvable, improvable_ids}.
     2523// {missing_alt, missing_alt_ids, missing_cap, missing_cap_ids, missing_desc, missing_desc_ids,
     2524// decorative, seo_gap, seo_gap_ids, improvable, improvable_ids}.
    25192525// Every writer of the transient goes through here, and readers that need a key an older
    25202526// cached copy may lack recompute via altification_get_site_stats().
     2527//
     2528// One rule for every "missing" count: the field is empty, and the image is neither an SVG
     2529// (it can't be generated) nor decorative (a finished state, not a gap). The caption and
     2530// description counts are kept whether or not those fields are turned on — the notice only
     2531// shows a count for a field that is.
    25212532function altification_summarise_site_images( array $images ) {
    2522     $missing_alt     = 0;
    2523     $missing_alt_ids = [];
    2524     $decorative      = 0;
    2525     $seo_gap         = 0;
    2526     $seo_gap_ids     = [];
    2527     $improvable      = 0;
    2528     $improvable_ids  = [];
     2533    $missing_alt      = 0;
     2534    $missing_alt_ids  = [];
     2535    $missing_cap      = 0;
     2536    $missing_cap_ids  = [];
     2537    $missing_desc     = 0;
     2538    $missing_desc_ids = [];
     2539    $decorative       = 0;
     2540    $seo_gap          = 0;
     2541    $seo_gap_ids      = [];
     2542    $improvable       = 0;
     2543    $improvable_ids   = [];
    25292544    foreach ( $images as $i ) {
    25302545        if ( $i['is_decorative'] ) $decorative++;
    2531         if ( ! $i['has_alt'] && ! $i['is_svg'] && ! $i['is_decorative'] ) {
     2546        $countable = ! $i['is_svg'] && ! $i['is_decorative'];
     2547        if ( $countable && ! $i['has_alt'] ) {
    25322548            $missing_alt++;
    25332549            $missing_alt_ids[] = (int) $i['id'];
     2550        }
     2551        if ( $countable && ! $i['has_caption'] ) {
     2552            $missing_cap++;
     2553            $missing_cap_ids[] = (int) $i['id'];
     2554        }
     2555        if ( $countable && ! $i['has_desc'] ) {
     2556            $missing_desc++;
     2557            $missing_desc_ids[] = (int) $i['id'];
    25342558        }
    25352559        if ( $i['keyword_mismatch'] ) {
    … …  
    25502574        // filtered list would show.
    25512575        'missing_alt_ids' => $missing_alt_ids,
     2576        // The same for captions and descriptions, which the notice also counted with its own
     2577        // SQL until 1.0.13 — decorative images and SVGs included.
     2578        'missing_cap'      => $missing_cap,
     2579        'missing_cap_ids'  => $missing_cap_ids,
     2580        'missing_desc'     => $missing_desc,
     2581        'missing_desc_ids' => $missing_desc_ids,
    25522582        'decorative'     => $decorative,
    25532583        'seo_gap'        => $seo_gap,
    … …  
    25832613}
    25842614
     2615// Whether $attachment_id is on one of the cached stats' id lists. $stats may be false.
     2616function altification_site_stats_has( $stats, $list_key, $attachment_id ) {
     2617    return is_array( $stats ) && isset( $stats[ $list_key ] )
     2618        && in_array( (int) $attachment_id, array_map( 'intval', $stats[ $list_key ] ), true );
     2619}
     2620
     2621// Put $attachment_id on, or take it off, one of the cached stats' id lists, and keep the
     2622// matching count ($count_key) equal to the list's length.
     2623function altification_site_stats_set_listed( array &$stats, $list_key, $count_key, $attachment_id, $listed ) {
     2624    $ids = array_values( array_diff( array_map( 'intval', $stats[ $list_key ] ?? [] ), [ (int) $attachment_id ] ) );
     2625    if ( $listed ) {
     2626        $ids[] = (int) $attachment_id;
     2627    }
     2628    $stats[ $list_key ]  = $ids;
     2629    $stats[ $count_key ] = count( $ids );
     2630}
     2631
     2632// Whether a save leaves an image on one of the cached missing-field lists (missing_alt_ids,
     2633// missing_cap_ids, missing_desc_ids) — what the Media Library notice counts and its filters
     2634// list — so the save handlers keep them in step with what the next Site Scan would find.
     2635//
     2636// An image with the field filled, or marked decorative, is never on the list. One already on
     2637// it stays on while the field is still empty. One not on it goes on only when this save made
     2638// it missing: it cleared the field, or it stopped being decorative with the field still
     2639// empty. An image that was already missing the field without being listed was left out by
     2640// the scan on purpose — an SVG, a file the scan can't resolve, or an unattached image the
     2641// "Only count images that are used on a page or post" setting excludes.
     2642function altification_missing_list_after_save( $attachment_id, $listed_before, $had_field, $has_field, $was_decorative, $is_decorative ) {
     2643    if ( $has_field || $is_decorative ) {
     2644        return false;
     2645    }
     2646    if ( $listed_before ) {
     2647        return true;
     2648    }
     2649    return ( $had_field || $was_decorative )
     2650        && get_post_mime_type( $attachment_id ) !== 'image/svg+xml'
     2651        && altification_image_is_counted( $attachment_id );
     2652}
     2653
    25852654function altification_clear_site_stats() {
    25862655    delete_transient( 'altification_site_stats' );
  • altification/trunk/includes/media.php

    r3826858 r3826946  
    413413    $query->set( 'post_mime_type', 'image' );
    414414
    415     // Keep the click-through view consistent with the counters that produced it — if the
    416     // notice excluded unattached images from the count, the resulting list must too. That
    417     // applies to the filters the notice still counts with SQL. missing_alt, improvable and
    418     // seo_gap list the exact ids the cached Site Scan counted, which already applied the
    419     // setting its own way (an unattached image found on a page still counts), so narrowing
    420     // them again here could leave the list shorter than the number that linked to it.
    421     $id_filters = [ 'missing_alt', 'improvable', 'seo_gap' ];
     415    // Keep the click-through view consistent with the counters that produced it. Every filter
     416    // but "complete" lists the exact ids the cached Site Scan counted, which already applied
     417    // the "Only count images that are used on a page or post" setting its own way (an
     418    // unattached image found on a page still counts) — narrowing them again here could leave
     419    // the list shorter than the number that linked to it. "complete" is still a query, so it
     420    // still gets the same narrowing.
     421    $id_filters = [ 'missing_alt', 'missing_cap', 'missing_desc', 'missing_any', 'improvable', 'seo_gap' ];
    422422    if ( altification_ignore_unattached() && ! in_array( $filter, $id_filters, true ) ) {
    423423        add_filter( 'posts_where', 'altification_media_filter_attached_only' );
    424424    }
    425425
     426    // The missing-field filters list the sets the notice counted: the cached Site Scan's
     427    // missing_*_ids, which leave out decorative images and SVGs. The queries these replaced
     428    // listed every image with the field empty, so they never matched the counts either.
     429    $missing_ids = function ( $list_keys ) {
     430        $stats = altification_get_site_stats( 'missing_cap_ids' );
     431        $ids   = [];
     432        foreach ( $list_keys as $list_key ) {
     433            $ids = array_merge( $ids, array_map( 'intval', $stats[ $list_key ] ?? [] ) );
     434        }
     435        return $ids ? array_values( array_unique( $ids ) ) : [ 0 ];
     436    };
     437
    426438    switch ( $filter ) {
    427439
    428440        case 'missing_alt':
    429             // The set the notice counted: the cached Site Scan's missing_alt_ids. The meta
    430             // query this replaced listed every image with an empty alt, decorative ones and
    431             // SVGs included, so it never matched the count either.
    432             $stats = altification_get_site_stats( 'missing_alt_ids' );
    433             $ids   = ! empty( $stats['missing_alt_ids'] ) ? array_map( 'intval', $stats['missing_alt_ids'] ) : [ 0 ];
    434             $query->set( 'post__in', $ids );
     441            $query->set( 'post__in', $missing_ids( [ 'missing_alt_ids' ] ) );
    435442            break;
    436443
    437444        case 'missing_cap':
    438             // post_excerpt holds the caption — filter via posts_where
    439             add_filter( 'posts_where', 'altification_media_filter_missing_cap' );
     445            $query->set( 'post__in', $missing_ids( [ 'missing_cap_ids' ] ) );
    440446            break;
    441447
    442448        case 'missing_desc':
    443             add_filter( 'posts_where', 'altification_media_filter_missing_desc' );
     449            $query->set( 'post__in', $missing_ids( [ 'missing_desc_ids' ] ) );
    444450            break;
    445451
    446452        case 'missing_any':
    447             // Handle entirely in posts_where to avoid meta_query parenthesis conflicts
    448             add_filter( 'posts_where', 'altification_media_filter_missing_any' );
     453            // Missing alt text, or a caption or description when that field is turned on —
     454            // the Site Scan's "Missing any". The query this replaced counted captions and
     455            // descriptions even with those fields turned off.
     456            $any_lists = [ 'missing_alt_ids' ];
     457            if ( altification_field_enabled( 'caption' ) )     $any_lists[] = 'missing_cap_ids';
     458            if ( altification_field_enabled( 'description' ) ) $any_lists[] = 'missing_desc_ids';
     459            $query->set( 'post__in', $missing_ids( $any_lists ) );
    449460            break;
    450461
    … …  
    474485} );
    475486
    476 function altification_media_filter_missing_cap( $where ) {
    477     global $wpdb;
    478     remove_filter( 'posts_where', 'altification_media_filter_missing_cap' );
    479     // No user input — table names are from $wpdb object, values are hardcoded literals
    480     return $where . " AND ({$wpdb->posts}.post_excerpt IS NULL OR {$wpdb->posts}.post_excerpt = '')";
    481 }
    482 
    483487function altification_media_filter_attached_only( $where ) {
    484488    global $wpdb;
    485489    remove_filter( 'posts_where', 'altification_media_filter_attached_only' );
    486490    return $where . " AND {$wpdb->posts}.post_parent > 0";
    487 }
    488 
    489 function altification_media_filter_missing_desc( $where ) {
    490     global $wpdb;
    491     remove_filter( 'posts_where', 'altification_media_filter_missing_desc' );
    492     return $where . " AND ({$wpdb->posts}.post_content IS NULL OR {$wpdb->posts}.post_content = '')";
    493 }
    494 
    495 function altification_media_filter_missing_any( $where ) {
    496     global $wpdb;
    497     remove_filter( 'posts_where', 'altification_media_filter_missing_any' );
    498     // The meta_key literal is hardcoded — use prepare() to make intent explicit
    499     $meta_key = '_wp_attachment_image_alt';
    500     return $where . $wpdb->prepare(
    501         " AND (
    502             NOT EXISTS (
    503                 SELECT 1 FROM {$wpdb->postmeta} pm
    504                 WHERE pm.post_id = {$wpdb->posts}.ID
    505                   AND pm.meta_key = %s
    506                   AND pm.meta_value != ''
    507             )
    508             OR ({$wpdb->posts}.post_excerpt IS NULL OR {$wpdb->posts}.post_excerpt = '')
    509             OR ({$wpdb->posts}.post_content IS NULL OR {$wpdb->posts}.post_content = '')
    510         )",
    511         $meta_key
    512     );
    513491}
    514492
    … …  
    534512    // list it linked to would show. Decorative images are not counted or shown here at all:
    535513    // marked decorative is a finished state, not something to fix.
    536     $stats       = altification_get_site_stats( 'missing_alt_ids' );
    537     $missing_alt = (int) ( $stats['missing_alt'] ?? 0 );
    538 
    539     // Captions and descriptions are still counted with SQL — the Site Scan's cached stats
    540     // don't carry them. The toggle uses a threshold value of 0 (filter orphans) or -1 (allow
    541     // all, since post_parent is always >= 0). This keeps the SQL string literal and the
    542     // variable value bound through %d, so PluginCheck doesn't flag string interpolation.
    543     global $wpdb;
    544     $parent_threshold = altification_ignore_unattached() ? 0 : -1;
    545     $missing_cap = altification_field_enabled( 'caption' ) ? (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    546         $wpdb->prepare(
    547             "SELECT COUNT(ID) FROM {$wpdb->posts}
    548              WHERE post_type = %s
    549                AND post_status = %s
    550                AND post_mime_type LIKE %s
    551                AND (post_excerpt IS NULL OR post_excerpt = '')
    552                AND post_parent > %d",
    553             'attachment', 'inherit', 'image/%', $parent_threshold
    554         )
    555     ) : 0;
    556     $missing_desc = altification_field_enabled( 'description' ) ? (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    557         $wpdb->prepare(
    558             "SELECT COUNT(ID) FROM {$wpdb->posts}
    559              WHERE post_type = %s
    560                AND post_status = %s
    561                AND post_mime_type LIKE %s
    562                AND (post_content IS NULL OR post_content = '')
    563                AND post_parent > %d",
    564             'attachment', 'inherit', 'image/%', $parent_threshold
    565         )
    566     ) : 0;
     514    //
     515    // Missing captions and descriptions come from the same place, for the same reasons. Until
     516    // 1.0.13 each had its own SQL, which counted decorative images and SVGs too. They are shown
     517    // only while that field is turned on in Settings.
     518    $stats        = altification_get_site_stats( 'missing_cap_ids' );
     519    $missing_alt  = (int) ( $stats['missing_alt'] ?? 0 );
     520    $missing_cap  = altification_field_enabled( 'caption' )     ? (int) ( $stats['missing_cap'] ?? 0 )  : 0;
     521    $missing_desc = altification_field_enabled( 'description' ) ? (int) ( $stats['missing_desc'] ?? 0 ) : 0;
    567522
    568523    // SEO gap and improvable counts — from the same cached scan as missing alt text above.
  • altification/trunk/includes/metabox.php

    r3826858 r3826946  
    438438        });
    439439
    440         // Bulk generate all missing
     440        // Bulk generate all missing. Decorative images and SVGs are skipped, as the Page Scanner
     441        // and Site Scan skip them: an SVG can't be generated, and generating for a decorative
     442        // image would end its decorative status when the result was saved.
    441443        $(document).on('click', '.altification-mb-generate-all', function() {
    442444            var $rows = $('.altification-mb-row').filter(function() {
    443445                var $r = $(this);
     446                if ( $r.attr('data-svg') === '1' || $r.attr('data-decorative') === '1' ) return false;
    444447                if ( shouldSkip( $r ) ) return false;
    445448                return $r.data('has-alt') == '0' ||
    … …  
    587590        $keyword_mismatch = ! $is_svg && ! $is_decorative && $gap_eligible && ( ! $has_alt || ( ! empty( $gap_keyword ) && ! $keyword_reviewed ) );
    588591
    589         if ( ! $has_alt )                          $missing_alt++;
    590         if ( $enable_caption     && ! $has_cap )   $missing_cap++;
    591         if ( $enable_description && ! $has_desc )  $missing_desc++;
     592        // Decorative images and SVGs are never missing anything — the rule every count in the
     593        // plugin uses (altification_summarise_site_images()). These counted them, so a page
     594        // with a decorative image could never show "All complete".
     595        $countable = ! $is_svg && ! $is_decorative;
     596        if ( $countable && ! $has_alt )                          $missing_alt++;
     597        if ( $countable && $enable_caption     && ! $has_cap )   $missing_cap++;
     598        if ( $countable && $enable_description && ! $has_desc )  $missing_desc++;
    592599
    593600        $images[] = compact( 'attachment_id', 'img_src', 'img_url', 'alt_text', 'caption', 'description', 'has_alt', 'has_cap', 'has_desc', 'improvable', 'keyword_mismatch', 'gap_eligible', 'shared_count', 'shared_titles', 'card_keyword', 'altified', 'is_svg', 'is_decorative' );
    … …  
    596603    $total        = count( $images );
    597604    $missing_any  = count( array_filter( $images, fn( $i ) =>
    598         ! $i['has_alt'] ||
    599         ( $enable_caption     && ! $i['has_cap'] ) ||
    600         ( $enable_description && ! $i['has_desc'] )
     605        ! $i['is_svg'] && ! $i['is_decorative'] && (
     606            ! $i['has_alt'] ||
     607            ( $enable_caption     && ! $i['has_cap'] ) ||
     608            ( $enable_description && ! $i['has_desc'] )
     609        )
    601610    ) );
    602611    $improvable_any       = count( array_filter( $images, fn( $i ) => $i['improvable'] ) );
  • altification/trunk/includes/settings.php

    r3680063 r3826946  
    386386                            <?php esc_html_e( 'Automatically generate alt text when an image is uploaded', 'altification' ); ?>
    387387                        </label>
    388                         <p class="description"><?php esc_html_e( 'When enabled, every uploaded image is generated automatically. Images uploaded into a page or post use that page\'s title and SEO keyphrase. Images uploaded directly to the media library use the Default keyword (if set) or your site name as the keyword, with your About your business context applied — so no image is ever left without alt text.', 'altification' ); ?> <?php esc_html_e( 'Note: if a media-library image is later added to a product or page, the Site Scan will flag it as an SEO gap — because the alt text was generated without that page\'s keyword. Regenerating from the Site Scan fixes it instantly.', 'altification' ); ?></p>
     388                        <p class="description"><?php esc_html_e( 'When enabled, the fields turned on here are generated as soon as an image is uploaded. An image uploaded into a page or post uses that page\'s title and SEO keyphrase. An image uploaded straight to the media library uses your Default keyword, with your About your business context applied — if no Default keyword is set, it isn\'t generated, so set one to cover those uploads too. SVGs are always skipped, as they can\'t be generated.', 'altification' ); ?> <?php esc_html_e( 'Note: if an image is later used on a different page from the one it was uploaded to, the Site Scan can flag it — as Improvable or as an SEO gap — so you can regenerate it with that page\'s keyword.', 'altification' ); ?></p>
    389389                    </td>
    390390                </tr>
  • altification/trunk/readme.txt

    r3826858 r3826946  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 1.0.12
     7Stable tag: 1.0.13
    88License: GPL-2.0-or-later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    110110
    111111== Changelog ==
     112
     113= 1.0.13 =
     114* Fixed: the Media Library banner's missing captions and missing descriptions counts included decorative images and SVGs, so they didn't match the Site Scan. They now come from the Site Scan, and their links list exactly those images. "Missing any field" now counts captions and descriptions only when those fields are turned on
     115* Fixed: the Site Scan's caption and description counts and tabs included decorative images and SVGs when the page first loaded, then changed after your first action. SVGs no longer appear on the No alt tab either, which never counted them
     116* Fixed: the editor sidebar counted decorative images as missing alt text, captions and descriptions, so a page with one never showed "All complete", and "Generate missing" generated for them. Decorative images and SVGs are now skipped, as they are in the Page Scanner and Site Scan
     117* Corrected the help text for generating alt text on upload: images uploaded straight to the media library are generated only when a Default keyword is set, and SVGs are skipped
     118* Each generation request now tells altification.ai which fields it is for, so it is charged one credit per field as listed
    112119
    113120= 1.0.12 =
    … …  
    212219== Upgrade Notice ==
    213220
     221= 1.0.13 =
     222Caption and description counts now match the Site Scan everywhere, and decorative images are no longer counted as missing anything, or generated for, in the editor sidebar.
     223
    214224= 1.0.12 =
    215225Images used on more than one page now show their SEO gaps on every screen, and the Media Library banner's missing alt text count now matches the Site Scan. Decorative images no longer count. Also prepares auto-generate on upload for WordPress 7.2.
Note: See TracChangeset for help on using the changeset viewer.