Make WordPress Core

Opened 22 months ago

Closed 3 weeks ago

#26466 closed defect (bug) (worksforme)

class-wp-posts-list-table.php : prepare_items() - Is $post_type global?

Reported by: tivnet Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Posts, Post Types Keywords: reporter-feedback
Focuses: administration Cc:


I had a weird error on this line in wp-admin/edit.php:

add_screen_option( 'per_page', array( 'label' => $title, 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );

$post_type was as array, having 3 post types in it.

I was sorting posts by tag.

In attempt to trace this var (which is kind of global in edit.php), I came down to the prepare_items().

There, we have
$post_type = $this->screen->post_type;

and it's not clear to me whether it should be a local or global variable.

However, when I made it global:
global $avail_post_stati, $wp_query, $per_page, $mode, $post_type;
the error has gone.

The related change in code was 19/09/12 (ryan):
Revision 21914: Reduce reliance on global variables in the list tables. Allow passing a screen ID to the list tables so that ajax handlers can set the needed screen. Props nacin fixes #21871

Change History (5)

comment:1 @nofearinc22 months ago

  • Cc mario@… added
  • Component changed from General to Administration
  • Version changed from 3.7.1 to 3.5

comment:2 @tivnet21 months ago

Any resolution on this?

comment:3 @nacin20 months ago

  • Component changed from Administration to Posts, Post Types
  • Focuses administration added

comment:4 @jessepollak20 months ago

  • Keywords reporter-feedback added

Thanks for this bug report, sorry it took a little while to respond!

I have not been able to replicate this issue, are you still seeing it in 3.8 and/or trunk?

From my exploration, I've tracked $post_type through a few layers:

Ultimately, $post_type pretty much ends up being set to the screen->post_type. In my grepping, I don't see any instance where this would be set to an array (it's always explicitly set to string), but if it were to be set to an array, it could cause problems here.

I'd guess that this is an issue with a plugin messing with the screen post type.

If this bug still exists, could you give us the output of the error? Also, your a generalized version of your tags and posts would be valuable.

Thanks again for the report!

Last edited 20 months ago by jessepollak (previous) (diff)

comment:5 @wonderboymusic3 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

No reported feedback in 1.5 years. screen->post_type is the preferred way to access.

Note: See TracTickets for help on using tickets.