Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#11435 closed defect (bug) (fixed)

Notice when requesting post title of non-existent post

Reported by: filosofo's profile filosofo Owned by: ryan's profile ryan
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9
Component: General Keywords: has-patch get_the_title tested
Focuses: Cc:

Description

If you try to get the post title using get_the_title(123), where 123 is not an existing post's ID, you get two notices because get_the_title() tries to access non-existent properties of NULL.

What exacerbates the problem is that the ID passed to the "the_title" filter is based on the (non-existent) ID property of the supposed post object. So filter callbacks can't fully deal with non-existent post title requests, as they do not get the requested ID.

Attachments (1)

get_the_title.notice.11435.diff (700 bytes) - added by filosofo 15 years ago.

Download all attachments as: .zip

Change History (4)

#1 @hakre
15 years ago

Related: #11521

#2 @hakre
15 years ago

  • Keywords tested added

Tested the patch. Does apply clean, works.

The only change compared to the current behaviour is, that for the case $post->post_title was undefined, it now passes an empty string instead of NULL to the various filters. IMHO this is a good to go, otherwise we could default the title to NULL to gain 100% binary compability.

#3 @westi
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12550]) Fix notices in get_the_title() when passed an invalid id. Also ensure that the filter gets the invalid id so a plugin can supply a default title instead. Fixes #11435 props filosofo.

Note: See TracTickets for help on using tickets.