WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 4 months ago

#43229 closed defect (bug) (fixed)

Documentation for add_meta_boxes hook is incorrect

Reported by: johnbillion Owned by: SergeyBiryukov
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch
Focuses: docs Cc:

Description

The documentation for the add_meta_boxes hook states that the $post parameter is a WP_Post object. This is incorrect because the object can be any type. On the comment editing screen for example, this parameter is a WP_Comment object.

Attachments (1)

43229.diff (567 bytes) - added by danieltj 5 months ago.
Patch to include all three object types.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
5 months ago

  • Component changed from General to Options, Meta APIs

#2 follow-up: @danieltj
5 months ago

  • Component changed from Options, Meta APIs to General

The add_meta_boxes hook doesn't have a parameter for a $post, at least not in function I found. Am I looking at the wrong one? I didn't see anything that referenced posts.

Reference: https://core.trac.wordpress.org/browser/tags/4.9/src/wp-admin/includes/template.php#L886

#3 @danieltj
5 months ago

  • Component changed from General to Options, Meta APIs

Sorry @SergeyBiryukov my comment overwrote the changes. I reverted back.

#4 in reply to: ↑ 2 ; follow-up: @SergeyBiryukov
5 months ago

Replying to danieltj:

The add_meta_boxes hook doesn't have a parameter for a $post, at least not in function I found. Am I looking at the wrong one? I didn't see anything that referenced posts.

It's about the add_meta_boxes filter, not the add_meta_box() function :) There are 3 instances of the hook:

#5 in reply to: ↑ 4 @danieltj
5 months ago

Replying to SergeyBiryukov:

Replying to danieltj:

The add_meta_boxes hook doesn't have a parameter for a $post, at least not in function I found. Am I looking at the wrong one? I didn't see anything that referenced posts.

It's about the add_meta_boxes filter, not the add_meta_box() function :) There are 3 instances of the hook: [...]

Ah, thank you for pointing that out. Was very confused when I saw the docs.

I'll take a look.

@danieltj
5 months ago

Patch to include all three object types.

This ticket was mentioned in Slack in #core by danieltj. View the logs.


4 months ago

#7 @SergeyBiryukov
4 months ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 5.0

#8 @SergeyBiryukov
4 months ago

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

In 42796:

Docs: Improve documentation for add_meta_boxes and do_meta_boxes actions.

Props danieltj, johnbillion, SergeyBiryukov.
Fixes #43229.

Note: See TracTickets for help on using tickets.