WordPress.org

Make WordPress Core

Opened 19 months ago

Closed 10 months ago

Last modified 10 months ago

#50036 closed enhancement (maybelater)

WP_Screen action property not correct on post edit pages

Reported by: DarkoG Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.3
Component: Administration 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 (3)

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


10 months ago

#2 @peterwilsoncc
10 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
  • Version 5.5 deleted

Thanks for the ticket @DarkoG.

You are quite correct, the action name could be better if it was consistent on the new and edit posts page. Unfortunately it's been different for quite some time now so changing it could cause backward compatibility issues with theme and plugin developers.

get_current_screen()->base and a couple of other attributes are in common so you may be able to use those to avoid all the additional if conditions.

Due to the back-compatibility issues, I am going to close this off as wontfix.

#3 @SergeyBiryukov
10 months ago

  • Component changed from General to Administration
  • Resolution changed from wontfix to maybelater
  • Version set to 3.3

Hmm, I agree there could be backward compatibility concerns here, but I don't think that should block us from fixing the inconsistency. This doesn't seem much different from other older bugs fixed over the years. It might be a good candidate for a change early in the release cycle, with a dev note to give enough time for plugin authors to adapt.

Setting the Version field to the release where WP_Screen was introduced [18779] / #18690.

Changing the status to maybelater, feel free to reopen if there's still interest.

Note: See TracTickets for help on using tickets.