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 | Owned by: | 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)
Change History (10)
#6
@
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.
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 sameif
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.