WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 3 months ago

#46542 closed defect (bug) (fixed)

Passing wrong param to do_meta_boxes in dashboard.php

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

Description

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

The line in dashboard.php are:

<?php
    /** 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: https://developer.wordpress.org/reference/hooks/do_meta_boxes/

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:

<?php
        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.

Cause:

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 3 months ago.

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
9 months ago

  • Component changed from General to Administration

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


8 months ago

#3 @SergeyBiryukov
8 months ago

  • Milestone changed from Awaiting Review to 5.3

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


3 months ago

#5 @davidbaumwald
3 months ago

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

@felipeelia
3 months ago

#6 @felipeelia
3 months ago

  • Keywords has-patch added; needs-patch removed

#7 @SergeyBiryukov
3 months 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.