Tonya Mork
3442f776f3
Comments: Fix PHP Notice "trying to get property of non-object" in comments_open() and pings_open().
...
The post for the comments or pings is retrieved by `get_post()`. If the post exists, `get_post()` returns an instance of `WP_Post`; else, it returns `null`.
In both `comments_open()` and `pings_open()`, the returned value from `get_post()` is used without checking if the object returned, if the post exists. When the post does not exist, the following notices occur:
{{{
PHP Notice: Trying to get property 'comment_status' of non-object in .../src/wp-includes/comment-template.php on line 1244
}}}
and
{{{
PHP Notice: Trying to get property 'pings_open' of non-object in ../src/wp-includes/comment-template.php on line 1274
}}}
This commit fixes these notices by checking if the post has a non-falsey value before using it as an object to set the `$open` state. As the return from `get_post()` will only be an object or `null`, the truthy check is appropriate and slightly more performant.
Tests added to validate the fix.
Follow-up to [1964], [40666].
Props dd32, audrasjb, costdev, hellofromTonya, sergeybiryukov.
Fixes #54159 .
git-svn-id: https://develop.svn.wordpress.org/trunk@52223 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-19 20:22:43 +00:00
..
2021-11-15 12:47:22 +00:00
2021-11-09 02:15:23 +00:00
2021-11-15 12:47:22 +00:00
2021-11-15 12:47:22 +00:00
2021-10-03 17:50:01 +00:00
2021-11-18 16:46:56 +00:00
2021-11-19 14:42:04 +00:00
2020-07-17 17:09:37 +00:00
2021-10-10 01:15:16 +00:00
2021-11-16 00:02:29 +00:00
2021-05-24 02:17:36 +00:00
2021-08-10 13:44:34 +00:00
2021-08-18 14:07:17 +00:00
2021-10-18 17:51:17 +00:00
2021-05-11 19:40:41 +00:00
2021-11-18 13:55:36 +00:00
2020-10-16 17:18:11 +00:00
2021-11-18 13:48:43 +00:00
2021-08-10 13:03:41 +00:00
2020-10-18 17:31:37 +00:00
2021-11-18 13:48:43 +00:00
2021-11-07 23:03:47 +00:00
2021-11-15 03:42:08 +00:00
2020-10-17 15:43:39 +00:00
2021-06-21 06:05:30 +00:00
2021-11-09 12:58:08 +00:00
2021-08-11 09:06:31 +00:00
2021-07-02 14:34:24 +00:00
2021-11-10 14:16:03 +00:00
2021-08-26 12:57:08 +00:00
2021-11-09 02:15:23 +00:00
2021-11-08 23:05:50 +00:00
2021-05-20 00:03:04 +00:00
2020-06-10 09:55:56 +00:00
2020-11-24 21:25:46 +00:00
2021-06-08 23:31:46 +00:00
2021-11-15 01:08:35 +00:00
2021-11-18 13:48:43 +00:00
2020-07-23 21:53:43 +00:00
2020-02-06 06:31:22 +00:00
2021-11-07 01:35:52 +00:00
2020-02-06 06:31:22 +00:00
2020-11-12 11:15:49 +00:00
2020-02-06 06:31:22 +00:00
2021-05-25 18:46:39 +00:00
2020-07-21 12:56:40 +00:00
2020-05-01 20:10:58 +00:00
2021-06-06 14:04:52 +00:00
2020-10-16 17:18:11 +00:00
2021-01-26 13:44:42 +00:00
2020-05-01 19:05:04 +00:00
2021-09-09 12:38:36 +00:00
2021-11-16 14:55:04 +00:00
2021-09-09 13:02:46 +00:00
2021-09-09 13:02:46 +00:00
2021-09-09 12:38:36 +00:00
2021-09-09 13:02:46 +00:00
2021-11-15 03:42:08 +00:00
2020-06-28 14:00:26 +00:00
2021-10-30 20:25:19 +00:00
2021-05-24 07:37:22 +00:00
2021-08-03 11:11:45 +00:00
2021-02-02 05:14:46 +00:00
2021-11-19 19:04:01 +00:00
2021-11-19 19:04:01 +00:00
2021-06-15 15:21:50 +00:00
2021-01-28 02:01:50 +00:00
2021-11-08 23:09:53 +00:00
2021-06-15 15:21:50 +00:00
2021-07-28 10:05:01 +00:00
2021-10-06 18:47:09 +00:00
2021-09-13 18:53:57 +00:00
2021-01-03 22:02:13 +00:00
2021-10-22 16:08:10 +00:00
2021-11-18 13:48:43 +00:00
2021-10-04 20:42:54 +00:00
2021-07-30 19:34:39 +00:00
2021-07-30 19:34:39 +00:00
2021-10-18 17:51:17 +00:00
2021-09-09 21:39:39 +00:00
2021-10-14 18:03:07 +00:00
2020-07-23 00:46:56 +00:00
2021-09-08 23:28:43 +00:00
2021-06-17 14:35:59 +00:00
2020-10-09 22:28:54 +00:00
2021-06-05 15:45:10 +00:00
2020-11-12 14:34:33 +00:00
2021-08-03 11:00:50 +00:00
2021-09-22 21:21:40 +00:00
2021-11-07 01:35:52 +00:00
2021-11-12 23:50:07 +00:00
2021-10-01 14:59:31 +00:00
2021-11-19 14:42:04 +00:00
2021-07-01 21:11:48 +00:00
2021-11-07 01:35:52 +00:00
2021-11-07 01:35:52 +00:00
2021-09-09 20:38:20 +00:00
2021-09-09 20:38:20 +00:00
2021-11-08 10:43:52 +00:00
2021-11-09 01:09:11 +00:00
2020-11-12 14:41:19 +00:00
2020-09-18 10:35:41 +00:00
2020-10-08 21:13:57 +00:00
2021-09-10 15:59:17 +00:00
2021-01-03 21:55:04 +00:00
2021-07-30 19:34:39 +00:00
2021-01-03 22:02:13 +00:00
2020-11-24 21:20:36 +00:00
2021-06-15 10:23:57 +00:00
2021-10-15 05:03:17 +00:00
2020-06-20 11:16:12 +00:00
2021-11-19 14:42:04 +00:00
2020-11-09 15:13:56 +00:00
2021-10-04 20:42:54 +00:00
2020-08-11 00:32:22 +00:00
2021-04-04 18:28:59 +00:00
2020-06-19 22:53:54 +00:00
2021-02-22 19:16:07 +00:00
2020-08-11 00:32:22 +00:00
2021-07-30 19:34:39 +00:00
2020-07-23 00:50:57 +00:00
2021-07-30 19:34:39 +00:00
2020-08-12 15:03:50 +00:00
2021-05-15 17:36:49 +00:00
2020-10-10 20:00:30 +00:00
2021-07-30 19:34:39 +00:00
2021-02-20 17:08:24 +00:00
2020-07-14 12:08:28 +00:00
2021-11-01 14:29:42 +00:00
2021-07-30 19:34:39 +00:00
2020-12-10 23:51:52 +00:00
2021-01-27 21:52:10 +00:00
2021-11-16 14:56:42 +00:00
2021-11-08 19:18:39 +00:00
2021-11-08 23:09:53 +00:00
2021-11-18 13:48:43 +00:00
2021-10-27 18:42:13 +00:00
2020-03-23 20:18:15 +00:00
2021-09-22 21:21:40 +00:00
2021-11-19 14:42:04 +00:00
2021-06-23 01:33:20 +00:00
2021-11-16 01:41:23 +00:00
2021-11-07 01:35:52 +00:00
2021-08-16 20:16:13 +00:00
2021-09-22 21:21:40 +00:00
2021-07-30 19:34:39 +00:00
2021-07-30 19:34:39 +00:00
2021-11-19 20:22:43 +00:00
2021-11-18 13:55:36 +00:00
2021-11-08 14:21:44 +00:00
2021-10-29 23:11:32 +00:00
2020-02-06 06:31:22 +00:00
2021-11-10 00:39:45 +00:00
2021-11-15 10:59:48 +00:00
2021-05-25 08:26:21 +00:00
2021-08-10 19:43:33 +00:00
2020-02-06 06:31:22 +00:00
2021-11-13 07:26:52 +00:00
2020-11-03 17:34:20 +00:00
2020-02-09 16:52:28 +00:00
2021-03-20 18:28:32 +00:00
2020-07-23 19:04:38 +00:00
2021-05-15 17:36:49 +00:00
2021-11-16 19:40:36 +00:00
2021-11-19 14:42:04 +00:00
2021-09-02 08:29:03 +00:00
2021-11-19 15:12:25 +00:00
2021-11-11 16:27:44 +00:00
2021-11-08 21:44:12 +00:00
2021-11-09 22:58:39 +00:00
2021-05-15 17:36:49 +00:00
2021-02-02 00:08:01 +00:00
2021-11-10 19:54:51 +00:00
2021-11-09 18:49:12 +00:00
2021-11-19 14:42:04 +00:00
2021-11-12 01:08:35 +00:00
2021-11-17 15:54:40 +00:00
2021-11-16 21:23:12 +00:00
2021-11-11 18:30:27 +00:00
2020-10-17 16:03:58 +00:00
2021-08-17 22:07:55 +00:00
2021-11-18 15:10:18 +00:00
2020-11-19 18:22:02 +00:00
2021-07-06 20:20:51 +00:00
2021-11-18 13:55:36 +00:00
2020-10-18 20:52:01 +00:00
2020-10-18 17:25:10 +00:00
2020-05-16 18:40:52 +00:00
2021-11-18 13:55:36 +00:00
2021-01-03 22:02:13 +00:00
2021-11-16 17:07:43 +00:00
2021-11-15 12:47:22 +00:00
2021-11-08 10:47:55 +00:00
2021-11-18 16:02:41 +00:00
2021-05-04 15:00:33 +00:00
2020-11-24 21:25:46 +00:00
2021-11-18 13:48:43 +00:00
2021-11-18 13:48:43 +00:00
2021-11-19 14:42:04 +00:00
2021-06-15 15:21:50 +00:00
2020-11-12 11:15:49 +00:00
2020-11-12 11:15:49 +00:00
2021-11-11 03:50:22 +00:00
2021-11-10 01:25:09 +00:00
2020-11-19 16:13:54 +00:00
2021-03-23 23:00:03 +00:00
2020-11-16 22:50:03 +00:00
2021-01-04 17:16:43 +00:00
2021-11-16 19:59:11 +00:00
2020-02-06 06:31:22 +00:00
2021-06-15 15:21:50 +00:00
2021-05-15 17:36:49 +00:00
2020-11-12 11:15:49 +00:00
2021-11-18 13:48:43 +00:00
2021-11-09 02:15:23 +00:00
2020-05-26 09:35:34 +00:00
2021-05-25 14:19:14 +00:00
2021-11-08 19:18:39 +00:00
2021-11-08 23:09:53 +00:00
2021-11-08 19:18:39 +00:00
2021-11-10 14:16:03 +00:00
2021-11-16 22:18:32 +00:00
2021-11-09 16:21:00 +00:00
2020-10-08 21:13:57 +00:00
2021-10-18 13:29:47 +00:00
2021-11-18 13:48:43 +00:00
2021-11-19 18:58:14 +00:00
2020-02-06 06:31:22 +00:00