Commit c2244c106a for wordpress.org
commit c2244c106a2c38a6ccb01423c38c56d938eeb3eb
Author: westonruter <westonruter@git.wordpress.org>
Date: Mon Nov 30 20:20:56 2026 +0000
Permalinks: Fix shortlink warning when the post is missing.
In the `query` context, `wp_get_shortlink()` took the post ID from `get_queried_object_id()` and then looked the post up with `get_post()`. When the queried object ID was non-zero but did not resolve to a post, the shortlink logic still ran and read `post_type` on `null`, emitting a warning from `wp_shortlink_header()` and `wp_shortlink_wp_head()`. The queried object is now used directly, and only when it is a `WP_Post`, which matches how the `post` context already only sets the ID from a resolved post. This also resolves two PHPStan errors for property access on a possibly-null post.
Developed in https://github.com/WordPress/wordpress-develop/pull/14543.
Follow-up to r25030, r34445.
Props bor0, westonruter, laweens, softglaze.
See #51376.
Fixes #66348.
Built from https://develop.svn.wordpress.org/trunk@65831
git-svn-id: http://core.svn.wordpress.org/trunk@64860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index aabf7bc69d..a5437b2575 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -4205,8 +4205,11 @@ function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) {
$post_id = 0;
if ( 'query' === $context && is_singular() ) {
- $post_id = get_queried_object_id();
- $post = get_post( $post_id );
+ $queried_object = get_queried_object();
+ if ( $queried_object instanceof WP_Post ) {
+ $post = $queried_object;
+ $post_id = $queried_object->ID;
+ }
} elseif ( 'post' === $context ) {
$post = get_post( $id );
if ( ! empty( $post->ID ) ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index a7af7cd497..66a4e50c46 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.3-alpha-65830';
+$wp_version = '7.3-alpha-65831';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.