Commit Graph

485 Commits

Author SHA1 Message Date
hellofromTonya 30c9e4338d 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.
Built from https://develop.svn.wordpress.org/trunk@52223


git-svn-id: http://core.svn.wordpress.org/trunk@51815 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-19 20:24:00 +00:00
John Blackbourn 40626108d0 Docs: Corrections relating to types used in inline documentation for comment ID and site ID proprties.
Includes a correction for a typo introduced in [52204].

See #53399

Built from https://develop.svn.wordpress.org/trunk@52205


git-svn-id: http://core.svn.wordpress.org/trunk@51797 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-18 13:57:01 +00:00
joedolson 387f4467a4 Comments: Change new comment required text class.
Change the new class on comment required text from `comment-required-message` to `required-field-message` for better future-compatibility, enabling better reuse.

Props sabernhardt.
Fixes #16206.

Built from https://develop.svn.wordpress.org/trunk@52200


git-svn-id: http://core.svn.wordpress.org/trunk@51792 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-17 18:38:02 +00:00
hellofromTonya df540dbd95 Comments: Don't output "cancel comment reply link" if comments aren't threaded.
Though hidden via `style="display:none;"`, if the comments aren't threaded, this commit doesn't output the cancel comment reply link (skips over that logic). Change in `comment_form()`.

Adds tests.

Follow-up to [12810], [38959].

Props henrywright, jigneshnakrani, rachelbaker, desrosj, audrasjb, hellofromTonya.
Fixes #37267.
Built from https://develop.svn.wordpress.org/trunk@52175


git-svn-id: http://core.svn.wordpress.org/trunk@51767 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-16 02:14:59 +00:00
Sergey Biryukov 17ae1d0c7f Comments: Use `get_comment_author()` to retrieve the comment author name in `get_comment_reply_link()`.
This ensures that the `get_comment_author` filter is applied to the comment author name as expected.

Follow-up to [29822], [47506].

Props mjulian7, audrasjb, chaion07, hellofromTonya, SergeyBiryukov.
Fixes #53678.
Built from https://develop.svn.wordpress.org/trunk@52154


git-svn-id: http://core.svn.wordpress.org/trunk@51746 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-14 18:01:04 +00:00
joedolson 56b07f0ea2 Comments: Mark comment text field as required.
Add required asterisk to the comment text field. Historically, the name and email fields are marked as required, but the comment text field is not, though it is actually a required field.

Props infected, solarissmoke, rianrietveld, afercia, sabernhardt, strider72, mai21, audrasjb.
Fixes #16206.
Built from https://develop.svn.wordpress.org/trunk@52029


git-svn-id: http://core.svn.wordpress.org/trunk@51621 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-07 21:14:58 +00:00
John Blackbourn ae9eae8f64 Docs: Document some more common names for dynamic hooks and standardise the phrasing used.
Fixes #53581

Built from https://develop.svn.wordpress.org/trunk@51837


git-svn-id: http://core.svn.wordpress.org/trunk@51444 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-21 18:21:00 +00:00
John Blackbourn efaf4a8938 Docs: Add and correct examples of common names for various dynamic hooks.
See #53581

Built from https://develop.svn.wordpress.org/trunk@51327


git-svn-id: http://core.svn.wordpress.org/trunk@50936 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-03 21:42:59 +00:00
John Blackbourn ea60cd8191 Docs: Descriptive improvements and corrections for various docblocks.
See #53399

Built from https://develop.svn.wordpress.org/trunk@51300


git-svn-id: http://core.svn.wordpress.org/trunk@50909 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-01 21:12:58 +00:00
joedolson 82f31a97cb Coding Standards: Extraneous white space at end of line.
Fixes a minor coding standards issue.

Follow up to [51082].

See #51189.
Built from https://develop.svn.wordpress.org/trunk@51084


git-svn-id: http://core.svn.wordpress.org/trunk@50693 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-07 23:15:58 +00:00
joedolson 50fd820621 Comments: Return valid comment reply link if comments are paginated.
Fix the link returned by `get_comment_reply_link()` so the link points to the correct page of comments when links are paginated. While this link is normally overridden by the comment-reply script, if that script is disabled, the link would point to a location that did not exist when comments were paginated.

