-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass the comments query paged
arg to functions get_next_comments_link
and get_previous_comments_link
#63698
Pass the comments query paged
arg to functions get_next_comments_link
and get_previous_comments_link
#63698
Conversation
paged
arg to functions get_next_comments_link
and get_previous_comments_link
Is there a similar fix required for the It looks like it also should get covered as it calls |
I believe you are right and we should cover |
@ockham, can you confirm this approach would work from your perspective? As far as I'm concerned, it might resolve the issue. |
Apologies for the late reply. Yeah, I think making the argument explicit should be the way forward to make this work. We will have to implement the "other side" -- i.e. the changes to @SantosGuillamot Do you have some bandwidth to take that on? I'm a bit swamped with other things these days 😅 |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I have created this alternative pull request in core, which removes the problematic That PR plus this one should solve both problems.
Regarding this, I've been taking a deeper look and I believe it is not needed. Let me explain my reasoning: |
@@ -37,7 +37,7 @@ function render_block_core_comments_pagination_next( $attributes, $content, $blo | |||
$label .= $pagination_arrow; | |||
} | |||
|
|||
$next_comments_link = get_next_comments_link( $label, $max_page ); | |||
$next_comments_link = get_next_comments_link( $label, $max_page, $comment_vars['paged'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in WordPress/wordpress-develop#7275 (comment), we need to add some safeguards to make sure that we're not passing this extra argument if get_next_comments_link()
-- as provided by whatever WordPress version is running -- doesn't support the additional parameter yet.
To do so, I think our best course of action is PHP's ReflectionFunction
:
Something like (untested):
$next_comments_link = get_next_comments_link( $label, $max_page, $comment_vars['paged'] ); | |
$get_next_comments_link_reflection = new ReflectionFunction( 'get_next_comments_link' ); | |
if ( $get_next_comments_link_reflection->getNumberOfParameters() >= 3 ) { | |
$next_comments_link = get_next_comments_link( $label, $max_page, $comment_vars['paged'] ); | |
} else { | |
$next_comments_link = get_next_comments_link( $label, $max_page ); | |
} |
and accordingly for get_previous_comments_link
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to add this safety check? If I am not mistaken, when passing the third argument to a function that only accepts two, PHP will just ignore it, right? At least, that's what I can see from my testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are functions like func_get_args that allow to handle any number of params, so as far as I tested it, providing an additional param that isn't handled works just fine.
<?php
function foo()
{
$numargs = func_num_args();
echo "Number of arguments: $numargs \n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "\n";
}
}
foo(1, 2, 3);
?>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, fair enough! I was assuming that PHP would at least issue a warning or a notice if strict error reporting was enabled, but it seems that that isn't the case. (Here's a related SO thread.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it fatals on built-in functions I tested, but not on custom functions 🤷🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it directly with get_next_comments_link
in a branch without the changes and it doesn't seem to break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM 👍
I found an issue that was likely caused by changes in this PR: #65424 |
I just came here to report the same thing 😕 |
I've started a PR trying to solve that: #65435 |
What?
According to this report, the solution introduced in this pull request to solved the mentioned bug, where
cpage
was updated based on the query, is causing problems with plugins relying on it being0
or undefined.This pull request explores another alternative to solve the initial bug without modifying
cpage.
It needs to be tested with this other core pull request, which modifies the relevant functions to accept the new parameter.
How?
Pass the
paged
argument from the query to get_next_comments_link and get_previous_comments_link so they only read thecpage
when it is not defined. A check like the following must be added in the core functions:Testing Instructions
It needs to be tested with this other core pull request, which modifies the relevant functions to accept the new parameter.
last page displayed by default.