Commit bb26471543 for wordpress.org
commit bb26471543b104e047f9f4b264810adc372cd6ce
Author: Sergey Biryukov <sergeybiryukov.ru@gmail.com>
Date: Thu Jul 25 22:38:16 2024 +0000
Comments: Only type cast a scalar `$comment_id` in `get_comment_author_link()`.
This aims to resolve a fatal error when the incoming `$comment_id` is an instance of `WP_Comment` (or any object) without a `comment_ID` property defined, or if it's empty:
{{{
Object of class WP_Comment could not be converted to string
}}}
This commit mirrors the changes previously made for a similar code fragment in `get_comment_author()`.
Includes:
* Unit tests to demonstrate the fatal error and validate the fix.
* Changing the default value for a non-existent comment ID in `get_comment_author()` from an empty string to zero as a numeric string, for consistency with `get_comment_ID()`.
Follow-up to [52818], [55289], [58335], [58755].
Props narenin, mukesh27, iflairwebtechnologies, umeshsinghin, SergeyBiryukov.
Fixes #61715.
Built from https://develop.svn.wordpress.org/trunk@58809
git-svn-id: http://core.svn.wordpress.org/trunk@58205 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php
index fed6568af3..ccc57ed8ee 100644
--- a/wp-includes/comment-template.php
+++ b/wp-includes/comment-template.php
@@ -29,7 +29,7 @@ function get_comment_author( $comment_id = 0 ) {
} elseif ( is_scalar( $comment_id ) ) {
$comment_id = (string) $comment_id;
} else {
- $comment_id = '';
+ $comment_id = '0';
}
if ( empty( $comment->comment_author ) ) {
@@ -233,7 +233,13 @@ function get_comment_author_email_link( $link_text = '', $before = '', $after =
function get_comment_author_link( $comment_id = 0 ) {
$comment = get_comment( $comment_id );
- $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_id;
+ if ( ! empty( $comment->comment_ID ) ) {
+ $comment_id = $comment->comment_ID;
+ } elseif ( is_scalar( $comment_id ) ) {
+ $comment_id = (string) $comment_id;
+ } else {
+ $comment_id = '0';
+ }
$comment_author_url = get_comment_author_url( $comment );
$comment_author = get_comment_author( $comment );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index dbea95c968..a62d0ed8af 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.7-alpha-58807';
+$wp_version = '6.7-alpha-58809';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.