WordPress.org

Make WordPress Core

Opened 2 days ago

#50036 new enhancement

WP_Screen action property not correct on post edit pages

Reported by: DarkoG Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: trunk
Component: General Keywords:
Focuses: administration Cc:

Description

Hello,

I noticed that the WP_Screen current screen action property is not properly initialized on the post edit pages regardless of the post type.

Dump of the WP_Screen object on Add New Post page (accessible via url /wp-admin/post-new.php):

object(WP_Screen)[817]
  public 'action' => string 'add' (length=3)
  public 'base' => string 'post' (length=4)
  private 'columns' => int 0
  public 'id' => string 'post' (length=4)
  protected 'in_admin' => string 'site' (length=4)
  public 'is_network' => boolean false
  public 'is_user' => boolean false
  public 'parent_base' => null
  public 'parent_file' => null
  public 'post_type' => string 'post' (length=4)
  public 'taxonomy' => string '' (length=0)
  private '_help_tabs' => 
    array (size=0)
      empty
  private '_help_sidebar' => string '' (length=0)
  private '_screen_reader_content' => 
    array (size=0)
      empty
  private '_options' => 
    array (size=0)
      empty
  private '_show_screen_options' => null
  private '_screen_settings' => null
  public 'is_block_editor' => boolean true

Dump of the WP_Screen object on Edit Post page (accessible via wp-admin/post.php?post=1&action=edit) :

/home/vagrant/code/general/wp.test/wp-content/plugins/wp-breaking-news/includes/class-wpbn-metabox.php:23:
object(WP_Screen)[818]
  public 'action' => string '' (length=0)
  public 'base' => string 'post' (length=4)
  private 'columns' => int 0
  public 'id' => string 'post' (length=4)
  protected 'in_admin' => string 'site' (length=4)
  public 'is_network' => boolean false
  public 'is_user' => boolean false
  public 'parent_base' => null
  public 'parent_file' => null
  public 'post_type' => string 'post' (length=4)
  public 'taxonomy' => string '' (length=0)
  private '_help_tabs' => 
    array (size=0)
      empty
  private '_help_sidebar' => string '' (length=0)
  private '_screen_reader_content' => 
    array (size=0)
      empty
  private '_options' => 
    array (size=0)
      empty
  private '_show_screen_options' => null
  private '_screen_settings' => null
  public 'is_block_editor' => boolean true

It will be much better if the action property is edit on this screen, it will make it easier to check if it edit page. Currently i have to do something like this

<?php
$screen  = get_current_screen();
$is_edit = $screen->id === 'post' && isset($_GET['action']) && $_GET['action'] === 'edit';

Expected behavior will be:

<?php
$screen  = get_current_screen();
$is_edit = $screen->id === 'post' && $screen->action === 'edit';

Change History (0)

Note: See TracTickets for help on using tickets.