WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#25092 closed defect (bug) (fixed)

WP_Post->post_author is not INT

Reported by: 1994rstefan Owned by: nacin
Milestone: 3.7 Priority: normal
Severity: minor Version: 3.6
Component: General Keywords: has-patch
Focuses: Cc:
PR Number:

Description (last modified by SergeyBiryukov)

WP_Post->post_author should be a INT not a STRING.

If you have following Code

$post = get_post(123);
if($post->post_author !== wp_get_current_user()->ID)
   echo 'Not your Post';

it will always fail (printing "Not your Post") because wp_get_current_user()->ID is (as I would expect) a INT but $post->post_author is a STRING.

The WordPress Codex and also the inline PHP Documentation says that post_author is a INT.

Attachments (1)

25092.diff (346 bytes) - added by jamescollins 6 years ago.

Download all attachments as: .zip

Change History (12)

#1 @nacin
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #22324. The short of it: Not going to change for now.

#2 follow-up: @hakre
6 years ago

  • Keywords needs-docs added
  • Resolution duplicate deleted
  • Status changed from closed to reopened

The WordPress Codex and also the inline PHP Documentation says that post_author is a INT.

Don't trust the map, trust the terrain. So please fix the codex and the comments here as it looks like an documentation issue.

From a programmers standpoint you also need to treat those database values as user-values and you need to sanitize them first anyway to have correct working and stable code.

Last edited 6 years ago by hakre (previous) (diff)

#3 in reply to: ↑ 2 @nacin
6 years ago

Replying to hakre:

The WordPress Codex and also the inline PHP Documentation says that post_author is a INT.

Don't trust the map, trust the terrain. So please fix the codex and the comments here as it looks like an documentation issue.

You're welcome to fix the Codex, hakre.

I did not notice the documentation report. WP_Post's phpdoc should be changed, yes.

#4 @SergeyBiryukov
6 years ago

  • Milestone set to Awaiting Review

#5 @nacin
6 years ago

  • Keywords needs-codex added; needs-docs removed
  • Milestone changed from Awaiting Review to 3.7

#6 @nacin
6 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from reopened to closed

In 25086:

PHPDoc for WP_Post properties. fixes #25092.

@jamescollins
6 years ago

#7 @jamescollins
6 years ago

  • Keywords has-patch added
  • Resolution fixed deleted
  • Status changed from closed to reopened

25092.diff fixes a (minor) typo that was introduced in [25086].

#8 @SergeyBiryukov
6 years ago

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

In 25097:

Fix typo in phpdoc. props jamescollins. fixes #25092.

#9 @bcworkz
6 years ago

  • Keywords needs-codex removed

Codex revised 22 Aug 13 by Johnbillion

#11 @SergeyBiryukov
6 years ago

  • Description modified (diff)

Didn't mean to change the description, not sure what happened here.

Note: See TracTickets for help on using tickets.