Changeset 19052
- Timestamp:
- 10/24/2011 06:34:08 PM (13 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/screen.php
r19051 r19052 114 114 * 115 115 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. 116 * @return object An object containing the safe screen name and id 117 */ 118 function convert_to_screen( $hook_suffix ) { 119 $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $hook_suffix); 120 121 if ( is_network_admin() ) 122 $screen .= '-network'; 123 elseif ( is_user_admin() ) 124 $screen .= '-user'; 125 126 $screen = (string) apply_filters( 'screen_meta_screen', $screen ); 127 $screen = (object) array( 'id' => $screen, 'base' => $screen ); 128 return $screen; 116 * @return WP_Screen Screen object. 117 */ 118 function convert_to_screen( $hook_name ) { 119 return WP_Screen::get( $hook_name ); 129 120 } 130 121 … … 202 193 $icon_id = $screen->base; 203 194 204 if ( ! empty( $screen->post_type ) &&'page' == $screen->post_type )195 if ( 'page' == $screen->post_type ) 205 196 $icon_id = 'edit-pages'; 206 197 207 if ( ! empty( $screen->post_type ))198 if ( $screen->post_type ) 208 199 $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen->post_type ); 209 200 } … … 234 225 * @uses $current_screen 235 226 * 236 * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. 227 * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, 228 * or an existing screen object. 237 229 */ 238 230 function set_current_screen( $hook_name = '' ) { 239 global $current_screen; 240 241 $current_screen = new WP_Screen( $hook_name ); 242 243 $current_screen = apply_filters('current_screen', $current_screen); 231 WP_Screen::get( $hook_name )->set_current_screen(); 244 232 } 245 233 … … 321 309 * The post type associated with the screen, if any. 322 310 * The 'edit.php?post_type=page' screen has a post type of 'page'. 311 * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'. 323 312 * 324 313 * @since 3.3.0 … … 344 333 * @access private 345 334 */ 346 private static$_help_tabs = array();335 private $_help_tabs = array(); 347 336 348 337 /** 349 * The help sidebar data associated with screen s, if any.338 * The help sidebar data associated with screen, if any. 350 339 * 351 340 * @since 3.3.0 … … 353 342 * @access private 354 343 */ 355 private static $_help_sidebar = array();344 private $_help_sidebar = ''; 356 345 357 346 /** … … 361 350 362 351 /** 363 * The screen options associated with screen s, if any.352 * The screen options associated with screen, if any. 364 353 * 365 354 * @since 3.3.0 … … 367 356 * @access private 368 357 */ 369 private static $_options = array(); 358 private $_options = array(); 359 360 /** 361 * The screen object registry. 362 * 363 * @since 3.3.0 364 * @var array 365 * @access private 366 */ 367 private static $_registry = array(); 370 368 371 369 /** … … 387 385 private $_screen_settings; 388 386 387 /** 388 * Fetches a screen object. 389 * 390 * @since 3.3.0 391 * @access public 392 * 393 * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. 394 * Defaults to the current $hook_suffix global. 395 * @return WP_Screen Screen object. 396 */ 397 public function get( $hook_name = '' ) { 398 399 if ( is_a( $hook_name, 'WP_Screen' ) ) 400 return $hook_name; 401 402 $action = $post_type = $taxonomy = ''; 403 404 if ( $hook_name ) { 405 if ( '-network' == substr( $hook_name, -8 ) ) 406 $hook_name = str_replace( '-network', '', $hook_name ); 407 elseif ( '-user' == substr( $hook_name, -5 ) ) 408 $hook_name = str_replace( '-user', '', $hook_name ); 409 $id = sanitize_key( $hook_name ); 410 if ( false !== strpos( $id, '-' ) ) { 411 list( $id, $second ) = explode( '-', $id, 2 ); 412 if ( taxonomy_exists( $second ) ) { 413 $id = 'edit-tags'; 414 $taxonomy = $second; 415 } elseif ( post_type_exists( $second ) ) { 416 $post_type = $second; 417 } else { 418 $id .= '-' . $second; 419 } 420 } 421 } else { 422 $id = $GLOBALS['hook_suffix']; 423 $id = str_replace( '.php', '', $id ); 424 if ( in_array( substr( $id, -4 ), array( '-add', '-new' ) ) ) 425 $action = 'add'; 426 $id = str_replace( array( '-new', '-add' ), '', $id ); 427 } 428 429 if ( 'index' == $id ) 430 $id = 'dashboard'; 431 432 $base = $id; 433 434 // If this is the current screen, see if we can be more accurate for post types and taxonomies. 435 if ( ! $hook_name ) { 436 switch ( $base ) { 437 case 'post' : 438 if ( isset( $_GET['post'] ) ) 439 $post_id = (int) $_GET['post']; 440 elseif ( isset( $_POST['post_ID'] ) ) 441 $post_id = (int) $_POST['post_ID']; 442 else 443 $post_id = 0; 444 445 if ( $post_id ) { 446 $post = get_post( $post_id ); 447 if ( $post ) 448 $post_type = $post->post_type; 449 } elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) ) { 450 $post_type = $_GET['post_type']; 451 } elseif ( $action == 'add' && isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) { 452 $post_type = $_GET['post_type']; 453 } 454 break; 455 case 'edit' : 456 if ( isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) ) 457 $post_type = $_GET['post_type']; 458 break; 459 case 'edit-tags' : 460 if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) 461 $taxonomy = $_REQUEST['taxonomy']; 462 if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) 463 $post_type = $_REQUEST['post_type']; 464 else 465 $post_type = 'post'; 466 break; 467 } 468 } 469 470 switch ( $base ) { 471 case 'post' : 472 if ( ! $post_type ) 473 $post_type = 'post'; 474 $id = $post_type; 475 break; 476 case 'edit' : 477 if ( ! $post_type ) 478 $post_type = 'post'; 479 $id .= '-' . $post_type; 480 break; 481 case 'edit-tags' : 482 if ( ! $taxonomy ) 483 $taxonomy = 'post_tag'; 484 $id = 'edit-' . $taxonomy; 485 break; 486 } 487 488 if ( is_network_admin() ) { 489 $id .= '-network'; 490 $base .= '-network'; 491 } elseif ( is_user_admin() ) { 492 $id .= '-user'; 493 $base .= '-user'; 494 } 495 496 if ( isset( self::$_registry[ $id ] ) ) 497 return self::$_registry[ $id ]; 498 499 $screen = new WP_Screen(); 500 $screen->id = $id; 501 $screen->base = $base; 502 $screen->action = $action; 503 $screen->post_type = $post_type; 504 $screen->taxonomy = $taxonomy; 505 $screen->is_user = is_user_admin(); 506 $screen->is_network = is_network_admin(); 507 508 self::$_registry[ $id ] = $screen; 509 510 return $screen; 511 } 512 513 /** 514 * Makes the screen object the current screen. 515 * 516 * @see set_current_screen() 517 * @since 3.3.0 518 */ 519 function set_current_screen() { 520 global $current_screen, $taxnow, $typenow; 521 $current_screen = $this; 522 $taxnow = $this->taxonomy; 523 $typenow = $this->post_type; 524 $current_screen = apply_filters( 'current_screen', $current_screen ); 525 } 526 389 527 /** 390 528 * Constructor 391 529 * 392 530 * @since 3.3.0 393 * 394 * @param string $id A screen id. If empty, the $hook_suffix global is used to derive the ID. 395 */ 396 public function __construct( $id = '' ) { 397 global $hook_suffix, $typenow, $taxnow; 398 399 $action = ''; 400 401 if ( empty( $id ) ) { 402 $screen = $hook_suffix; 403 $screen = str_replace('.php', '', $screen); 404 if ( preg_match('/-add|-new$/', $screen) ) 405 $action = 'add'; 406 $screen = str_replace('-new', '', $screen); 407 $screen = str_replace('-add', '', $screen); 408 $this->id = $this->base = $screen; 409 } else { 410 $id = sanitize_key( $id ); 411 if ( false !== strpos($id, '-') ) { 412 list( $id, $typenow ) = explode('-', $id, 2); 413 if ( taxonomy_exists( $typenow ) ) { 414 $id = 'edit-tags'; 415 $taxnow = $typenow; 416 $typenow = ''; 417 } 418 } 419 $this->id = $this->base = $id; 420 } 421 422 $this->action = $action; 423 424 // Map index to dashboard 425 if ( 'index' == $this->base ) 426 $this->base = 'dashboard'; 427 if ( 'index' == $this->id ) 428 $this->id = 'dashboard'; 429 430 if ( 'edit' == $this->id ) { 431 if ( empty($typenow) ) 432 $typenow = 'post'; 433 $this->id .= '-' . $typenow; 434 $this->post_type = $typenow; 435 } elseif ( 'post' == $this->id ) { 436 if ( empty($typenow) ) 437 $typenow = 'post'; 438 $this->id = $typenow; 439 $this->post_type = $typenow; 440 } elseif ( 'edit-tags' == $this->id ) { 441 if ( empty($taxnow) ) 442 $taxnow = 'post_tag'; 443 $this->id = 'edit-' . $taxnow; 444 $this->taxonomy = $taxnow; 445 } 446 447 $this->is_network = is_network_admin(); 448 $this->is_user = is_user_admin(); 449 450 if ( $this->is_network ) { 451 $this->base .= '-network'; 452 $this->id .= '-network'; 453 } elseif ( $this->is_user ) { 454 $this->base .= '-user'; 455 $this->id .= '-user'; 456 } 457 458 if ( ! isset( self::$_help_tabs[ $this->id ] ) ) 459 self::$_help_tabs[ $this->id ] = array(); 460 if ( ! isset( self::$_help_sidebar[ $this->id ] ) ) 461 self::$_help_sidebar[ $this->id ] = ''; 462 if ( ! isset( self::$_options[ $this->id ] ) ) 463 self::$_options[ $this->id ] = array(); 464 } 531 * @access private 532 */ 533 private function __construct() {} 465 534 466 535 /** … … 502 571 */ 503 572 public function add_option( $option, $args = array() ) { 504 self::$_options[ $this->id ][ $option ] = $args;573 $this->_options[ $option ] = $args; 505 574 } 506 575 … … 513 582 */ 514 583 public function get_option( $option, $key = false ) { 515 if ( ! isset( self::$_options[ $this->id ][ $option ] ) )584 if ( ! isset( $this->_options[ $option ] ) ) 516 585 return null; 517 586 if ( $key ) { 518 if ( isset( self::$_options[ $this->id ][ $option ][ $key ] ) )519 return self::$_options[ $this->id ][ $option ][ $key ];587 if ( isset( $this->_options[ $option ][ $key ] ) ) 588 return $this->_options[ $option ][ $key ]; 520 589 return null; 521 590 } 522 return self::$_options[ $this->id ][ $option ];591 return $this->_options[ $option ]; 523 592 } 524 593 … … 551 620 return; 552 621 553 self::$_help_tabs[ $this->id ][] = $args;622 $this->_help_tabs[] = $args; 554 623 } 555 624 … … 563 632 */ 564 633 public function add_help_sidebar( $content ) { 565 self::$_help_sidebar[ $this->id ]= $content;634 $this->_help_sidebar = $content; 566 635 } 567 636 … … 578 647 self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this ); 579 648 580 if ( isset( self::$_old_compat_help[ $this->id ] ) || empty( self::$_help_tabs[ $this->id ]) ) {649 if ( isset( self::$_old_compat_help[ $this->id ] ) || empty($this->_help_tabs ) ) { 581 650 // Call old contextual_help filter. 582 651 if ( isset( self::$_old_compat_help[ $this->id ] ) ) … … 604 673 'callback' => array( $this, 'render_screen_options' ), 605 674 ) ); 606 $_options_tab = array_pop( self::$_help_tabs[ $this->id ]);607 array_unshift( self::$_help_tabs[ $this->id ], $_options_tab );675 $_options_tab = array_pop( $this->_help_tabs ); 676 array_unshift( $this->_help_tabs, $_options_tab ); 608 677 } 609 678 … … 615 684 <div class="contextual-help-tabs"> 616 685 <ul> 617 <?php foreach ( self::$_help_tabs[ $this->id ]as $i => $tab ):686 <?php foreach ( $this->_help_tabs as $i => $tab ): 618 687 $link_id = "tab-link-{$tab['id']}"; 619 688 $panel_id = "tab-panel-{$tab['id']}"; … … 630 699 </div> 631 700 632 <?php if ( ! empty( self::$_help_sidebar[ $this->id ]) ) : ?>701 <?php if ( ! empty( $this->_help_sidebar ) ) : ?> 633 702 <div class="contextual-help-sidebar"> 634 <?php echo self::$ _help_sidebar[ $this->id ]; ?>703 <?php echo self::$this->_help_sidebar; ?> 635 704 </div> 636 705 <?php endif; ?> 637 706 638 707 <div class="contextual-help-tabs-wrap"> 639 <?php foreach ( self::$_help_tabs[ $this->id ]as $i => $tab ):708 <?php foreach ( $this->_help_tabs as $i => $tab ): 640 709 $panel_id = "tab-panel-{$tab['id']}"; 641 710 $classes = ( $i == 0 ) ? 'active' : ''; … … 678 747 } 679 748 680 if ( $this->_screen_settings || self::$_options[ $this->id ])749 if ( $this->_screen_settings || $this->_options ) 681 750 $show_screen = true; 682 751 -
trunk/wp-admin/post.php
r18796 r19052 17 17 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder')); 18 18 19 if ( isset($_GET['post']) ) 20 $post_id = (int) $_GET['post']; 21 elseif ( isset($_POST['post_ID']) ) 22 $post_id = (int) $_POST['post_ID']; 23 else 24 $post_id = 0; 25 $post_ID = $post_id; 26 $post = null; 27 $post_type_object = null; 28 $post_type = null; 29 if ( $post_id ) { 30 $post = get_post($post_id); 31 if ( $post ) { 32 $post_type_object = get_post_type_object($post->post_type); 33 if ( $post_type_object ) { 34 $post_type = $post->post_type; 35 $current_screen->post_type = $post->post_type; 36 $current_screen->id = $current_screen->post_type; 37 } 38 } 39 } elseif ( isset($_POST['post_type']) ) { 40 $post_type_object = get_post_type_object($_POST['post_type']); 41 if ( $post_type_object ) { 42 $post_type = $post_type_object->name; 43 $current_screen->post_type = $post_type; 44 $current_screen->id = $current_screen->post_type; 45 } 19 if ( isset( $_GET['post'] ) ) 20 $post_id = $post_ID = (int) $_GET['post']; 21 elseif ( isset( $_POST['post_ID'] ) ) 22 $post_id = $post_ID = (int) $_POST['post_ID']; 23 else 24 $post_id = $post_ID = 0; 25 26 $post = $post_type = $post_type_object = null; 27 28 if ( $post_id ) 29 $post = get_post( $post_id ); 30 31 if ( $post ) { 32 $post_type = $post->post_type; 33 $post_type_object = get_post_type_object( $post_type ); 46 34 } 47 35
Note: See TracChangeset
for help on using the changeset viewer.