Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#27328 closed enhancement (worksforme)

Conditional tags for wp-admin

Reported by: ericlewis's profile ericlewis Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:

Description

On the front-end, we have access to conditional tags, which allows us to check which page is being requested quite declarative, and elegant.

if ( is_page( 'about' ) ) { /* do something */ }
if ( is_post_type_archive( 'people' ) ) { /* do something else */ }

In wp-admin, we're not so well equipped. You have access to $hook_suffix and get_current_screen(), both of which would require writing some more, at times tricky to craft imperative conditionals.

Change History (5)

#1 @ericlewis
11 years ago

Some ideas:

is_post_type_list_screen() // true for a listings screen of any post type.
is_post_type_list_screen( 'post' ) // true for the posts listings screen.
is_edit_screen() // true for an edit screen of any post type.
is_edit_screen( 'post' ) // true for a post edit screen.
is_edit_screen( 13 ) // true for the edit screen of post with an ID of 13.
is_add_new_screen() // true for an add new screen.
is_add_new_screen( 'post' )
is_settings_page( 'tools' )
is_taxonomy_edit_screen()
is_taxonomy_edit_screen( 'tag' )

#2 @juliobox
11 years ago

Hello

In which cases do you need these functions, can you provide us some examples?
Thank you

#3 @nacin
11 years ago

The current screen object is pretty resilient for this. I'd rather not add new top-level functions:

$screen = get_current_screen();

if ( $screen->base === 'edit' )
if ( $screen->base === 'edit' && $screen->post_type === 'post' )
if ( $screen->base === 'post' )
if ( $screen->base === 'post' && $screen->post_type === 'post' )
if ( $screen->base === 'post' && $screen->action === 'add' )
if ( $screen->base === 'post' && $screen->post_type === 'post' && $screen->action === 'add' )
if ( $screen->id === 'tools' )
if ( $screen->base === 'edit-tags' && $screen->taxonomy === 'post_tag' )

#4 @ericlewis
11 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Sounds fair - closing out.

#5 @helen
11 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.