Make WordPress Core

Opened 12 years ago

Closed 8 years ago

#22247 closed defect (bug) (fixed)

Ensure post ID evaluates to true before adding "Edit post" tab in admin bar

Reported by: joe-anzalone's profile Joe Anzalone Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.7 Priority: normal
Severity: normal Version: 3.1
Component: Toolbar Keywords: has-patch dev-feedback has-unit-tests
Focuses: Cc:

Description

This patch checks that a post has an ID set before adding an "Edit post" link in the admin bar on the front-end for individual post pages and static pages.

This can be helpful for plugins that choose to create a "fake" page that does not exist in the database, and set their ID to "0."

An example of such a fake page can be seen on my On The Fly YouTube Embeds plugin which borrows a lot of code from Scott Sherrill-Mix's blog post: Creating a (Better) Fake Post with a WordPress Plugin

Attachments (2)

22247.diff (617 bytes) - added by Joe Anzalone 12 years ago.
22247.unit-tests.diff (1.4 KB) - added by akibjorklund 8 years ago.

Download all attachments as: .zip

Change History (10)

@Joe Anzalone
12 years ago

#1 @SergeyBiryukov
12 years ago

  • Component changed from General to Toolbar

#2 @SergeyBiryukov
12 years ago

  • Version changed from trunk to 3.1

#3 @morganestes
9 years ago

  • Keywords dev-feedback added

I've tested this out and it works in 4.3.0 trunk. Since we're using $current_object->ID as a parameter twice in the same if check, it makes sense to check it for a valid value beforehand.
That also takes care of the example @Joe Anzalone provided with plugins creating their own posts with an ID of 0.

#4 @morganestes
9 years ago

  • Keywords needs-unit-tests added

#6 @akibjorklund
8 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Not sure what the reported issue actually is, but if I understand correctly, the ticket is about an edit link appearing when there should be none. If this is true, it does not seem to be an issue anymore. get_edit_post_link will fetch the post using get_post and will not return a valid link if the post is not found. I've attached a patch that contains unit tests to prove this.

While the issue itself has probably been fixed within some other ticket and the original patch is unnecessary, the unit tests I created could still be committed.

#7 @SergeyBiryukov
8 years ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#8 @jorbin
8 years ago

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

In 38508:

Toolbar: Add unit tests for edit links.

When there is no post ID, there should be no edit link. This adds unit tests for it.

Fixes #22247.
Props akibjorklund.

Note: See TracTickets for help on using tickets.