[wp-trac] [WordPress Trac] #46542: Passing wrong param to do_meta_boxes in dashboard.php
WordPress Trac
noreply at wordpress.org
Sat Mar 16 23:31:02 UTC 2019
#46542: Passing wrong param to do_meta_boxes in dashboard.php
--------------------------+-----------------------------
Reporter: killua99 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
The hook `do_meta_boxes` is been calling with wrong params in
dashboard.php
The line in dashboard.php are:
{{{#!php
<?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
<?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)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46542>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list