📜 ⬆️ ⬇️

Mystical bug of the last WordPress of the old Opera 8.5

Four night hours spent searching for information. As a result, I again had to figure out the code myself, armed with a self-help manual and the Internet.

We are preparing to launch a corporate blog. As an approximate kid, I downloaded the latest version of Wordpress from the official site so that it contained all the necessary security patches. There just recently released some kind of stable version. I bet. I am happy. I'm starting to test.

Add comments. Everything is fine in IE. Everything is fine in Firefox. I'm starting to test in Opera ... Opanki. After the guest has sent the comment, the page is not updated. I press F5 to update it manually. I see that the comment got into the database. On my other blogs there is no such thing (there is an older version of Wordpress).
')
I'm starting to dig. I put another topic. All the same. I put a set of plug-ins from another blog. No changes. Word and reinstall Wordpress. The bug stayed. I see the same on other people's blogs, but I don’t want to have it left, especially on a corporate blog.

We are looking for in Yandex. Nothing. We are looking for in Google. We are looking for Wordpress. A huge number of bug reports that have not been answered for 7-8 months already. Free software, Christmas trees. In general, the search for results was not successful (usually it takes about 20 minutes to find the answer).

Having already experience in the support and development of a single software product, I understand: the problem is in the updated version. The guess was confirmed by the installation of the old wordpress. It all worked.

Rushed. Now I know that the case is most likely in one of the functions from the wp-comments-post.php file (it accepts comments). First I try to simply replace it with a file from the old version. Stop working at all. I'm starting to dig into this file. I am not a programmer, I understand someone else's code every time. I guess he does something like that first, and then redirects the user to the page with the answer.

In the end I see the following structure:

$ location = (empty ($ _ POST ['redirect_to'])? get_permalink ($ comment_post_ID): $ _POST ['redirect_to']). '# comment-'. $ comment_id;
$ location = apply_filters ('comment_post_redirect', $ location, $ comment);
wp_redirect ($ location);

I do not know why I caught up with her. Compare with old Wordpress:

$ location = (empty ($ _POST ['redirect_to']))? get_permalink ($ comment_post_ID): $ _POST ['redirect_to'];
wp_redirect ($ location);

At first I thought it was the matter of apply_filters. Commented out. Problem still exists. I look at this construction here (?:) For about 10 minutes (I did not find in the self-guide that the operation was done with a colon). Seeking what is empty. It turns out that this is a function that checks if its argument is not empty. Then I begin to understand that this construction checks some condition, and depending on it, forms a link for the redirect. And “redirect_to”, it turns out, is some hidden form field that can be substituted into your topic and tell the engine where to send the user after the comment. Initially I did not find such a field in the WordPress themes in comments.php.

And here I notice that in the previous version the bracket is in a different place. I decided to try to replace this construction with brackets on the one in the previous WordPress. It worked like.

I did not understand why I screwed up there and why it worked. It was:

$ location = (empty ($ _ POST ['redirect_to'])? get_permalink ($ comment_post_ID): $ _POST ['redirect_to']). '# comment-'. $ comment_id;

It became:

$ location = (empty ($ _POST ['redirect_to']))? get_permalink ($ comment_post_ID): $ _POST ['redirect_to']. '# comment-'. $ comment_id;

Now the “tail” disappears somewhere, which redirects not just to the page, but to the added comment. We are trying to enclose the bracket construction in one more bracket:

$ location = ((empty ($ _POST ['redirect_to']))? get_permalink ($ comment_post_ID): $ _POST ['redirect_to']). '# comment-'. $ comment_id;

In IE and FF, and Opera again stopped updating the page. The cursor is hanging, some load is being displayed, and that's it. As a result, came to this option:

$ location = (empty ($ _POST ['redirect_to']))? get_permalink ($ comment_post_ID): $ _POST ['redirect_to'];
$ location = $ location. '# comment-'. $ comment_id;

But that is not all!!!

I add one comment, the second. And then opa! Bug is back. I try to put a slash in front of the bars. Are added. The next comment is that the page is not updated again. I remove the slash. Is added. The next comment is again a bug.

Can someone say what was the matter? And yet, I still do not understand why this bug is manifested only in Opera and only in Wordpress 2.2?

Source: https://habr.com/ru/post/12010/


All Articles