Make WordPress Core

Opened 8 years ago

Last modified 4 years ago

#31711 new defect (bug)

is_front_page flag affected by frontpage ID and page Title strange conflict

Reported by: m_i_n's profile m_i_n Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: General Keywords: has-patch
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)

31711.patch (1.6 KB) - added by tyxla 8 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.

Download all attachments as: .zip

Change History (6)

#1 @tyxla
8 years ago

  • Keywords needs-patch added

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 within is_front_page().

As the documentation states, is_page() accepts: Page ID, title, slug, path, or array of such, so in that case 2 is being accepted as title, which is why the is_front_page() function returns true.

Patch with a fix is coming in a minute.

Last edited 8 years ago by tyxla (previous) (diff)

@tyxla
8 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.

#2 @tyxla
8 years ago

  • Keywords has-patch added; needs-patch removed

#3 @DrewAPicture
8 years ago

#31009 was marked as a duplicate.

#4 @MikeHansenMe
8 years ago

Tested this and it worked as expected. Unit test also passes.

#5 @DrewAPicture
8 years ago

  • Version changed from trunk to 3.1
Note: See TracTickets for help on using tickets.