props MrPauloEn, paaggeli, alexstine, engahmeds3ed.
Fixes #51189.
Built from https://develop.svn.wordpress.org/trunk@51081


git-svn-id: http://core.svn.wordpress.org/trunk@50690 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-07 21:49:59 +00:00
John Blackbourn b59c0f307b Docs: Corrections and improvements to types used in various docblocks.
See #51800, #52217

Built from https://develop.svn.wordpress.org/trunk@49936


git-svn-id: http://core.svn.wordpress.org/trunk@49635 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-05 17:16:11 +00:00
Sergey Biryukov 0a20850f57 Docs: Clarify the `$format` parameter description in `comment_time()`.
See #51800.
Built from https://develop.svn.wordpress.org/trunk@49735


git-svn-id: http://core.svn.wordpress.org/trunk@49458 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-02 16:55:06 +00:00
John Blackbourn f4cda1b62f Docs: Upgrade more parameters in docblocks to used typed array notation.
See #51800, #41756

Built from https://develop.svn.wordpress.org/trunk@49693


git-svn-id: http://core.svn.wordpress.org/trunk@49416 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-24 21:27:05 +00:00
Sergey Biryukov e569358678 General: Ensure that filtered arguments in `get_search_form()` contain all required default values.
Props kellybleck, davidbaumwald, whyisjake, SergeyBiryukov.
Fixes #51645.
Built from https://develop.svn.wordpress.org/trunk@49355


git-svn-id: http://core.svn.wordpress.org/trunk@49115 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-28 16:57:08 +00:00
Sergey Biryukov fbd8078d4e Comments: Add a filter for top level comments query arguments in `comments_template()`.
Props hellofromTonya, Howdy_McGee, garrett-eclipse, davidbaumwald, thomaslhotta.
Fixes #38074.
Built from https://develop.svn.wordpress.org/trunk@49256


git-svn-id: http://core.svn.wordpress.org/trunk@49018 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-20 20:11:06 +00:00
Sergey Biryukov 0e3147c40e Coding Standards: Replace alias PHP functions with the canonical names.
Using the canonical function name for PHP functions is strongly recommended, as aliases may be deprecated or removed without (much) warning.

This replaces all uses of the following:
* `join()` with `implode()`
* `sizeof()` with `count()`
* `is_writeable()` with `is_writable()`
* `doubleval()` with a `(float)` cast

In part, this is a follow-up to #47746.

Props jrf.
See #50767.
Built from https://develop.svn.wordpress.org/trunk@49193


git-svn-id: http://core.svn.wordpress.org/trunk@48955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-18 17:27:06 +00:00
Sergey Biryukov 897f004a9c General: Replace older-style PHP type conversion functions with type casts.
This improves performance, readability, and consistency throughout core.

* `intval()` → `(int)`
* `strval()` → `(string)`
* `floatval()` → `(float)`

Props ayeshrajans.
Fixes #42918.
Built from https://develop.svn.wordpress.org/trunk@49108


git-svn-id: http://core.svn.wordpress.org/trunk@48870 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-08 21:15:13 +00:00
Sergey Biryukov 0418dad234 Docs: Synchronize the description of the `$format` parameter in various date/time functions for posts and comments.
See #50768.
Built from https://develop.svn.wordpress.org/trunk@48929


git-svn-id: http://core.svn.wordpress.org/trunk@48691 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-09-01 00:43:06 +00:00
Sergey Biryukov d3abb209e1 Date/Time: In `get_the_date()` and related functions, pass the original, unmodified `$format` value to the filters.
Additionally, simplify the `$format` argument checks for consistency with similar checks in `get_the_modified_date()` and `get_the_modified_time()`.

Follow-up to [48912].

Props Rarst.
See #51184.
Built from https://develop.svn.wordpress.org/trunk@48918


