Plugin Directory

Changeset 3698101


Ignore:
Timestamp:
09/16/2026 07:38:56 AM (2 months ago)
Author:
plugupp
Message:

Release 2.7.3

Location:
dynamic-og-image-generator/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • dynamic-og-image-generator/trunk/admin/class-gutenberg.php

    r3678151 r3698101  
    9191
    9292                        // 2.7.2: WooCommerce's own record of which attachment is the
    93                         // store placeholder. The sidebar's "does this post have a real
    94                         // Featured Image?" check must agree with
    95                         // DOIG_Source_Resolver::has_real_featured_image() or the
     93                        // store placeholder. The sidebar's "is this Featured Image
     94                        // usable as a share image?" check must agree with
     95                        // DOIG_Source_Resolver::has_social_featured_image() or the
    9696                        // Regenerate Now gate and the preview diverge from what the
    9797                        // front end emits. 0 when the option is absent (no WooCommerce),
    9898                        // which can never match a real attachment ID.
    9999                        'wcPlaceholderId' => (int) get_option( 'woocommerce_placeholder_image' ),
     100
     101                        // 2.7.3: the same social-safe MIME list the resolver gates on,
     102                        // filter included, so the sidebar and the front end cannot
     103                        // disagree about whether an SVG (or any other unrenderable
     104                        // format) will be used. An ARRAY survives wp_localize_script
     105                        // intact - only scalars are cast to strings - so the JS can
     106                        // compare mime_type from select('core').getMedia() against it
     107                        // directly.
     108                        'socialMimeTypes' => array_values( DOIG_Source_Resolver::social_image_mime_types() ),
    100109                );
    101110
  • dynamic-og-image-generator/trunk/assets/js/gutenberg.js

    r3678151 r3698101  
    188188
    189189                                // 2.7.2: both featured branches gate on
    190                                 // hasRealFeaturedImage so the preview mirrors
    191                                 // featured_payload(), which now returns null for a
    192                                 // sentinel / placeholder / dangling thumbnail. Without
    193                                 // this the sidebar would preview the WooCommerce
    194                                 // placeholder while the front end emits a screenshot.
     190                                // hasSocialFeaturedImage so the preview mirrors
     191                                // featured_payload(), which returns null for a sentinel /
     192                                // placeholder / dangling thumbnail and (2.7.3) for a
     193                                // format social platforms do not render. Without this the
     194                                // sidebar would preview the WooCommerce placeholder, or an
     195                                // SVG, while the front end emits a screenshot.
    195196                                case SOURCE_FEATURED: {
    196                                         const fiUrl = hasRealFeaturedImage ? attachmentPreviewUrl( featuredImage ) : null;
     197                                        const fiUrl = hasSocialFeaturedImage ? attachmentPreviewUrl( featuredImage ) : null;
    197198                                        return fiUrl ? { url: fiUrl, isScreenshot: false } : null;
    198199                                }
    199200
    200201                                case SOURCE_FEATURED_WITH_FALLBACK: {
    201                                         const fiUrl = hasRealFeaturedImage ? attachmentPreviewUrl( featuredImage ) : null;
     202                                        const fiUrl = hasSocialFeaturedImage ? attachmentPreviewUrl( featuredImage ) : null;
    202203                                        if ( fiUrl ) {
    203204                                                return { url: fiUrl, isScreenshot: false };
    … …  
    208209                                }
    209210
     211                                // 2.7.3: the Custom Image gets the same format gate the
     212                                // Featured path gets, mirroring attachment_payload() -
     213                                // an SVG picked here emits nothing on the front end, so
     214                                // it must not preview as though it will.
    210215                                case SOURCE_CUSTOM: {
    211                                         const customUrl = attachmentPreviewUrl( customImage );
     216                                        const customUrl = isSocialSafeMedia( customImage ) ? attachmentPreviewUrl( customImage ) : null;
    212217                                        return customUrl ? { url: customUrl, isScreenshot: false } : null;
    213218                                }
    … …  
    319324                // would otherwise never match.
    320325                const wcPlaceholderId = parseInt( window.doigSidebar?.wcPlaceholderId ?? 0, 10 ) || 0;
     326                // 2.7.3: the social-safe MIME list, localised from
     327                // DOIG_Source_Resolver::social_image_mime_types() so the sidebar
     328                // and the front end read the same list, filter included. Arrays
     329                // survive wp_localize_script unchanged (only scalars are cast to
     330                // strings), so no parsing is needed here - but the fallback
     331                // matters, because a cached script against an older PHP build
     332                // would otherwise gate every image out.
     333                const socialMimeTypes = Array.isArray( window.doigSidebar?.socialMimeTypes )
     334                        ? window.doigSidebar.socialMimeTypes
     335                        : [ 'image/jpeg', 'image/png', 'image/gif', 'image/webp' ];
     336
     337                /**
     338                 * Is this attachment record one social platforms will render?
     339                 * Mirrors DOIG_Source_Resolver::is_social_image_mime_type().
     340                 * An attachment still loading (undefined) is not yet an answer,
     341                 * so it reports false and the UI settles once the record lands.
     342                 *
     343                 * @param {Object|null|undefined} media wp.data attachment record
     344                 * @return {boolean}
     345                 */
     346                function isSocialSafeMedia( media ) {
     347                        return !! media && socialMimeTypes.indexOf( media.mime_type ) !== -1;
     348                }
    321349
    322350                // Resolved source mode for this post - JS-side mirror of
    … …  
    345373                // screenshot anyway - matches the M4.2 server-side gate in
    346374                // DOIG_Cron::schedule() and DOIG_Post_Meta::rest_regenerate().
    347                 // JS mirror of DOIG_Source_Resolver::has_real_featured_image()
    348                 // (2.7.2). A thumbnail can exist in meta and still have no image
    349                 // behind it - the -1 sentinel importers write, a dangling or
    350                 // non-image attachment, or the WooCommerce placeholder. The
    351                 // featuredImage record covers the first two: wp.data returns
    352                 // nothing for -1 or for a deleted attachment, so it stays null.
    353                 // The placeholder is a real attachment and loads fine, so it needs
    354                 // the explicit ID comparison against the localised option value.
    355                 // wcPlaceholderId is 0 when no placeholder is recorded, which can
    356                 // never match a real featured_media ID.
    357                 const hasRealFeaturedImage = ( !! featuredImage && featuredMediaId !== wcPlaceholderId );
     375                // JS mirror of DOIG_Source_Resolver::has_social_featured_image()
     376                // (2.7.2, renamed and widened 2.7.3). A thumbnail can exist in
     377                // meta and still put no image in front of a sharer - the -1
     378                // sentinel importers write, a dangling or non-image attachment,
     379                // the WooCommerce placeholder, or an image in a format social
     380                // platforms do not render. The featuredImage record covers the
     381                // first two: wp.data returns nothing for -1 or for a deleted
     382                // attachment, so it stays null. The placeholder is a real
     383                // attachment and loads fine, so it needs the explicit ID
     384                // comparison against the localised option value; wcPlaceholderId
     385                // is 0 when no placeholder is recorded, which can never match a
     386                // real featured_media ID. The format is settled by the record's
     387                // own mime_type against the localised list.
     388                const hasSocialFeaturedImage = (
     389                        isSocialSafeMedia( featuredImage )
     390                        && featuredMediaId !== wcPlaceholderId
     391                );
    358392                const needsScreenshot = (
    359393                        resolvedMode === SOURCE_SCREENSHOT
    360                         || ( resolvedMode === SOURCE_FEATURED_WITH_FALLBACK && ! hasRealFeaturedImage )
     394                        || ( resolvedMode === SOURCE_FEATURED_WITH_FALLBACK && ! hasSocialFeaturedImage )
    361395                );
     396
     397                // 2.7.3: the image the customer picked exists and loads, but its
     398                // format is one no social platform draws - the SVG case. Empty
     399                // string when there is nothing to warn about. Only the mode
     400                // actually in use is reported, so a stray SVG sitting in a
     401                // Featured Image slot on a Custom-mode post stays quiet.
     402                const blockedFormatMime = ( function () {
     403                        const usesFeatured = (
     404                                resolvedMode === SOURCE_FEATURED
     405                                || resolvedMode === SOURCE_FEATURED_WITH_FALLBACK
     406                        );
     407                        if (
     408                                usesFeatured
     409                                && featuredImage
     410                                && featuredMediaId !== wcPlaceholderId
     411                                && ! isSocialSafeMedia( featuredImage )
     412                        ) {
     413                                return featuredImage.mime_type || '';
     414                        }
     415                        if (
     416                                resolvedMode === SOURCE_CUSTOM
     417                                && customImage
     418                                && ! isSocialSafeMedia( customImage )
     419                        ) {
     420                                return customImage.mime_type || '';
     421                        }
     422                        return '';
     423                } )();
     424
     425                // "image/svg+xml" reads as "SVG" to a writer. Generic on purpose:
     426                // whatever format the gate refuses is named back to the customer
     427                // without a hardcoded list of names to keep in sync.
     428                const blockedFormatLabel = blockedFormatMime
     429                        ? blockedFormatMime.split( '/' ).pop().replace( '+xml', '' ).toUpperCase()
     430                        : '';
    362431                // Compute the preview image AFTER resolvedMode, cachedUrl and
    363                 // hasRealFeaturedImage are available - getPreviewImage() references
     432                // hasSocialFeaturedImage are available - getPreviewImage() references
    364433                // all three. Function declaration is hoisted; the invocation isn't,
    365434                // so calling it earlier would hit the temporal dead zone.
    … …  
    916985                                ),
    917986
     987                                // Unsupported-format warning (2.7.3). The picked image
     988                                // exists and loads, so nothing on this screen would
     989                                // otherwise tell the customer why their share preview is
     990                                // blank: the gate in DOIG_Source_Resolver refuses the
     991                                // attachment, and under Featured-with-fallback the
     992                                // screenshot quietly takes over instead. Named as a
     993                                // warning rather than an error because the plugin still
     994                                // produces a correct share image in the FwF case - the
     995                                // thing the customer chose is simply not the thing that
     996                                // ships.
     997                                blockedFormatMime && wp.element.createElement( Notice, {
     998                                        status:        'warning',
     999                                        isDismissible: false,
     1000                                        className:     'doig-unsupported-format-warning',
     1001                                },
     1002                                        sprintf(
     1003                                                /* translators: %s: uppercase image format name taken from the attachment's MIME type, for example SVG */
     1004                                                __( 'This %s image is in a format social platforms cannot display, so it will not be used as the share image. Under "Featured image (with screenshot when missing)" the screenshot is used instead; otherwise choose a JPEG, PNG, GIF or WebP.', 'dynamic-og-image-generator' ),
     1005                                                blockedFormatLabel
     1006                                        )
     1007                                ),
     1008
    9181009                                // Small-image warning (Q3 lock 2026-06-22). Soft notice
    9191010                                // surfaced when the resolved image is below the 200x200
    … …  
    10051096                                                if ( resolvedMode === SOURCE_OFF ) {
    10061097                                                        helpText = __( 'DOIG is Off for this post. Set the Image Source above to Auto-screenshot to enable regeneration.', 'dynamic-og-image-generator' );
    1007                                                 } else if ( resolvedMode === SOURCE_FEATURED_WITH_FALLBACK && hasRealFeaturedImage ) {
     1098                                                } else if ( resolvedMode === SOURCE_FEATURED_WITH_FALLBACK && hasSocialFeaturedImage ) {
    10081099                                                        helpText = __( 'This post has a Featured Image, so the screenshot fallback is not in use. Regenerate becomes available if you remove the Featured Image.', 'dynamic-og-image-generator' );
    10091100                                                } else {
  • dynamic-og-image-generator/trunk/dynamic-og-image-generator.php

    r3678151 r3698101  
    55 * Plugin URI:        https://wordpress.org/plugins/dynamic-og-image-generator/
    66 * Description:       Automatically generates real screenshot-based Open Graph images for your pages and posts. No templates — actual screenshots of your site, cached locally and refreshed on a configurable schedule.
    7  * Version:           2.7.2
     7 * Version:           2.7.3
    88 * Requires at least: 6.0
    99 * Requires PHP:      7.4
    … …  
    116116    }
    117117    // Plugin constants
    118     define( 'DOIG_VERSION', '2.7.2' );
     118    define( 'DOIG_VERSION', '2.7.3' );
    119119    define( 'DOIG_PLUGIN_FILE', __FILE__ );
    120120    define( 'DOIG_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  • dynamic-og-image-generator/trunk/includes/class-og-injector.php

    r3620214 r3698101  
    1212 * Two operating modes:
    1313 *
    14  * 1. No supported SEO plugin active — outputs the full social meta block
     14 * 1. No supported SEO plugin active - outputs the full social meta block
    1515 *    (og:image, og:image:width, og:image:height, og:image:type, twitter:image,
    1616 *    twitter:card).
    1717 *
    18  * 2. Supported SEO plugin active (Yoast, Rank Math, AIOSEO) — the SEO compat
    19  *    class already overrides og:image and twitter:image inside the SEO plugin's
    20  *    own output. This method only emits the supplementary tags that SEO plugins
    21  *    cannot reliably resolve for a cached screenshot file: og:image:width,
    22  *    og:image:height, og:image:type, and twitter:card. og:image and twitter:image
    23  *    are intentionally omitted to avoid duplicate tags.
     18 * 2. Supported SEO plugin active (Yoast, Rank Math, AIOSEO) on a page that
     19 *    plugin covers - DOIG prints NOTHING here. Every tag it would print
     20 *    goes through the SEO plugin's own filters in DOIG_SEO_Compat instead,
     21 *    so there is exactly one emitter per page.
     22 *
     23 * Mode 2 changed in 2.7.3. Until then DOIG printed og:image:width /
     24 * og:image:height / og:image:type / twitter:card of its own alongside the
     25 * SEO plugin's output, on the reasoning that SEO plugins drop those tags
     26 * inconsistently. Two problems, both recorded rather than theorised:
     27 *
     28 *   - Orphaned sub-tags. When the SEO plugin refuses the image DOIG handed
     29 *     it - Yoast dropping an SVG that fails its own whitelist, the
     30 *     2026-09-15 macupp.com case - no og:image ships, but DOIG had already
     31 *     printed the width / height / type for it. Dimensions with no image
     32 *     are not valid Open Graph; an og:image with no dimensions is.
     33 *   - Duplicates. All three plugins in fact emit these tags themselves
     34 *     from the values DOIG's compat filters feed them (Yoast via
     35 *     wpseo_opengraph_image_width/_height/_type; Rank Math via the
     36 *     image_array enrichment its image_meta() loop reads; AIOSEO via the
     37 *     aioseo_facebook_tags array), and all three emit twitter:card of
     38 *     their own. The earlier note calling the duplicate pairs pre-existing
     39 *     design was wrong: they are duplicates of tags the compat layer
     40 *     already supplies.
     41 *
     42 * The 2.7.3 rule is therefore one emitter per page. Where a plugin offers
     43 * no filter for a tag, DOIG omits that tag rather than printing a second
     44 * one.
    2445 */
    2546class DOIG_OG_Injector {
    … …  
    213234         * The shared emission block for posts and surfaces.
    214235         *
     236         * One emitter per page (2.7.3). When a supported SEO plugin covers
     237         * the current page DOIG prints nothing at all here - not the image,
     238         * not its dimensions, not twitter:card - because DOIG_SEO_Compat has
     239         * already pushed the same payload through that plugin's own filters
     240         * and the plugin prints the whole set itself. Printing a second copy
     241         * produced duplicate og:image:width / height / type pairs, and left
     242         * those tags stranded with no og:image whenever the SEO plugin
     243         * refused the image DOIG offered it.
     244         *
     245         * The comment markers wrap only what DOIG actually prints. When it
     246         * prints nothing, it prints nothing - no empty marker block in the
     247         * source of every page on the site.
     248         *
    215249         * @param array $payload {url, width, height, type} from the resolver.
    216250         */
    217251        private static function emit_tags( $payload ) {
     252                // Per-PAGE, not per-install: AIOSEO handles singular pages but
     253                // not taxonomy/author pages, where DOIG is the only emitter and
     254                // the full block below is correct (see
     255                // seo_plugin_handles_current_page).
     256                if ( self::seo_plugin_handles_current_page() ) {
     257                        return;
     258                }
     259
    218260                echo "\n<!-- PlugUpp Dynamic OG Image Generator -->\n";
    219 
    220                 // og:image + twitter:image only when no SEO plugin handles this
    221                 // page. When one does, DOIG_SEO_Compat hooks the plugin's own
    222                 // image filters with the same payload URL, so emitting our own
    223                 // og:image here would produce a duplicate. Note this is
    224                 // per-PAGE, not per-install: AIOSEO handles singular pages but
    225                 // not taxonomy/author pages (see seo_plugin_handles_current_page).
    226                 if ( ! self::seo_plugin_handles_current_page() ) {
    227                         echo '<meta property="og:image" content="' . esc_url( $payload['url'] ) . '" />' . "\n";
    228                         echo '<meta name="twitter:image" content="' . esc_url( $payload['url'] ) . '" />' . "\n";
    229                 }
    230 
    231                 // Supplementary metadata. The og:image:* tags are inconsistently
    232                 // emitted by SEO plugins (Yoast emits them only when its
    233                 // internal cache has the attachment's metadata; Rank Math emits
    234                 // via its image_meta() loop reading from an attachment array
    235                 // that DOIG's URL-rewrite resets to {url: ...} - the 2.3.0
    236                 // image_array filter fix mitigates but doesn't fully eliminate
    237                 // the gap; AIOSEO is more consistent post-2.3.0). Always emit
    238                 // from DOIG so the metadata IS present even when the SEO
    239                 // plugin's own emission drops them. twitter:card: same story.
     261                echo '<meta property="og:image" content="' . esc_url( $payload['url'] ) . '" />' . "\n";
     262                echo '<meta name="twitter:image" content="' . esc_url( $payload['url'] ) . '" />' . "\n";
    240263                echo '<meta property="og:image:width" content="' . esc_attr( $payload['width'] ) . '" />' . "\n";
    241264                echo '<meta property="og:image:height" content="' . esc_attr( $payload['height'] ) . '" />' . "\n";
    242265                echo '<meta property="og:image:type" content="' . esc_attr( $payload['type'] ) . '" />' . "\n";
    243266                echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
    244 
    245267                echo "<!-- /PlugUpp Dynamic OG Image Generator -->\n";
    246268        }
  • dynamic-og-image-generator/trunk/includes/class-seo-compat.php

    r3620214 r3698101  
    1919 *
    2020 * Supported: Yoast SEO, Rank Math, All in One SEO (AIOSEO).
     21 *
     22 * 2.7.3 - ONE EMITTER PER PAGE. On a page a supported SEO plugin covers,
     23 * this class is the only route DOIG's image takes; DOIG_OG_Injector prints
     24 * nothing of its own there. That makes the filter coverage below the whole
     25 * story, so it was re-read from the current WP.org sources on 2026-09-15
     26 * rather than assumed:
     27 *
     28 * - Yoast SEO 28.5. og:image:width / og:image:height / og:image:type each
     29 *   have a dedicated filter, all three already wired below
     30 *   (src/presenters/open-graph/image-presenter.php lines 114, 129, 144).
     31 * - Rank Math 1.0.278. No per-tag dimension filters exist. Its emission
     32 *   loop image_meta() reads width / height / alt / type straight off the
     33 *   image array and tags each as og:image:<key>
     34 *   (includes/opengraph/class-image.php lines 148-155), and that array
     35 *   passes through rank_math/opengraph/{network}/image_array (line 235) -
     36 *   the filter already wired below. So all three tags are covered.
     37 * - AIOSEO 5.0.1.1. getFacebookMeta() assembles an array and runs it
     38 *   through aioseo_facebook_tags (app/Common/Social/Output.php line 103);
     39 *   the view then renders EVERY key/value pair it finds
     40 *   (app/Common/Views/main/social.php lines 17-27), so the og:image:type
     41 *   key DOIG adds emits even though AIOSEO never sets one itself. AIOSEO
     42 *   sets og:image:width / og:image:height of its own (lines 74-75), which
     43 *   the filter below overwrites with the resolver's values.
     44 *
     45 * twitter:card is deliberately NOT wired. All three plugins emit it
     46 * themselves from the customer's own configured card type - Yoast
     47 * src/presenters/twitter/card-presenter.php line 18 (filter
     48 * wpseo_twitter_card_type, line 32), Rank Math
     49 * includes/opengraph/class-twitter.php line 117 (filter
     50 * rank_math/opengraph/twitter/card_type, line 242), AIOSEO
     51 * app/Common/Social/Output.php line 119. DOIG used to print a second
     52 * summary_large_image tag beside theirs; the customer's setting is the
     53 * one that should win, and two conflicting twitter:card tags on a page
     54 * is not a better outcome than one.
    2155 */
    2256class DOIG_SEO_Compat {
  • dynamic-og-image-generator/trunk/includes/class-source-resolver.php

    r3678151 r3698101  
    249249                        // FwF only needs a screenshot when no Featured Image is set
    250250                        // on the post; with an FI, the FI emits and no capture is
    251                         // needed. has_real_featured_image() rather than
    252                         // has_post_thumbnail() - see its docblock for the three
    253                         // thumbnails that exist in meta but can never emit.
    254                         $needed = ! self::has_real_featured_image( $post_id );
     251                        // needed. has_social_featured_image() rather than
     252                        // has_post_thumbnail() - see its docblock for the thumbnails
     253                        // that exist in meta but can never emit, the unrenderable
     254                        // formats included.
     255                        $needed = ! self::has_social_featured_image( $post_id );
    255256                } else {
    256257                        $needed = false;
    … …  
    291292
    292293        /**
    293          * Does this post carry a Featured Image DOIG can actually emit?
    294          *
    295          * `has_post_thumbnail()` answers a different question: "is the
    296          * `_thumbnail_id` meta non-empty?". Three thumbnails pass that test
    297          * and still have no image behind them, all seen on real sites:
     294         * The image formats DOIG will hand to a social platform.
     295         *
     296         * PROVENANCE. This is the intersection of what every major platform
     297         * renders and what both validating SEO plugins accept, read from the
     298         * current WP.org source on 2026-09-15:
     299         *
     300         * - Yoast SEO 28.5 - `src/helpers/image-helper.php`,
     301         *   `$valid_image_types = [ image/jpeg, image/gif, image/png,
     302         *   image/webp ]`, enforced by `is_valid_attachment()`. An
     303         *   attachment outside that list is dropped silently: no og:image
     304         *   at all.
     305         * - Rank Math 1.0.278 - `includes/opengraph/class-image.php`,
     306         *   `is_valid_image_url()` allows jpeg/jpg/gif/png/webp/avif by file
     307         *   extension. One format wider than Yoast (avif).
     308         * - AIOSEO 5.0.1.1 - validates nothing. It will happily print an
     309         *   og:image pointing at an SVG.
     310         *
     311         * DOIG keeps its own conservative list rather than trusting whatever
     312         * SEO plugin happens to be installed, because "the plugin accepted
     313         * it" is not the same claim as "the platform will render it", and
     314         * one of the three plugins accepts everything.
     315         *
     316         * The safety is deliberately asymmetric. A format wrongly REJECTED
     317         * here falls back to the screenshot under Featured-with-fallback, or
     318         * emits nothing under Featured / Custom, which is what would have
     319         * happened anyway on a platform that cannot draw it: harmless. A
     320         * format wrongly ACCEPTED produces a share with NO preview image -
     321         * the 2.7.3 bug. So additions wait for evidence: the sentinel script
     322         * `scripts/check-social-image-types.sh` flags the day Yoast or Rank
     323         * Math changes its list, and platform support is checked before a
     324         * format is added. Never add a format on a hunch.
     325         *
     326         * AVIF is the one known, deliberate divergence: Rank Math accepts it,
     327         * Yoast does not, so a site running Yoast would get no og:image from
     328         * an AVIF attachment. It stays out until Yoast accepts it.
     329         *
     330         * Site owners who know their audience can widen or narrow the list
     331         * through the `doig_social_image_mime_types` filter.
     332         *
     333         * @since 2.7.3
     334         *
     335         * @return string[] MIME types DOIG will emit as a share image.
     336         */
     337        public static function social_image_mime_types() {
     338                /**
     339                 * Filters the image MIME types DOIG will emit as a share image.
     340                 *
     341                 * An attachment whose MIME type is not on this list is treated
     342                 * as if it were not there: Featured-with-fallback falls through
     343                 * to the screenshot, Featured and Custom emit nothing.
     344                 *
     345                 * @since 2.7.3
     346                 *
     347                 * @param string[] $mime_types Social-safe image MIME types.
     348                 */
     349                return (array) apply_filters(
     350                        'doig_social_image_mime_types',
     351                        array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp' )
     352                );
     353        }
     354
     355        /**
     356         * Is this MIME type one DOIG will emit as a share image?
     357         *
     358         * @since 2.7.3
     359         *
     360         * @param string $mime_type
     361         * @return bool
     362         */
     363        public static function is_social_image_mime_type( $mime_type ) {
     364                return in_array( (string) $mime_type, self::social_image_mime_types(), true );
     365        }
     366
     367        /**
     368         * Does this post carry a Featured Image usable as a SOCIAL SHARE
     369         * image?
     370         *
     371         * Deliberately not "does this post have a featured image?". A post
     372         * can carry a perfectly real, correctly rendered Featured Image that
     373         * no social platform will ever draw. That is a different question and
     374         * this method answers the one DOIG actually needs.
     375         *
     376         * `has_post_thumbnail()` answers a third question again: "is the
     377         * `_thumbnail_id` meta non-empty?". Four thumbnails pass that test
     378         * and still put no image in front of a sharer, all seen on real
     379         * sites:
    298380         *
    299381         * 1. The -1 sentinel. Importers and catalogue plugins write
    … …  
    317399         *    so the check is a no-op there. No WooCommerce class or function
    318400         *    is referenced.
     401         * 4. An image in a format social platforms do not render - an SVG
     402         *    uploaded through Safe SVG is the case that produced this
     403         *    method's rename. `wp_attachment_is_image()` returns TRUE for an
     404         *    SVG, so every earlier gate accepted it; Yoast then dropped the
     405         *    image/svg+xml URL from its own whitelist and the page shipped
     406         *    with og:image:width / height / type and no og:image at all.
     407         *    Source-verified on macupp.com, 2026-09-15.
     408         *
     409         * Gate (d) is the Yoast OVERLAY. DOIG's own list is the baseline;
     410         * Yoast can only make the answer STRICTER, never looser, so a
     411         * plugin that validates nothing (AIOSEO) cannot widen what DOIG
     412         * emits. Asking Yoast at all is worth it because Yoast is the one
     413         * that will silently drop the image downstream: if it says no, DOIG
     414         * emitting anyway just recreates the bug, whereas answering false
     415         * here sends Featured-with-fallback to the screenshot, which is the
     416         * correct outcome. The call is fully guarded - a Yoast refactor that
     417         * moves or renames the helper must never fatal DOIG, so an
     418         * unreachable helper simply leaves the baseline answer standing.
    319419         *
    320420         * Every "does this post have a featured image?" decision in the
    321421         * plugin - the FwF capture gate and the featured emission branch -
    322          * routes through here, so a sentinel, placeholder or dangling
    323          * thumbnail falls exactly where a post with no Featured Image at all
    324          * would fall.
    325          *
    326          * @since 2.7.2
     422         * routes through here, so a sentinel, placeholder, dangling or
     423         * unrenderable thumbnail falls exactly where a post with no Featured
     424         * Image at all would fall.
     425         *
     426         * @since 2.7.2 (as has_real_featured_image)
     427         * @since 2.7.3 Renamed; MIME gate and Yoast overlay added.
    327428         *
    328429         * @param int $post_id
    329430         * @return bool
    330431         */
    331         public static function has_real_featured_image( $post_id ) {
     432        public static function has_social_featured_image( $post_id ) {
    332433                $attachment_id = (int) get_post_thumbnail_id( $post_id );
    333434
    … …  
    344445                }
    345446
    346                 return true;
     447                if ( ! self::is_social_image_mime_type( get_post_mime_type( $attachment_id ) ) ) {
     448                        return false;
     449                }
     450
     451                return self::yoast_accepts_attachment( $attachment_id );
     452        }
     453
     454        /**
     455         * Yoast's verdict on an attachment, as an overlay on DOIG's own
     456         * baseline. True when Yoast is not active, when its image helper is
     457         * unreachable, or when it accepts the attachment; false ONLY when a
     458         * reachable Yoast says no.
     459         *
     460         * Every hop is guarded. `YoastSEO()` is a plain function in Yoast's
     461         * `src/functions.php`, `helpers` is a magic-property surface and
     462         * `image` resolves through Yoast's DI container, so any of them can
     463         * be absent or throw in a build we have not seen. A failure to ASK
     464         * must never become a failure to emit, and must never be a fatal on
     465         * the customer's front end.
     466         *
     467         * @since 2.7.3
     468         *
     469         * @param int $attachment_id
     470         * @return bool
     471         */
     472        private static function yoast_accepts_attachment( $attachment_id ) {
     473                if ( ! function_exists( 'YoastSEO' ) ) {
     474                        return true;
     475                }
     476
     477                try {
     478                        $yoast = YoastSEO();
     479                        if ( ! is_object( $yoast ) || ! isset( $yoast->helpers ) || ! is_object( $yoast->helpers ) ) {
     480                                return true;
     481                        }
     482
     483                        $image_helper = $yoast->helpers->image;
     484                        if ( ! is_object( $image_helper ) || ! method_exists( $image_helper, 'is_valid_attachment' ) ) {
     485                                return true;
     486                        }
     487
     488                        return (bool) $image_helper->is_valid_attachment( $attachment_id );
     489                } catch ( \Throwable $e ) {
     490                        // PHP 7+ Throwable covers both Error and Exception, so a
     491                        // removed method or a container miss degrades to "Yoast did
     492                        // not object" rather than a white screen.
     493                        return true;
     494                }
    347495        }
    348496
    … …  
    455603         * attachment metadata. Null when no FI is set on the post.
    456604         *
    457          * Gated on has_real_featured_image() (2.7.2) rather than a bare
    458          * `> 0` check, so a -1 sentinel, a placeholder or a dangling
    459          * attachment produces the same null as an unset thumbnail: Featured
     605         * Gated on has_social_featured_image() (2.7.2, widened 2.7.3) rather
     606         * than a bare `> 0` check, so a -1 sentinel, a placeholder, a
     607         * dangling attachment or an image in a format social platforms do
     608         * not render produces the same null as an unset thumbnail: Featured
    460609         * mode emits nothing, Featured-with-fallback falls through to the
    461610         * screenshot.
    … …  
    465614         */
    466615        private static function featured_payload( $post_id ) {
    467                 if ( ! self::has_real_featured_image( $post_id ) ) {
     616                if ( ! self::has_social_featured_image( $post_id ) ) {
    468617                        return null;
    469618                }
    … …  
    494643         * hard-coded screenshot ones.
    495644         *
     645         * 2.7.3: also returns null when the attachment's format is not one
     646         * social platforms render. This is the single funnel every
     647         * attachment-backed mode passes through - Featured, per-post Custom
     648         * Image, and the site-wide surfaces' Custom Image - so the Custom
     649         * paths get the same gate the Featured path gets from
     650         * has_social_featured_image() without a second copy of the rule.
     651         * Emitting an unrenderable image is strictly worse than emitting
     652         * nothing: nothing lets the SEO plugin's own fallback chain run,
     653         * while an SVG og:image produces a share card with no picture at
     654         * all.
     655         *
    496656         * @param int $attachment_id
    497657         * @return array|null
    … …  
    503663                }
    504664
     665                $attachment_mime = (string) get_post_mime_type( $attachment_id );
     666                if ( '' !== $attachment_mime && ! self::is_social_image_mime_type( $attachment_mime ) ) {
     667                        DOIG_Logger::debug(
     668                                sprintf(
     669                                        'social_image_gate refused attachment %d (mime=%s) - not a format social platforms render',
     670                                        (int) $attachment_id,
     671                                        $attachment_mime
     672                                )
     673                        );
     674                        return null;
     675                }
     676
    505677                $meta   = wp_get_attachment_metadata( $attachment_id );
    506678                $width  = is_array( $meta ) && isset( $meta['width'] )  ? (int) $meta['width']  : 0;
    507679                $height = is_array( $meta ) && isset( $meta['height'] ) ? (int) $meta['height'] : 0;
    508680
    509                 $mime = (string) get_post_mime_type( $attachment_id );
     681                $mime = $attachment_mime;
    510682                if ( '' === $mime ) {
    511683                        // Last-resort default. wp_get_attachment_url() returned a URL
  • dynamic-og-image-generator/trunk/readme.txt

    r3678151 r3698101  
    44Requires at least: 6.0
    55Tested up to: 7.1
    6 Stable tag: 2.7.2
     6Stable tag: 2.7.3
    77Requires PHP: 7.4
    88License: GPLv2 or later
    … …  
    131131
    132132== Changelog ==
     133
     134= 2.7.3 =
     135* Fixed: a featured or custom image in a format social platforms cannot display (such as SVG) no longer results in a share preview with no image. Under "Featured image (with screenshot when missing)" the screenshot is now used instead, and the editor sidebar explains why.
     136* Fixed: when an SEO plugin is active, the plugin no longer prints image size tags of its own alongside the SEO plugin's, which could leave size tags without an image or print them twice.
    133137
    134138= 2.7.2 =
Note: See TracChangeset for help on using the changeset viewer.