Make WordPress Core


Ignore:
Timestamp:
09/26/2011 09:32:10 PM (15 years ago)
Author:
nacin
Message:

Move WP_Screen and friends (15 functions) into admin/includes/screen.php. see #18690.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r18781 r18782  
    220220                echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
    221221        }
    222 }
    223 
    224 /**
    225  * Get the column headers for a screen
    226  *
    227  * @since 2.7.0
    228  *
    229  * @param string|object $screen The screen you want the headers for
    230  * @return array Containing the headers in the format id => UI String
    231  */
    232 function get_column_headers( $screen ) {
    233         if ( is_string( $screen ) )
    234                 $screen = convert_to_screen( $screen );
    235 
    236         global $_wp_column_headers;
    237 
    238         if ( !isset( $_wp_column_headers[ $screen->id ] ) ) {
    239                 $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
    240         }
    241 
    242         return $_wp_column_headers[ $screen->id ];
    243 }
    244 
    245 /**
    246  * Get a list of hidden columns.
    247  *
    248  * @since 2.7.0
    249  *
    250  * @param string|object $screen The screen you want the hidden columns for
    251  * @return array
    252  */
    253 function get_hidden_columns( $screen ) {
    254         if ( is_string( $screen ) )
    255                 $screen = convert_to_screen( $screen );
    256 
    257         return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
    258222}
    259223
     
    1007971
    1008972/**
    1009  * {@internal Missing Short Description}}
    1010  *
    1011  * @since 2.7.0
    1012  *
    1013  * @param unknown_type $screen
    1014  */
    1015 function meta_box_prefs($screen) {
    1016         global $wp_meta_boxes;
    1017 
    1018         if ( is_string($screen) )
    1019                 $screen = convert_to_screen($screen);
    1020 
    1021         if ( empty($wp_meta_boxes[$screen->id]) )
    1022                 return;
    1023 
    1024         $hidden = get_hidden_meta_boxes($screen);
    1025 
    1026         foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
    1027                 foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
    1028                         foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
    1029                                 if ( false == $box || ! $box['title'] )
    1030                                         continue;
    1031                                 // Submit box cannot be hidden
    1032                                 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
    1033                                         continue;
    1034                                 $box_id = $box['id'];
    1035                                 echo '<label for="' . $box_id . '-hide">';
    1036                                 echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
    1037                                 echo "{$box['title']}</label>\n";
    1038                         }
    1039                 }
    1040         }
    1041 }
    1042 
    1043 /**
    1044  * Get Hidden Meta Boxes
    1045  *
    1046  * @since 2.7.0
    1047  *
    1048  * @param string|object $screen Screen identifier
    1049  * @return array Hidden Meta Boxes
    1050  */
    1051 function get_hidden_meta_boxes( $screen ) {
    1052         if ( is_string( $screen ) )
    1053                 $screen = convert_to_screen( $screen );
    1054 
    1055         $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
    1056 
    1057         // Hide slug boxes by default
    1058         if ( !is_array( $hidden ) ) {
    1059                 if ( 'post' == $screen->base || 'page' == $screen->base )
    1060                         $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
    1061                 else
    1062                         $hidden = array( 'slugdiv' );
    1063                 $hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
    1064         }
    1065 
    1066         return $hidden;
    1067 }
    1068 
    1069 /**
    1070973 * Add a new section to a settings page.
    1071974 *
     
    13951298        global $post;
    13961299        if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
    1397 }
    1398 
    1399 /**
    1400  * {@internal Missing Short Description}}
    1401  *
    1402  * @since 2.7.0
    1403  */
    1404 function favorite_actions( $screen = null ) {
    1405         $default_action = false;
    1406 
    1407         if ( is_string($screen) )
    1408                 $screen = convert_to_screen($screen);
    1409 
    1410         if ( $screen->is_user )
    1411                 return;
    1412 
    1413         if ( isset($screen->post_type) ) {
    1414                 $post_type_object = get_post_type_object($screen->post_type);
    1415                 if ( 'add' != $screen->action )
    1416                         $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts));
    1417                 else
    1418                         $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
    1419         }
    1420 
    1421         if ( !$default_action ) {
    1422                 if ( $screen->is_network ) {
    1423                         $default_action = array('sites.php' => array( __('Sites'), 'manage_sites'));
    1424                 } else {
    1425                         switch ( $screen->id ) {
    1426                                 case 'upload':
    1427                                         $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
    1428                                         break;
    1429                                 case 'media':
    1430                                         $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
    1431                                         break;
    1432                                 case 'link-manager':
    1433                                 case 'link':
    1434                                         if ( 'add' != $screen->action )
    1435                                                 $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
    1436                                         else
    1437                                                 $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
    1438                                         break;
    1439                                 case 'users':
    1440                                         $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
    1441                                         break;
    1442                                 case 'user':
    1443                                         $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
    1444                                         break;
    1445                                 case 'plugins':
    1446                                         $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
    1447                                         break;
    1448                                 case 'plugin-install':
    1449                                         $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
    1450                                         break;
    1451                                 case 'themes':
    1452                                         $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
    1453                                         break;
    1454                                 case 'theme-install':
    1455                                         $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
    1456                                         break;
    1457                                 default:
    1458                                         $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
    1459                                         break;
    1460                         }
    1461                 }
    1462         }
    1463 
    1464         if ( !$screen->is_network ) {
    1465                 $actions = array(
    1466                         'post-new.php' => array(__('New Post'), 'edit_posts'),
    1467                         'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
    1468                         'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
    1469                         'media-new.php' => array(__('Upload'), 'upload_files'),
    1470                         'edit-comments.php' => array(__('Comments'), 'moderate_comments')
    1471                         );
    1472         } else {
    1473                 $actions = array(
    1474                         'sites.php' => array( __('Sites'), 'manage_sites'),
    1475                         'users.php' => array( __('Users'), 'manage_network_users')
    1476                 );
    1477         }
    1478 
    1479         $default_key = array_keys($default_action);
    1480         $default_key = $default_key[0];
    1481         if ( isset($actions[$default_key]) )
    1482                 unset($actions[$default_key]);
    1483         $actions = array_merge($default_action, $actions);
    1484         $actions = apply_filters( 'favorite_actions', $actions, $screen );
    1485 
    1486         $allowed_actions = array();
    1487         foreach ( $actions as $action => $data ) {
    1488                 if ( current_user_can($data[1]) )
    1489                         $allowed_actions[$action] = $data[0];
    1490         }
    1491 
    1492         if ( empty($allowed_actions) )
    1493                 return;
    1494 
    1495         $first = array_keys($allowed_actions);
    1496         $first = $first[0];
    1497         echo '<div id="favorite-actions">';
    1498         echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
    1499         echo '<div id="favorite-inside">';
    1500 
    1501         array_shift($allowed_actions);
    1502 
    1503         foreach ( $allowed_actions as $action => $label) {
    1504                 echo "<div class='favorite-action'><a href='$action'>";
    1505                 echo $label;
    1506                 echo "</a></div>\n";
    1507         }
    1508         echo "</div></div>\n";
    15091300}
    15101301
     
    16891480
    16901481/**
    1691  * Convert a screen string to a screen object
    1692  *
    1693  * @since 3.0.0
    1694  *
    1695  * @param string $screen The name of the screen
    1696  * @return object An object containing the safe screen name and id
    1697  */
    1698 function convert_to_screen( $screen ) {
    1699         $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
    1700 
    1701         if ( is_network_admin() )
    1702                 $screen .= '-network';
    1703         elseif ( is_user_admin() )
    1704                 $screen .= '-user';
    1705 
    1706         $screen = (string) apply_filters( 'screen_meta_screen', $screen );
    1707         $screen = (object) array('id' => $screen, 'base' => $screen);
    1708         return $screen;
    1709 }
    1710 
    1711 function screen_meta($screen) {
    1712         global $wp_meta_boxes, $_wp_contextual_help, $wp_list_table, $wp_current_screen_options;
    1713 
    1714         if ( is_string($screen) )
    1715                 $screen = convert_to_screen($screen);
    1716 
    1717         $columns = get_column_headers( $screen );
    1718         $hidden = get_hidden_columns( $screen );
    1719 
    1720         $meta_screens = array('index' => 'dashboard');
    1721 
    1722         if ( isset($meta_screens[$screen->id]) ) {
    1723                 $screen->id = $meta_screens[$screen->id];
    1724                 $screen->base = $screen->id;
    1725         }
    1726 
    1727         $show_screen = false;
    1728         if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) )
    1729                 $show_screen = true;
    1730 
    1731         $screen_options = screen_options($screen);
    1732         if ( $screen_options )
    1733                 $show_screen = true;
    1734 
    1735         if ( !isset($_wp_contextual_help) )
    1736                 $_wp_contextual_help = array();
    1737 
    1738         $settings = apply_filters('screen_settings', '', $screen);
    1739 
    1740         switch ( $screen->id ) {
    1741                 case 'widgets':
    1742                         $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
    1743                         $show_screen = true;
    1744                         break;
    1745         }
    1746         if ( ! empty( $settings ) )
    1747                 $show_screen = true;
    1748 
    1749         if ( !empty($wp_current_screen_options) )
    1750                 $show_screen = true;
    1751 
    1752         $show_screen = apply_filters('screen_options_show_screen', $show_screen, $screen);
    1753 
    1754         // If we have screen options, add the menu to the admin bar.
    1755         if ( $show_screen )
    1756                 add_action( 'admin_bar_menu', 'wp_admin_bar_screen_options_menu', 80 );
    1757 
    1758 
    1759 ?>
    1760 <div id="screen-meta">
    1761 <?php if ( $show_screen ) : ?>
    1762 <div id="screen-options-wrap" class="hidden">
    1763         <form id="adv-settings" action="" method="post">
    1764         <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
    1765                 <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
    1766                 <div class="metabox-prefs">
    1767                         <?php meta_box_prefs($screen); ?>
    1768                         <br class="clear" />
    1769                 </div>
    1770                 <?php endif;
    1771                 if ( ! empty($columns) ) : ?>
    1772                 <h5><?php echo ( isset( $columns['_title'] ) ?  $columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
    1773                 <div class="metabox-prefs">
    1774 <?php
    1775         $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
    1776 
    1777         foreach ( $columns as $column => $title ) {
    1778                 // Can't hide these for they are special
    1779                 if ( in_array( $column, $special ) )
    1780                         continue;
    1781                 if ( empty( $title ) )
    1782                         continue;
    1783 
    1784                 if ( 'comments' == $column )
    1785                         $title = __( 'Comments' );
    1786                 $id = "$column-hide";
    1787                 echo '<label for="' . $id . '">';
    1788                 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
    1789                 echo "$title</label>\n";
    1790         }
    1791 ?>
    1792                         <br class="clear" />
    1793                 </div>
    1794         <?php endif;
    1795         echo screen_layout($screen);
    1796 
    1797         if ( !empty( $screen_options ) ) {
    1798                 ?>
    1799                 <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
    1800                 <?php
    1801         }
    1802 
    1803         echo $screen_options;
    1804         echo $settings; ?>
    1805         <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
    1806         </form>
    1807 </div>
    1808 
    1809 <?php endif; // $show_screen
    1810 
    1811         $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
    1812         ?>
    1813         <div id="contextual-help-wrap" class="hidden">
    1814         <?php
    1815         $contextual_help = '';
    1816         if ( isset($_wp_contextual_help[$screen->id]) && is_array($_wp_contextual_help[$screen->id]) ) {
    1817                 $contextual_help .= '<div class="metabox-prefs">' . "\n";
    1818 
    1819                 /*
    1820                  * Loop through ['contextual-help-tabs']
    1821                  *   - It's a nested array where $key=>$value >> $title=>$content
    1822                  * Has no output so can only loop the array once
    1823                  */
    1824                 $contextual_help_tabs = ''; // store looped content for later
    1825                 $contextual_help_panels = ''; // store looped content for later
    1826 
    1827                 $tab_active = true;
    1828 
    1829                 foreach ( $_wp_contextual_help[$screen->id]['tabs'] as $tab ) {
    1830                         $tab_slug = sanitize_html_class( $tab[ 0 ] );
    1831                         $contextual_help_tabs .= '<li class="tab-' . $tab_slug . ( ($tab_active) ? ' active' : '' ) . '">';
    1832                         $contextual_help_tabs .= '<a href="#' . $tab_slug . '">' . $tab[1] . '</a>';
    1833                         $contextual_help_tabs .= '</li>' ."\n";
    1834                        
    1835                         $contextual_help_panels .= '<div id="' . $tab_slug . '" class="help-tab-content' . ( ($tab_active) ? ' active' : '' ) . '">';
    1836                         $contextual_help_panels .= $tab[2];
    1837                         $contextual_help_panels .= "</div>\n";
    1838 
    1839                         $tab_active = false;
    1840                 }
    1841 
    1842                 // Start output from loop: Tabbed help content
    1843                 $contextual_help .= '<ul class="contextual-help-tabs">' . "\n";
    1844                 $contextual_help .= $contextual_help_tabs;
    1845                 $contextual_help .= '</ul>' ."\n";
    1846                 $contextual_help .= '<div class="contextual-help-tabs-wrap">' . "\n";
    1847                 $contextual_help .= $contextual_help_panels;
    1848                 $contextual_help .= "</div>\n";
    1849                 // END: Tabbed help content
    1850 
    1851                 // Sidebar to right of tabs
    1852                 $contextual_help .= '<div class="contextual-help-links">' . "\n";
    1853                 $contextual_help .= $_wp_contextual_help[$screen->id]['sidebar'];
    1854                 $contextual_help .= "</div>\n";
    1855                
    1856                 $contextual_help .= "</div>\n"; // end metabox
    1857                
    1858         } elseif ( isset($_wp_contextual_help[$screen->id]) ) {
    1859                 $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n";
    1860         } else {
    1861                 $contextual_help .= '<div class="metabox-prefs">';
    1862                 $default_help  = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
    1863                 $default_help .= '<br />';
    1864                 $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
    1865                 $contextual_help .= apply_filters('default_contextual_help', $default_help);
    1866                 $contextual_help .= '</div>' . "\n";
    1867         }
    1868 
    1869         echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
    1870         ?>
    1871         </div>
    1872 
    1873 </div> <?php // #screen-meta
    1874 }
    1875 
    1876 /**
    1877  * Add contextual help text for a page
    1878  *
    1879  * The array $help takes the following format:
    1880  *      array( 'contextual-help-tabs'   => array( $tab1_title => $tab1_value [, $tab2_title => $tab2_value, ...] ),
    1881  *              'contextual-help-links' => $help_links_as_string )
    1882  *
    1883  * For backwards compatability, a string is also accepted.
    1884  *
    1885  * @since 2.7.0
    1886  *
    1887  * @param string        $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
    1888  * @param array|string  $help   Creates tabs & links columns within help text in array.
    1889  *
    1890  */
    1891 function add_contextual_help($screen, $help) {
    1892         global $_wp_contextual_help;
    1893 
    1894         if ( is_string($screen) )
    1895                 $screen = convert_to_screen($screen);
    1896 
    1897         if ( !isset($_wp_contextual_help) )
    1898                 $_wp_contextual_help = array();
    1899 
    1900         $_wp_contextual_help[$screen->id] = $help;
    1901 }
    1902 
    1903 function screen_layout($screen) {
    1904         global $screen_layout_columns, $wp_current_screen_options;
    1905 
    1906         if ( is_string($screen) )
    1907                 $screen = convert_to_screen($screen);
    1908 
    1909         // Back compat for plugins using the filter instead of add_screen_option()
    1910         $columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen);
    1911         if ( !empty($columns) && isset($columns[$screen->id]) )
    1912                 add_screen_option('layout_columns', array('max' => $columns[$screen->id]) );
    1913 
    1914         if ( !isset($wp_current_screen_options['layout_columns']) ) {
    1915                 $screen_layout_columns = 0;
    1916                 return '';
    1917         }
    1918 
    1919         $screen_layout_columns = get_user_option("screen_layout_$screen->id");
    1920         $num = $wp_current_screen_options['layout_columns']['max'];
    1921 
    1922         if ( ! $screen_layout_columns ) {
    1923                 if ( isset($wp_current_screen_options['layout_columns']['default']) )
    1924                         $screen_layout_columns = $wp_current_screen_options['layout_columns']['default'];
    1925                 else
    1926                         $screen_layout_columns = 'auto';
    1927         }
    1928 
    1929         $i = 1;
    1930         $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
    1931         while ( $i <= $num ) {
    1932                 $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
    1933                 ++$i;
    1934         }
    1935         $return .= "<label><input type='radio' id='wp_auto_columns' name='screen_columns' value='auto'" . ( ($screen_layout_columns == 'auto') ? " checked='checked'" : "" ) . " />" . __('auto') . "</label>\n";
    1936         $return .= "</div>\n";
    1937         return $return;
    1938 }
    1939 
    1940 /**
    1941  * Register and configure an admin screen option
    1942  *
    1943  * @since 3.1.0
    1944  *
    1945  * @param string $option An option name.
    1946  * @param mixed $args Option dependent arguments
    1947  * @return void
    1948  */
    1949 function add_screen_option( $option, $args = array() ) {
    1950         global $wp_current_screen_options;
    1951 
    1952         if ( !isset($wp_current_screen_options) )
    1953                 $wp_current_screen_options = array();
    1954 
    1955         $wp_current_screen_options[$option] = $args;
    1956 }
    1957 
    1958 function screen_options($screen) {
    1959         global $wp_current_screen_options;
    1960 
    1961         if ( is_string($screen) )
    1962                 $screen = convert_to_screen($screen);
    1963 
    1964         if ( !isset($wp_current_screen_options['per_page']) )
    1965                 return '';
    1966 
    1967         $per_page_label = $wp_current_screen_options['per_page']['label'];
    1968 
    1969         if ( empty($wp_current_screen_options['per_page']['option']) ) {
    1970                 $option = str_replace( '-', '_', "{$screen->id}_per_page" );
    1971         } else {
    1972                 $option = $wp_current_screen_options['per_page']['option'];
    1973         }
    1974 
    1975         $per_page = (int) get_user_option( $option );
    1976         if ( empty( $per_page ) || $per_page < 1 ) {
    1977                 if ( isset($wp_current_screen_options['per_page']['default']) )
    1978                         $per_page = $wp_current_screen_options['per_page']['default'];
    1979                 else
    1980                         $per_page = 20;
    1981         }
    1982 
    1983         if ( 'edit_comments_per_page' == $option )
    1984                 $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
    1985         elseif ( 'categories_per_page' == $option )
    1986                 $per_page = apply_filters( 'edit_categories_per_page', $per_page );
    1987         else
    1988                 $per_page = apply_filters( $option, $per_page );
    1989 
    1990         // Back compat
    1991         if ( isset( $screen->post_type ) )
    1992                 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $screen->post_type );
    1993 
    1994         $return = "<div class='screen-options'>\n";
    1995         if ( !empty($per_page_label) )
    1996                 $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n";
    1997         $return .= get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false );
    1998         $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
    1999         $return .= "</div>\n";
    2000         return $return;
    2001 }
    2002 
    2003 function screen_icon( $screen = '' ) {
    2004         echo get_screen_icon( $screen );
    2005 }
    2006 
    2007 function get_screen_icon( $screen = '' ) {
    2008         global $current_screen, $typenow;
    2009 
    2010         if ( empty($screen) )
    2011                 $screen = $current_screen;
    2012         elseif ( is_string($screen) )
    2013                 $name = $screen;
    2014 
    2015         $class = 'icon32';
    2016 
    2017         if ( empty($name) ) {
    2018                 if ( !empty($screen->parent_base) )
    2019                         $name = $screen->parent_base;
    2020                 else
    2021                         $name = $screen->base;
    2022 
    2023                 if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
    2024                         $name = 'edit-pages';
    2025 
    2026                 $post_type = '';
    2027                 if ( isset( $screen->post_type ) )
    2028                         $post_type = $screen->post_type;
    2029                 elseif ( $current_screen == $screen )
    2030                         $post_type = $typenow;
    2031                 if ( $post_type )
    2032                         $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
    2033         }
    2034 
    2035         return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>';
    2036 }
    2037 
    2038 /**
    20391482 * Test support for compressing JavaScript from PHP
    20401483 *
     
    20991542        </script>
    21001543<?php
    2101 }
    2102 
    2103 /**
    2104  *  Get the current screen object
    2105  *
    2106  *  @since 3.1.0
    2107  *
    2108  * @return object Current screen object
    2109  */
    2110 function get_current_screen() {
    2111         global $current_screen;
    2112 
    2113         if ( !isset($current_screen) )
    2114                 return null;
    2115 
    2116         return $current_screen;
    2117 }
    2118 
    2119 /**
    2120  * Set the current screen object
    2121  *
    2122  * @since 3.0.0
    2123  *
    2124  * @uses $current_screen
    2125  *
    2126  * @param string $id Screen id, optional.
    2127  */
    2128 function set_current_screen( $id =  '' ) {
    2129         global $current_screen;
    2130 
    2131         $current_screen = new WP_Screen( $id );
    2132 
    2133         $current_screen = apply_filters('current_screen', $current_screen);
    21341544}
    21351545
     
    22621672<?php
    22631673}
    2264 
    2265 class WP_Screen {
    2266         var $action = '';
    2267         var $base;
    2268         var $id;
    2269         var $is_network;
    2270         var $is_user;
    2271         var $parent_base;
    2272         var $parent_file;
    2273         var $post_type;
    2274         var $taxonomy;
    2275 
    2276         function __construct( $id = '' ) {
    2277                 global $hook_suffix, $typenow, $taxnow;
    2278 
    2279                 $action = '';
    2280 
    2281                 if ( empty( $id ) ) {
    2282                         $screen = $hook_suffix;
    2283                         $screen = str_replace('.php', '', $screen);
    2284                         if ( preg_match('/-add|-new$/', $screen) )
    2285                                 $action = 'add';
    2286                         $screen = str_replace('-new', '', $screen);
    2287                         $screen = str_replace('-add', '', $screen);
    2288                         $this->id = $this->base = $screen;
    2289                 } else {
    2290                         $id = sanitize_key( $id );
    2291                         if ( false !== strpos($id, '-') ) {
    2292                                 list( $id, $typenow ) = explode('-', $id, 2);
    2293                                 if ( taxonomy_exists( $typenow ) ) {
    2294                                         $id = 'edit-tags';
    2295                                         $taxnow = $typenow;
    2296                                         $typenow = '';
    2297                                 }
    2298                         }
    2299                         $this->id = $this->base = $id;
    2300                 }
    2301 
    2302                 $this->action = $action;
    2303 
    2304                 // Map index to dashboard
    2305                 if ( 'index' == $this->base )
    2306                         $this->base = 'dashboard';
    2307                 if ( 'index' == $this->id )
    2308                         $this->id = 'dashboard';
    2309 
    2310                 if ( 'edit' == $this->id ) {
    2311                         if ( empty($typenow) )
    2312                                 $typenow = 'post';
    2313                         $this->id .= '-' . $typenow;
    2314                         $this->post_type = $typenow;
    2315                 } elseif ( 'post' == $this->id ) {
    2316                         if ( empty($typenow) )
    2317                                 $typenow = 'post';
    2318                         $this->id = $typenow;
    2319                         $this->post_type = $typenow;
    2320                 } elseif ( 'edit-tags' == $this->id ) {
    2321                         if ( empty($taxnow) )
    2322                                 $taxnow = 'post_tag';
    2323                         $this->id = 'edit-' . $taxnow;
    2324                         $this->taxonomy = $taxnow;
    2325                 }
    2326 
    2327                 $this->is_network = is_network_admin();
    2328                 $this->is_user = is_user_admin();
    2329 
    2330                 if ( $this->is_network ) {
    2331                         $this->base .= '-network';
    2332                         $this->id .= '-network';
    2333                 } elseif ( $this->is_user ) {
    2334                         $this->base .= '-user';
    2335                         $this->id .= '-user';
    2336                 }
    2337         }
    2338 
    2339         function set_parentage( $parent_file ) {
    2340                 $this->parent_file = $parent_file;
    2341                 $this->parent_base = preg_replace('/\?.*$/', '', $parent_file);
    2342                 $this->parent_base = str_replace('.php', '', $this->parent_base);
    2343         }
    2344 
    2345         function add_option( $option, $args = array() ) {
    2346                 return add_screen_option( $option, $args );
    2347         }
    2348 
    2349         function add_help_tab( $id, $title, $content) {
    2350                 global $_wp_contextual_help;
    2351 
    2352                 $_wp_contextual_help[$this->id]['tabs'][] = array( $id, $title, $content );
    2353         }
    2354 
    2355         function add_help_sidebar( $content ) {
    2356                 global $_wp_contextual_help;
    2357 
    2358                 $_wp_contextual_help[$this->id]['sidebar'] = $content;
    2359         }
    2360 }
Note: See TracChangeset for help on using the changeset viewer.