#27328 closed enhancement (worksforme)
Conditional tags for wp-admin
Reported by: | 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)
#2
@
11 years ago
Hello
In which cases do you need these functions, can you provide us some examples?
Thank you
#3
@
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' )
Note: See
TracTickets for help on using
tickets.
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' )