git-svn-id: http://core.svn.wordpress.org/trunk@48680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-31 18:30:05 +00:00
Sergey Biryukov aec28121b3 Date/Time: Make sure `get_the_date()` and related functions return correct time if the format was specified as `false`.
Technically, the `$format` argument should always be a string, but passing `false` used to work before [47808], so this restores backward compatibility.

The list of affected functions:
* `get_the_date()`
* `get_the_time()`
* `get_comment_date()`
* `get_comment_time()`

Props wittich, Rarst, akabarikalpesh, SergeyBiryukov.
Fixes #51184.
Built from https://develop.svn.wordpress.org/trunk@48912


git-svn-id: http://core.svn.wordpress.org/trunk@48674 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-31 15:58:04 +00:00
John Blackbourn 782f05d2c5 Docs: Various fixes and improvements to inline documentation.
See #49572
Built from https://develop.svn.wordpress.org/trunk@48695


git-svn-id: http://core.svn.wordpress.org/trunk@48457 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-30 19:14:03 +00:00
Sergey Biryukov 7913a1c7db Docs: Improve documentation for `wp_list_comments()`.
Note that passing `div` to the `style` parameter will result in no additional list markup.

Props liuhaibin, jeremyfelt, functionalrhyme.
Fixes #49181.
Built from https://develop.svn.wordpress.org/trunk@48597


git-svn-id: http://core.svn.wordpress.org/trunk@48359 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-24 01:11:02 +00:00
John Blackbourn 9bc7d0a776 Docs: Another pass at some inline docs fixes mostly made by PHPCBF.
See #49572, #50744
Built from https://develop.svn.wordpress.org/trunk@48590


git-svn-id: http://core.svn.wordpress.org/trunk@48352 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 21:11:05 +00:00
Sergey Biryukov 12747ac7b7 Coding Standards: Use a consistent naming pattern for variables in `wp-includes/comment-template.php`.
See #49542.
Built from https://develop.svn.wordpress.org/trunk@48579


git-svn-id: http://core.svn.wordpress.org/trunk@48341 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 13:34:07 +00:00
Sergey Biryukov d1b980492f Docs: Improve description for `comment_id_fields()`.
Rename the `$id` parameter to `$post_id` for clarity.

Props stevenlinx.
Fixes #50737.
Built from https://develop.svn.wordpress.org/trunk@48577


git-svn-id: http://core.svn.wordpress.org/trunk@48339 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 13:11:04 +00:00
John Blackbourn 4ff1233e75 Docs: Correct and improve inline docs for parameters that accept a callback function.
See #49572
Built from https://develop.svn.wordpress.org/trunk@48473


git-svn-id: http://core.svn.wordpress.org/trunk@48242 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-14 11:56:04 +00:00
Sergey Biryukov af5c8f316c Docs: Improve description of the `$text` parameter in `cancel_comment_reply_link()`.
Props stevenlinx.
Fixes #50642.
Built from https://develop.svn.wordpress.org/trunk@48457


git-svn-id: http://core.svn.wordpress.org/trunk@48226 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-13 14:42:03 +00:00
Sergey Biryukov ca1b6f324c Comments: Allow passing a custom class to the form container element in `comment_form()`.
Props cjbj, yahil, mayankmajeji, andraganescu, SergeyBiryukov.
Fixes #41009.
Built from https://develop.svn.wordpress.org/trunk@48393


git-svn-id: http://core.svn.wordpress.org/trunk@48162 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 18:29:04 +00:00
Sergey Biryukov 803a05946b Comments: Remove `wp_get_include_unapproved_comments_argument()` for now.
The function seems too specific and low-level for an abstraction, is only used in two places, and does not provide a significant benefit in terms of reducing code duplication.

Follow-up to [48133].

See #8973.
Built from https://develop.svn.wordpress.org/trunk@48140


git-svn-id: http://core.svn.wordpress.org/trunk@47909 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-23 13:53:08 +00:00
whyisjake 0c91c23277 Comments: Ensure the proper comment count and pages for unapproved comments.
Previiously, unapproved comments can alter the comment count, returning incorrect page numbers.

