Changeset 21687
- Timestamp:
- 08/31/2012 05:16:46 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/screen.php
r21457 r21687 245 245 246 246 /** 247 * Which admin the screen is in. network | user | site | false 248 * 249 * @since 3.5.0 250 * @var string 251 * @access protected 252 */ 253 protected $in_admin; 254 255 /** 247 256 * Whether the screen is in the network admin. 248 257 * 249 * @since 3.3.0 258 * Deprecated. Use in_admin() instead. 259 * 260 * @since 3.3.0 261 * @deprecated 3.5.0 250 262 * @var bool 251 263 * @access public … … 256 268 * Whether the screen is in the user admin. 257 269 * 258 * @since 3.3.0 270 * Deprecated. Use in_admin() instead. 271 * 272 * @since 3.3.0 273 * @deprecated 3.5.0 259 274 * @var bool 260 275 * @access public … … 378 393 379 394 $post_type = $taxonomy = null; 380 $i s_network = $is_user= false;395 $in_admin = false; 381 396 $action = ''; 382 397 … … 403 418 if ( '-network' == substr( $id, -8 ) ) { 404 419 $id = substr( $id, 0, -8 ); 405 $i s_network = true;420 $in_admin = 'network'; 406 421 } elseif ( '-user' == substr( $id, -5 ) ) { 407 422 $id = substr( $id, 0, -5 ); 408 $i s_user = true;423 $in_admin = 'user'; 409 424 } 410 425 … … 420 435 } 421 436 } 437 438 if ( ! $in_admin ) 439 $in_admin = 'site'; 422 440 } else { 423 $is_network = is_network_admin(); 424 $is_user = is_user_admin(); 441 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) 442 $in_admin = 'network'; 443 elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) 444 $in_admin = 'user'; 445 else 446 $in_admin = 'site'; 425 447 } 426 448 427 449 if ( 'index' == $id ) 428 450 $id = 'dashboard'; 451 elseif ( 'front' == $id ) 452 $in_admin = false; 429 453 430 454 $base = $id; … … 477 501 } 478 502 479 if ( $is_network) {503 if ( 'network' == $in_admin ) { 480 504 $id .= '-network'; 481 505 $base .= '-network'; 482 } elseif ( $is_user) {506 } elseif ( 'user' == $in_admin ) { 483 507 $id .= '-user'; 484 508 $base .= '-user'; … … 498 522 $screen->post_type = (string) $post_type; 499 523 $screen->taxonomy = (string) $taxonomy; 500 $screen->is_user = $is_user; 501 $screen->is_network = $is_network; 524 $screen->is_user = ( 'user' == $in_admin ); 525 $screen->is_network = ( 'network' == $in_admin ); 526 $screen->in_admin = $in_admin; 502 527 503 528 self::$_registry[ $id ] = $screen; … … 527 552 */ 528 553 private function __construct() {} 554 555 /** 556 * Indicates whether the screen is in a particular admin 557 * 558 * @since 3.5.0 559 * 560 * @param string $admin The admin to check against (network | user | site). 561 * If empty any of the three admins will result in true. 562 * @return boolean True if the screen is in the indicated admin, false otherwise. 563 * 564 */ 565 public function in_admin( $admin = null ) { 566 if ( empty( $admin ) ) 567 return (bool) $this->in_admin; 568 569 return ( $admin == $this->in_admin ); 570 } 529 571 530 572 /** -
trunk/wp-includes/load.php
r21559 r21687 584 584 */ 585 585 function is_admin() { 586 if ( defined( 'WP_ADMIN' ) ) 586 if ( isset( $GLOBALS['current_screen'] ) ) 587 return $GLOBALS['current_screen']->in_admin(); 588 elseif ( defined( 'WP_ADMIN' ) ) 587 589 return WP_ADMIN; 590 588 591 return false; 589 592 } … … 600 603 */ 601 604 function is_blog_admin() { 602 if ( defined( 'WP_BLOG_ADMIN' ) ) 605 if ( isset( $GLOBALS['current_screen'] ) ) 606 return $GLOBALS['current_screen']->in_admin( 'blog' ); 607 elseif ( defined( 'WP_BLOG_ADMIN' ) ) 603 608 return WP_BLOG_ADMIN; 609 604 610 return false; 605 611 } … … 616 622 */ 617 623 function is_network_admin() { 618 if ( defined( 'WP_NETWORK_ADMIN' ) ) 624 if ( isset( $GLOBALS['current_screen'] ) ) 625 return $GLOBALS['current_screen']->in_admin( 'network' ); 626 elseif ( defined( 'WP_NETWORK_ADMIN' ) ) 619 627 return WP_NETWORK_ADMIN; 628 620 629 return false; 621 630 } … … 632 641 */ 633 642 function is_user_admin() { 634 if ( defined( 'WP_USER_ADMIN' ) ) 643 if ( isset( $GLOBALS['current_screen'] ) ) 644 return $GLOBALS['current_screen']->in_admin( 'user' ); 645 elseif ( defined( 'WP_USER_ADMIN' ) ) 635 646 return WP_USER_ADMIN; 647 636 648 return false; 637 649 }
Note: See TracChangeset
for help on using the changeset viewer.