Opened 10 years ago
Last modified 4 weeks ago
#31711 new defect (bug)
is_front_page flag affected by frontpage ID and page Title strange conflict
Reported by: | m_i_n | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | General | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
I want to report a strange bug. The is_front_page flag has incorrect value in cases like described below:
Front page in Settings / Reading is set to a static page: http://i.imgur.com/DzrbOVM.png
This Sample Page ID is 2
If you visit any other page, all is fine. For example the Lorem ipsum page: http://i.imgur.com/n5M0x8R.png
However, if you change title of this page to be the same as ID of a frontpage - in my case 2, then the is_front_page flag changes value to incorrect: http://i.imgur.com/KCa1JYo.png
It happens for titles like: 2, 02, 000002. Basically always if (int)$page_title == $front_page_id
The wrong is_front_page flag may affect themes/plugins which use it.
It's quite rare for the bug to take effect, but it happens, as I got a report from a user of my theme.
Attachments (1)
Change History (11)
@
10 years ago
Fixing is_front_page()
conflicts with the titles of other page when they are the same like the ID of the front page. Including a unit test for that case.
This ticket was mentioned in PR #7101 on WordPress/wordpress-develop by @tw2113.
2 months ago
#6
- Keywords has-unit-tests added
This code change updates original changes from the trac ticket below, to match the current code from WordPress Trunk. Everything should match what the original patch submitter added, with the exception of strict type checking between integers.
Trac ticket: See https://core.trac.wordpress.org/ticket/31711
@mukesh27 commented on PR #7101:
2 months ago
#7
@tw2113 The unit tests going failed, could you please check it?
2 months ago
#9
Notes for future me:
7) Tests_Query_Conditionals::test_page_on_front is_front_page is false but is expected to be true. /var/www/tests/phpunit/includes/abstract-testcase.php:1145 /var/www/tests/phpunit/tests/query/conditionals.php:49 /var/www/vendor/bin/phpunit:122 8) Tests_Query_Conditionals::test_is_front_page_id_equals_the_title_of_other_page Failed asserting that false is true. /var/www/tests/phpunit/tests/query/conditionals.php:1321 /var/www/vendor/bin/phpunit:122 9) Tests_Query_VerbosePageRules::test_page_on_front is_front_page is false but is expected to be true. /var/www/tests/phpunit/includes/abstract-testcase.php:1145 /var/www/tests/phpunit/tests/query/conditionals.php:49 /var/www/vendor/bin/phpunit:122 10) Tests_Query_VerbosePageRules::test_is_front_page_id_equals_the_title_of_other_page Failed asserting that false is true. /var/www/tests/phpunit/tests/query/conditionals.php:1321 /var/www/vendor/bin/phpunit:122
I was able to reproduce the described issue. That's such an interesting bug.
This is caused by the (expected) ambiguous behavior of the
is_page()
conditional tag, which is used withinis_front_page()
.As the documentation states,
is_page()
accepts:Page ID, title, slug, path, or array of such
, so in that case2
is being accepted as title, which is why theis_front_page()
function returnstrue
.Patch with a fix is coming in a minute.