Make WordPress Core

Opened 4 weeks ago

Closed 3 weeks ago

#64251 closed defect (bug) (fixed)

Documentation for `add_meta_boxes` hook is incorrect

Reported by: opr18's profile opr18 Owned by: westonruter's profile westonruter
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: docs Cc:

Change History (8)

#1 @soyebsalar01
4 weeks ago

The hook is too old and too widely used to be refactored without breaking plugins, so explicitly documenting:
we can add the one line so User might not confuse.

@param WP_Post | WP_Comment | stdClass $post

do_action( 'edit_form_after_title', $post, $title ) this hooks used in several admin screens it is fired with non-WP_Post types, for example:

Link editor -> passes a stdClass (legacy Link Manager structure)

Comment editor-> passes a WP_Comment

Some meta-box contexts -> might pass null or an incomplete object depending on screen

so @opr18 is right the docs expect $post to always be a WP_Post, which isn’t true. This creates fragile code, silent failures, type-hinting conflicts, confusion for people reading core docs.

#2 @opr18
4 weeks ago

  • Summary changed from Documentation for `add_meta_boxes hook` is incorrect to Documentation for `add_meta_boxes` hook is incorrect

#3 @westonruter
4 weeks ago

  • Component changed from Options, Meta APIs to Administration
  • Focuses docs added
  • Milestone changed from Awaiting Review to 7.0

Update the docs to loosen the type of the second param being passed to the hook

This makes sense to me.

This ticket was mentioned in PR #10527 on WordPress/wordpress-develop by @opr18.


4 weeks ago
#4

  • Keywords has-patch added

This patch updates the documentation for the add_meta_boxes_{$post_type} and add_meta_boxes hooks to correctly reflect that $post will not always be a WP_Post object.

Trac ticket: https://core.trac.wordpress.org/ticket/64251

#5 @nikunj8866
4 weeks ago

  • Keywords changes-requested added

@opr18 I've added a comment in PR for a minor adjustment.

#6 @nikunj8866
3 weeks ago

  • Keywords changes-requested removed

#7 @westonruter
3 weeks ago

  • Owner set to westonruter
  • Status changed from new to reviewing

#8 @westonruter
3 weeks ago

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

In 61278:

Docs: Update meta box action documentation to more accurately reflect the possible object types.

In addition to a meta box being able to be added for a post, it can also be added for a comment or a link, or even nothing at all when on the Dashboard.

Props opr18, nikunj8866, soyebsalar01, westonruter.
See #64224.
Fixes #64251.

Note: See TracTickets for help on using tickets.