Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#46542 closed defect (bug) (fixed)

Passing wrong param to do_meta_boxes in dashboard.php

Reported by: killua99's profile killua99 Owned by: felipeelia's profile felipeelia
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.2
Component: Administration Keywords: has-patch
Focuses: Cc:


The hook do_meta_boxes is been calling with wrong params in dashboard.php

The line in dashboard.php are:

    /** This action is documented in wp-admin/includes/meta-boxes.php */
    do_action( 'do_meta_boxes', $screen->id, 'normal', '' );

The hook do_meta_boxes require that the third param to be a WP_Post object.

As the hook documentation said here:

If you write a hook that does require to be a WP_Post the third param and you navigate to dashboard you could get a PHP Fatal error.

Steps to reproduce:

Write in any active plugin these lines:

        add_action( 'do_meta_boxes', function ( string $post_type, string $context, \WP_Post $post ) {
            // Navigate to dashboard you will get an error since the 3rd param is an string.
            if ( $post instanceof \WP_Post ) {
                // Your code.
        }, 10, 3 );

Navigate to the dashboard.php

Expected result.

Normal dashboard page.

Actual result:

You get an PHP Fatal Error.


Description above

Possible solution:

1 - Write a special meta_box for dashboard
2 - Correct documentation that the third param might get an string on it (seems like dashboard.php is the only passing a string)

Attachments (1)

46542.diff (799 bytes) - added by felipeelia 4 years ago.

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Administration

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

4 years ago

#3 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 5.3

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

4 years ago

#5 @davidbaumwald
4 years ago

  • Keywords needs-patch added
  • Owner set to felipeelia
  • Status changed from new to assigned

4 years ago

#6 @felipeelia
4 years ago

  • Keywords has-patch added; needs-patch removed

#7 @SergeyBiryukov
4 years ago

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

In 46071:

Docs: Improve documentation for do_meta_boxes action.

Props felipeelia, killua99, SergeyBiryukov.
Fixes #46542.

Note: See TracTickets for help on using tickets.