Fixes #8973.

Props GregMulhauser, dd32, ryan, mrmist, hakre, solarissmoke, billerickson, ericlewis, SergeyBiryukov, chriscct7, dossy, lukecavanagh, renggo888, jdorner, matjack1, pento, audrasjb, imath, davidbaumwald, whyisjake.  


Built from https://develop.svn.wordpress.org/trunk@48133


git-svn-id: http://core.svn.wordpress.org/trunk@47902 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-23 05:24:10 +00:00
Sergey Biryukov e13c363b17 Docs: Capitalize "ID", when referring to a post ID, term ID, etc. in a more consistent way.
See #49572.
Built from https://develop.svn.wordpress.org/trunk@48104


git-svn-id: http://core.svn.wordpress.org/trunk@47873 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-20 12:02:12 +00:00
whyisjake c075eec24f Editor: Ensure latest comments can only be viewed from public posts.
Props: poena, xknown. 

Built from https://develop.svn.wordpress.org/trunk@47984


git-svn-id: http://core.svn.wordpress.org/trunk@47752 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-10 19:20:11 +00:00
Sergey Biryukov 569c006248 Comments: Rename `Walker_Comment::comment_text()` to `::filter_comment_text()` for clarity.
Ensure the comment object is not null before checking its status.

Follow-up to [47887].

See #49956.
Built from https://develop.svn.wordpress.org/trunk@47889


git-svn-id: http://core.svn.wordpress.org/trunk@47663 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-02 21:45:10 +00:00
Sergey Biryukov 7932193708 Coding Standards: Use strict comparison where static strings are involved.
This reduces the number of `WordPress.PHP.StrictComparisons.LooseComparison` issues in half, from 1897 to 890.

Includes minor code layout fixes for better readability.

See #49542.
Built from https://develop.svn.wordpress.org/trunk@47808


git-svn-id: http://core.svn.wordpress.org/trunk@47584 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-05-16 18:42:12 +00:00
noisysocks b4e1e8f0d1 Comments: Fix title not updating when replying to a comment
When replying to an existing comment, the comment form is moved to below the
existing comment with JS, but the form heading was not being updated. This
fixes the issue by introducing a new data-attribute to the reply link with the
correct heading string, and applying that string to the heading when the form
is moved.

Props isabel_brison, azaozz, peterwilsoncc.
Fixes #38009.

Built from https://develop.svn.wordpress.org/trunk@47506


git-svn-id: http://core.svn.wordpress.org/trunk@47281 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-03-25 04:55:10 +00:00
Sergey Biryukov 5308f570cb Comments: Restore the fourth parameter of `comments_number()` as `$post_id`, for consistency with `get_comments_number_text()`.
The parameter was previously used as the number of comments, marked as deprecated in [5101].

Given that it's been deprecated for the last 13 years, it should be safe to undeprecate and repurpose it for a cleaner function signature, instead of adding a fifth parameter.

Follow-up to [47276].

Fixes #48772.
Built from https://develop.svn.wordpress.org/trunk@47366


git-svn-id: http://core.svn.wordpress.org/trunk@47153 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-25 17:34:08 +00:00
Sergey Biryukov 6b2c63031c Coding Standards: Rename `$d` parameter in various date/time functions to `$format` for clarity.
See #49222.
Built from https://develop.svn.wordpress.org/trunk@47287


git-svn-id: http://core.svn.wordpress.org/trunk@47087 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-14 00:07:07 +00:00
Sergey Biryukov 17e563cd9c Comments: Add a `$post_id` parameter to `get_comments_number_text()` and `comments_number()`.
This allow for using these functions outside of the loop.

Props donmhico, garrett-eclipse, Hinjiriyo, imath.
Fixes #48772.
Built from https://develop.svn.wordpress.org/trunk@47276


git-svn-id: http://core.svn.wordpress.org/trunk@47076 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-11 20:41:05 +00:00
Sergey Biryukov 641c632b0c Coding Standards: Use Yoda conditions where appropriate.
See #49222.
Built from https://develop.svn.wordpress.org/trunk@47219


