Make convert_to_screen() more resilient. see #18785.

git-svn-id: https://develop.svn.wordpress.org/trunk@19063 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2011-10-25 06:54:23 +00:00
parent 261ee73e3d
commit 219bc246bc
1 changed files with 17 additions and 12 deletions

View File

@ -401,12 +401,23 @@ final class WP_Screen {
$action = $post_type = $taxonomy = '';
if ( $hook_name )
$id = $hook_name;
else
$id = $GLOBALS['hook_suffix'];
$id = str_replace( '.php', '', $id );
if ( in_array( substr( $id, -4 ), array( '-add', '-new' ) ) )
$action = 'add';
$id = str_replace( array( '-new', '-add' ), '', $id );
if ( $hook_name ) {
if ( '-network' == substr( $hook_name, -8 ) )
$hook_name = str_replace( '-network', '', $hook_name );
elseif ( '-user' == substr( $hook_name, -5 ) )
$hook_name = str_replace( '-user', '', $hook_name );
$id = sanitize_key( $hook_name );
if ( '-network' == substr( $id, -8 ) )
$id = str_replace( '-network', '', $id );
elseif ( '-user' == substr( $id, -5 ) )
$id = str_replace( '-user', '', $id );
$id = sanitize_key( $id );
if ( false !== strpos( $id, '-' ) ) {
list( $id, $second ) = explode( '-', $id, 2 );
if ( taxonomy_exists( $second ) ) {
@ -418,13 +429,7 @@ final class WP_Screen {
$id .= '-' . $second;
}
}
} else {
$id = $GLOBALS['hook_suffix'];
$id = str_replace( '.php', '', $id );
if ( in_array( substr( $id, -4 ), array( '-add', '-new' ) ) )
$action = 'add';
$id = str_replace( array( '-new', '-add' ), '', $id );
}
}
if ( 'index' == $id )
$id = 'dashboard';