| 1 | Index: wp-admin/includes/screen.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-admin/includes/screen.php (revision 21945) |
|---|
| 4 | +++ wp-admin/includes/screen.php (working copy) |
|---|
| 5 | @@ -237,6 +237,15 @@ |
|---|
| 6 | /** |
|---|
| 7 | * The unique ID of the screen. |
|---|
| 8 | * |
|---|
| 9 | + * @since 3.5.0 |
|---|
| 10 | + * @var string |
|---|
| 11 | + * @access public |
|---|
| 12 | + */ |
|---|
| 13 | + public $guid = ''; |
|---|
| 14 | + |
|---|
| 15 | + /** |
|---|
| 16 | + * The somewhat unique ID of the screen. |
|---|
| 17 | + * |
|---|
| 18 | * @since 3.3.0 |
|---|
| 19 | * @var string |
|---|
| 20 | * @access public |
|---|
| 21 | @@ -391,6 +400,73 @@ |
|---|
| 22 | if ( is_a( $hook_name, 'WP_Screen' ) ) |
|---|
| 23 | return $hook_name; |
|---|
| 24 | |
|---|
| 25 | + if ( false !== strpos( $hook_name, ':' ) ) |
|---|
| 26 | + $_screen = WP_Screen::get_from_guid( $hook_name ); |
|---|
| 27 | + else |
|---|
| 28 | + $_screen = WP_Screen::get_from_hook( $hook_name ); |
|---|
| 29 | + |
|---|
| 30 | + if ( isset( self::$_registry[ $_screen->id ] ) ) { |
|---|
| 31 | + $screen = self::$_registry[ $_screen->id ]; |
|---|
| 32 | + if ( $screen === get_current_screen() ) |
|---|
| 33 | + return $screen; |
|---|
| 34 | + unset( $_screen->id ); |
|---|
| 35 | + } else { |
|---|
| 36 | + $screen = new WP_Screen(); |
|---|
| 37 | + } |
|---|
| 38 | + |
|---|
| 39 | + foreach ( get_object_vars( $_screen ) as $property => $value ) { |
|---|
| 40 | + $screen->$property = $value; |
|---|
| 41 | + } |
|---|
| 42 | + |
|---|
| 43 | + self::$_registry[ $_screen->id ] = $screen; |
|---|
| 44 | + |
|---|
| 45 | + return $screen; |
|---|
| 46 | + } |
|---|
| 47 | + |
|---|
| 48 | + public static function get_from_guid( $guid ) { |
|---|
| 49 | + $screen = new stdClass; |
|---|
| 50 | + |
|---|
| 51 | + // admin:page:arg1:arg2:arg3:... |
|---|
| 52 | + $screen->guid = $guid; |
|---|
| 53 | + $bits = explode( ':', $guid ); |
|---|
| 54 | + $screen->in_admin = $bits[0]; |
|---|
| 55 | + $screen->is_user = ( 'user' == $in_admin ); |
|---|
| 56 | + $screen->is_network = ( 'network' == $in_admin ); |
|---|
| 57 | + $screen->base = $screen->id = $bits[1]; |
|---|
| 58 | + $screen->taxonomy = ''; |
|---|
| 59 | + $screen->post_type = ''; |
|---|
| 60 | + |
|---|
| 61 | + switch ( $screen->id ) { |
|---|
| 62 | + case 'edit-tags': |
|---|
| 63 | + $screen->taxonomy = $bits[2]; |
|---|
| 64 | + if ( ! empty( $bits[3] ) ) |
|---|
| 65 | + $screen->post_type = $bits[3]; |
|---|
| 66 | + $screen->id = 'edit-' . $screen->taxonomy; |
|---|
| 67 | + break; |
|---|
| 68 | + case 'edit': |
|---|
| 69 | + $screen->post_type = $bits[2]; |
|---|
| 70 | + $screen->id = 'edit-' . $screen->post_type; |
|---|
| 71 | + break; |
|---|
| 72 | + case 'post': |
|---|
| 73 | + $screen->post_type = $bits[2]; |
|---|
| 74 | + $screen->action = 'add'; |
|---|
| 75 | + break; |
|---|
| 76 | + case 'media': |
|---|
| 77 | + case 'link': |
|---|
| 78 | + case 'user': |
|---|
| 79 | + $screen->action = 'add'; |
|---|
| 80 | + break; |
|---|
| 81 | + } |
|---|
| 82 | + |
|---|
| 83 | + if ( 'site' != $screen->in_admin ) { |
|---|
| 84 | + $screen->base .= '-' . $screen->in_admin; |
|---|
| 85 | + $screen->id .= '-' . $screen->in_admin; |
|---|
| 86 | + } |
|---|
| 87 | + |
|---|
| 88 | + return $screen; |
|---|
| 89 | + } |
|---|
| 90 | + |
|---|
| 91 | + public static function get_from_hook( $hook_name = '' ) { |
|---|
| 92 | $post_type = $taxonomy = null; |
|---|
| 93 | $in_admin = false; |
|---|
| 94 | $action = ''; |
|---|
| 95 | @@ -437,7 +513,7 @@ |
|---|
| 96 | |
|---|
| 97 | if ( ! $in_admin ) |
|---|
| 98 | $in_admin = 'site'; |
|---|
| 99 | - } else { |
|---|
| 100 | + } elseif ( ! $in_admin ) { |
|---|
| 101 | if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) |
|---|
| 102 | $in_admin = 'network'; |
|---|
| 103 | elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) |
|---|
| 104 | @@ -508,15 +584,23 @@ |
|---|
| 105 | $base .= '-user'; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | - if ( isset( self::$_registry[ $id ] ) ) { |
|---|
| 109 | - $screen = self::$_registry[ $id ]; |
|---|
| 110 | - if ( $screen === get_current_screen() ) |
|---|
| 111 | - return $screen; |
|---|
| 112 | - } else { |
|---|
| 113 | - $screen = new WP_Screen(); |
|---|
| 114 | - $screen->id = $id; |
|---|
| 115 | + // @todo create guid |
|---|
| 116 | + $screen = new stdClass; |
|---|
| 117 | + $screen->guid = $in_admin . ':' . $base; |
|---|
| 118 | + |
|---|
| 119 | + switch ( $base ) { |
|---|
| 120 | + case 'edit-tags': |
|---|
| 121 | + $screen->guid .= ':' . $taxonomy; |
|---|
| 122 | + if ( $post_type ) |
|---|
| 123 | + $screen->guid .= ':' . $post_type; |
|---|
| 124 | + break; |
|---|
| 125 | + case 'edit': |
|---|
| 126 | + case 'post': |
|---|
| 127 | + $screen->guid .= ':' . $post_type; |
|---|
| 128 | + break; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | + $screen->id = $id; |
|---|
| 132 | $screen->base = $base; |
|---|
| 133 | $screen->action = $action; |
|---|
| 134 | $screen->post_type = (string) $post_type; |
|---|
| 135 | @@ -525,10 +609,8 @@ |
|---|
| 136 | $screen->is_network = ( 'network' == $in_admin ); |
|---|
| 137 | $screen->in_admin = $in_admin; |
|---|
| 138 | |
|---|
| 139 | - self::$_registry[ $id ] = $screen; |
|---|
| 140 | - |
|---|
| 141 | return $screen; |
|---|
| 142 | - } |
|---|
| 143 | + } |
|---|
| 144 | |
|---|
| 145 | /** |
|---|
| 146 | * Makes the screen object the current screen. |
|---|