git-svn-id: http://core.svn.wordpress.org/trunk@47019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-09 16:55:09 +00:00
Sergey Biryukov 47ed56f38f Code Modernization: Replace `dirname( __FILE__ )` calls with `__DIR__` magic constant.
This avoids the performance overhead of the function call every time `dirname( __FILE__ )` was used instead of `__DIR__`.

This commit also includes:

* Removing unnecessary parentheses from `include`/`require` statements. These are language constructs, not function calls.
* Replacing `include` statements for several files with `require_once`, for consistency:
 * `wp-admin/admin-header.php`
 * `wp-admin/admin-footer.php`
 * `wp-includes/version.php`

Props ayeshrajans, desrosj, valentinbora, jrf, joostdevalk, netweb.
Fixes #48082.
Built from https://develop.svn.wordpress.org/trunk@47198


git-svn-id: http://core.svn.wordpress.org/trunk@46998 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-06 06:33:11 +00:00
Sergey Biryukov 001ffe81fb Docs: Improve inline comments per the documentation standards.
Includes minor code layout fixes for better readability.

See #48303.
Built from https://develop.svn.wordpress.org/trunk@47122


git-svn-id: http://core.svn.wordpress.org/trunk@46922 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-01-29 00:45:18 +00:00
Sergey Biryukov 1c3b5c9dc8 Comments: Add `In reply to %s.` prefix to child comments in comments feed.
The prefix includes a link to the parent comment and the name of its author.

Props zodiac1978, imath, SergeyBiryukov.
Fixes #43429.
Built from https://develop.svn.wordpress.org/trunk@47111


git-svn-id: http://core.svn.wordpress.org/trunk@46911 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-01-26 22:29:06 +00:00
Sergey Biryukov dd4d98a368 Docs: In various `@return` tags, list the expected type first, instead of `false`.
Follow-up to [46696].

See #48303.
Built from https://develop.svn.wordpress.org/trunk@47060


git-svn-id: http://core.svn.wordpress.org/trunk@46860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-01-11 18:32:05 +00:00
Sergey Biryukov 523bf256ef Docs: Synchronize "Default empty array" notes for `$args` parameter in `get_comment_text()` and `comment_text()`.
Props denisco.
See #48303.
Built from https://develop.svn.wordpress.org/trunk@47032


git-svn-id: http://core.svn.wordpress.org/trunk@46832 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-01-02 19:22:03 +00:00
Sergey Biryukov 8073fd3ec0 Docs: Use a third-person singular verb for comment template function descriptions, per the documentation standards.
See #48303.
Built from https://develop.svn.wordpress.org/trunk@47009


git-svn-id: http://core.svn.wordpress.org/trunk@46809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-12-24 16:19:01 +00:00
Sergey Biryukov 9c68816a21 Docs: Improve documentation for `get_comment_author_url()`.
Props stevenlinx.
Fixes #49076.
Built from https://develop.svn.wordpress.org/trunk@47008


git-svn-id: http://core.svn.wordpress.org/trunk@46808 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-12-24 16:10:05 +00:00
Sergey Biryukov c87fccd74f Comments: Avoid a PHP notice in `comment_form()` if the `email` field is not set.
Follow-up to [46090].

Props mat-lipe.
Fixes #48943.
Built from https://develop.svn.wordpress.org/trunk@46885


git-svn-id: http://core.svn.wordpress.org/trunk@46685 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-12-11 22:14:02 +00:00
John Blackbourn aa1fdcbd52 Docs: Correct various docblocks documentation.
See #48303
Built from https://develop.svn.wordpress.org/trunk@46821


git-svn-id: http://core.svn.wordpress.org/trunk@46621 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-12-06 22:23:04 +00:00
John Blackbourn f545bb3f63 Docs: Improve documentation of known return types, plus other docs fixes.
See #48303

Built from https://develop.svn.wordpress.org/trunk@46660


git-svn-id: http://core.svn.wordpress.org/trunk@46460 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-11-05 21:23:02 +00:00