Make WordPress Core


Ignore:
Timestamp:
03/30/2025 11:32:38 PM (19 months ago)
Author:
audrasjb
Message:

Canonical: Use get_post_status() to determine whether the post has a publish post status in wp_get_canonical_url().

This changeset fixes an issue where wp_get_canonical_url() always returned false for attachments. Attachments have a inherit post status rather than publish. The wp_get_canonical_url() function was directly checking $post->post_status === 'publish', causing it to always return false for attachments. Using get_post_status() fixes the issue as if the post is an attachment, then the parent post status will be given instead.

Follow-up to [37685].

Props othernoel, ankitkumarshah, SirLouen,
Fixes #63041.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r59865 r60108  
    40644064        }
    40654065
    4066         if ( 'publish' !== $post->post_status ) {
     4066        if ( 'publish' !== get_post_status( $post ) ) {
    40674067                return false;
    40684068        }
Note: See TracChangeset for help on using the changeset viewer.