WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 2 months ago

#46542 new defect (bug)

Passing wrong param to do_meta_boxes in dashboard.php

Reported by: killua99 Owned by:
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.2
Component: Administration Keywords:
Focuses: Cc:

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)

Change History (3)

#1 @SergeyBiryukov
3 months ago

  • Component changed from General to Administration

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


2 months ago

#3 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.3
Note: See TracTickets for help on using tickets.