Make WordPress Core


Ignore:
Timestamp:
10/07/2011 04:57:12 AM (15 years ago)
Author:
nacin
Message:

Revert [18861], [18862], [18864], [18874], [18879], and [18880]. see #18785.

File:
1 edited

Legend:

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

    r18896 r18911  
    1515 * @return array Containing the headers in the format id => UI String
    1616 */
    17 function get_column_headers( $screen ) { // TODO: fold into WP_Screen?
     17function get_column_headers( $screen ) {
    1818        if ( is_string( $screen ) )
    1919                $screen = convert_to_screen( $screen );
     
    3636 * @return array
    3737 */
    38 function get_hidden_columns( $screen ) { // TODO: fold into WP_Screen
     38function get_hidden_columns( $screen ) {
    3939        if ( is_string( $screen ) )
    4040                $screen = convert_to_screen( $screen );
     
    4444
    4545/**
     46 * {@internal Missing Short Description}}
     47 *
     48 * @since 2.7.0
     49 *
     50 * @param unknown_type $screen
     51 */
     52function meta_box_prefs($screen) {
     53        global $wp_meta_boxes;
     54
     55        if ( is_string($screen) )
     56                $screen = convert_to_screen($screen);
     57
     58        if ( empty($wp_meta_boxes[$screen->id]) )
     59                return;
     60
     61        $hidden = get_hidden_meta_boxes($screen);
     62
     63        foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
     64                foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
     65                        foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
     66                                if ( false == $box || ! $box['title'] )
     67                                        continue;
     68                                // Submit box cannot be hidden
     69                                if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
     70                                        continue;
     71                                $box_id = $box['id'];
     72                                echo '<label for="' . $box_id . '-hide">';
     73                                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"' : '') . ' />';
     74                                echo "{$box['title']}</label>\n";
     75                        }
     76                }
     77        }
     78}
     79
     80/**
    4681 * Get Hidden Meta Boxes
    4782 *
     
    5186 * @return array Hidden Meta Boxes
    5287 */
    53 function get_hidden_meta_boxes( $screen ) { // TODO: fold into WP_Screen
     88function get_hidden_meta_boxes( $screen ) {
    5489        if ( is_string( $screen ) )
    5590                $screen = convert_to_screen( $screen );
     
    6398                else
    6499                        $hidden = array( 'slugdiv' );
    65 
    66100                $hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
    67101        }
    68102
    69103        return $hidden;
     104}
     105
     106/**
     107 * {@internal Missing Short Description}}
     108 *
     109 * @since 2.7.0
     110 */
     111function favorite_actions( $screen = null ) {
     112        $default_action = false;
     113
     114        if ( is_string($screen) )
     115                $screen = convert_to_screen($screen);
     116
     117        if ( $screen->is_user )
     118                return;
     119
     120        if ( isset($screen->post_type) ) {
     121                $post_type_object = get_post_type_object($screen->post_type);
     122                if ( 'add' != $screen->action )
     123                        $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));
     124                else
     125                        $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
     126        }
     127
     128        if ( !$default_action ) {
     129                if ( $screen->is_network ) {
     130                        $default_action = array('sites.php' => array( __('Sites'), 'manage_sites'));
     131                } else {
     132                        switch ( $screen->id ) {
     133                                case 'upload':
     134                                        $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
     135                                        break;
     136                                case 'media':
     137                                        $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
     138                                        break;
     139                                case 'link-manager':
     140                                case 'link':
     141                                        if ( 'add' != $screen->action )
     142                                                $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
     143                                        else
     144                                                $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
     145                                        break;
     146                                case 'users':
     147                                        $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
     148                                        break;
     149                                case 'user':
     150                                        $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
     151                                        break;
     152                                case 'plugins':
     153                                        $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
     154                                        break;
     155                                case 'plugin-install':
     156                                        $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
     157                                        break;
     158                                case 'themes':
     159                                        $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
     160                                        break;
     161                                case 'theme-install':
     162                                        $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
     163                                        break;
     164                                default:
     165                                        $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
     166                                        break;
     167                        }
     168                }
     169        }
     170
     171        if ( !$screen->is_network ) {
     172                $actions = array(
     173                        'post-new.php' => array(__('New Post'), 'edit_posts'),
     174                        'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
     175                        'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
     176                        'media-new.php' => array(__('Upload'), 'upload_files'),
     177                        'edit-comments.php' => array(__('Comments'), 'moderate_comments')
     178                        );
     179        } else {
     180                $actions = array(
     181                        'sites.php' => array( __('Sites'), 'manage_sites'),
     182                        'users.php' => array( __('Users'), 'manage_network_users')
     183                );
     184        }
     185
     186        $default_key = array_keys($default_action);
     187        $default_key = $default_key[0];
     188        if ( isset($actions[$default_key]) )
     189                unset($actions[$default_key]);
     190        $actions = array_merge($default_action, $actions);
     191        $actions = apply_filters( 'favorite_actions', $actions, $screen );
     192
     193        $allowed_actions = array();
     194        foreach ( $actions as $action => $data ) {
     195                if ( current_user_can($data[1]) )
     196                        $allowed_actions[$action] = $data[0];
     197        }
     198
     199        if ( empty($allowed_actions) )
     200                return;
     201
     202        $first = array_keys($allowed_actions);
     203        $first = $first[0];
     204        echo '<div id="favorite-actions">';
     205        echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
     206        echo '<div id="favorite-inside">';
     207
     208        array_shift($allowed_actions);
     209
     210        foreach ( $allowed_actions as $action => $label) {
     211                echo "<div class='favorite-action'><a href='$action'>";
     212                echo $label;
     213                echo "</a></div>\n";
     214        }
     215        echo "</div></div>\n";
    70216}
    71217
     
    78224 * @return object An object containing the safe screen name and id
    79225 */
    80 function convert_to_screen( $screen ) { // TODO: fold into WP_Screen?
     226function convert_to_screen( $screen ) {
    81227        $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
    82228
     
    86232                $screen .= '-user';
    87233
    88         // why do we need this? $screen = (string) apply_filters( 'screen_meta_screen', $screen );
     234        $screen = (string) apply_filters( 'screen_meta_screen', $screen );
    89235        $screen = (object) array('id' => $screen, 'base' => $screen);
    90236        return $screen;
    91237}
    92238
    93 function screen_icon( $for = '' ) { // TODO: fold into WP_Screen?
    94         global $current_screen;
    95 
    96         if ( !isset($current_screen) )
     239/**
     240 * Add contextual help text for a page.
     241 *
     242 * Creates a 'Screen Info' help tab.
     243 *
     244 * @since 2.7.0
     245 *
     246 * @param string    $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
     247 * @param string    $help   The content of a 'Screen Info' help tab.
     248 *
     249 * @todo: deprecate?
     250 */
     251function add_contextual_help($screen, $help) {
     252        global $_wp_contextual_help;
     253
     254        if ( is_string($screen) )
     255                $screen = convert_to_screen($screen);
     256
     257        if ( !isset($_wp_contextual_help) )
     258                $_wp_contextual_help = array();
     259
     260        $_wp_contextual_help[$screen->id] = $help;
     261}
     262
     263/**
     264 * Register and configure an admin screen option
     265 *
     266 * @since 3.1.0
     267 *
     268 * @param string $option An option name.
     269 * @param mixed $args Option dependent arguments
     270 * @return void
     271 */
     272function add_screen_option( $option, $args = array() ) {
     273        $current_screen = get_current_screen();
     274
     275        if ( ! $current_screen )
    97276                return;
    98277
    99         echo $current_screen->get_screen_icon( $for );
     278        return $current_screen->add_option( $option, $args );
     279}
     280
     281function screen_icon( $screen = '' ) {
     282        echo get_screen_icon( $screen );
     283}
     284
     285function get_screen_icon( $screen = '' ) {
     286        global $current_screen, $typenow;
     287
     288        if ( empty($screen) )
     289                $screen = $current_screen;
     290        elseif ( is_string($screen) )
     291                $name = $screen;
     292
     293        $class = 'icon32';
     294
     295        if ( empty($name) ) {
     296                if ( !empty($screen->parent_base) )
     297                        $name = $screen->parent_base;
     298                else
     299                        $name = $screen->base;
     300
     301                if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
     302                        $name = 'edit-pages';
     303
     304                $post_type = '';
     305                if ( isset( $screen->post_type ) )
     306                        $post_type = $screen->post_type;
     307                elseif ( $current_screen == $screen )
     308                        $post_type = $typenow;
     309                if ( $post_type )
     310                        $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
     311        }
     312
     313        return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>';
    100314}
    101315
     
    125339 * @param string $id Screen id, optional.
    126340 */
    127 function set_current_screen( $id = '' ) {
     341function set_current_screen( $id =  '' ) {
    128342        global $current_screen;
    129343
    130         if ( !is_a( $current_screen, 'WP_Screen' ) )
    131                 $current_screen = new WP_Screen( $id );
    132 
    133         // why do we need this? $current_screen = apply_filters('current_screen', $current_screen);
     344        $current_screen = new WP_Screen( $id );
     345
     346        $current_screen = apply_filters('current_screen', $current_screen);
    134347}
    135348
     
    252465         * @access private
    253466         */
    254         private $_options = array(
    255                 '_context' => '',
    256                 '_screen_settings' => ''
    257         );
    258 
    259         /**
    260          * Show screen options if any.
     467        private $_options = array();
     468
     469
     470        /**
     471         * Stores the result of the public show_screen_options function.
    261472         *
    262473         * @since 3.3.0
     
    264475         * @access private
    265476         */
    266         private $_show_options = false;
     477        private $_show_screen_options;
     478
     479        /**
     480         * Stores the 'screen_settings' section of screen options.
     481         *
     482         * @since 3.3.0
     483         * @var string
     484         * @access private
     485         */
     486        private $_screen_settings;
    267487
    268488        /**
     
    281501                        $screen = $hook_suffix;
    282502                        $screen = str_replace('.php', '', $screen);
    283 
    284503                        if ( preg_match('/-add|-new$/', $screen) )
    285504                                $action = 'add';
    286 
    287505                        $screen = str_replace('-new', '', $screen);
    288506                        $screen = str_replace('-add', '', $screen);
     
    290508                } else {
    291509                        $id = sanitize_key( $id );
    292 
    293510                        if ( false !== strpos($id, '-') ) {
    294511                                list( $id, $typenow ) = explode('-', $id, 2);
    295 
    296512                                if ( taxonomy_exists( $typenow ) ) {
    297513                                        $id = 'edit-tags';
     
    308524                if ( 'index' == $this->base )
    309525                        $this->base = 'dashboard';
    310 
    311526                if ( 'index' == $this->id )
    312527                        $this->id = 'dashboard';
     
    315530                        if ( empty($typenow) )
    316531                                $typenow = 'post';
    317 
    318532                        $this->id .= '-' . $typenow;
    319533                        $this->post_type = $typenow;
     
    321535                        if ( empty($typenow) )
    322536                                $typenow = 'post';
    323 
    324537                        $this->id = $typenow;
    325538                        $this->post_type = $typenow;
     
    327540                        if ( empty($taxnow) )
    328541                                $taxnow = 'post_tag';
    329 
    330542                        $this->id = 'edit-' . $taxnow;
    331543                        $this->taxonomy = $taxnow;
     
    360572        /**
    361573         * Adds an option for the screen.
    362          * Use the 'add_screen_help_and_options' action to add screen options.
     574         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
    363575         *
    364576         * @since 3.3.0
    365577         *
    366578         * @param string $option Option ID
    367          * @param mixed $args Associative array of arguments particular to the default $option or the HTML string to be printed in the Screen Options tab.
    368          */
    369         public function add_option( $option, $args = null ) {
    370                 if ( is_array($args) && !empty($option) )
    371                         $this->_options[ $option ] = $args;
    372                 elseif ( is_string($option) )
    373                         $this->_options['_screen_settings'] .= $option;
    374                 else
    375                         return false;
    376 
    377                 $this->_show_options = true;
    378                 return true;
    379         }
    380        
    381         /**
    382          * Adds option context.
    383          * Use the 'add_screen_help_and_options' action to add it. Will not be shown if there aren't any screen options.
    384          *
    385          * @since 3.3.0
    386          *
    387          * @param string $text
    388          */
    389         public function add_option_context( $text ) {
    390                 $this->_options['_context'] .= $text;
     579         * @param array $args Associative array of arguments particular to the given $option.
     580         */
     581        public function add_option( $option, $args = array() ) {
     582                $this->_options[ $option ] = $args;
    391583        }
    392584
    393585        /**
    394586         * Add a help tab to the contextual help for the screen.
    395          * Use the 'add_screen_help_and_options' action to add contextual help tabs.
     587         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add contextual help tabs.
    396588         *
    397589         * @since 3.3.0
     
    399591         * @param array $args
    400592         * - string   - title    - Title for the tab.
    401          * - string   - id       - Tab ID.
    402          * - string   - section  - Section title for the tab. Optional.
     593         * - string   - id       - Tab ID. Optional.
    403594         * - string   - content  - Help tab content in plain text or HTML. Optional.
    404595         * - callback - callback - A callback to generate the tab content. Optional.
     
    409600                        'title'    => false,
    410601                        'id'       => false,
    411                         'section'  => false,
    412602                        'content'  => '',
    413                         'callback' => false
     603                        'callback' => false,
    414604                );
    415605                $args = wp_parse_args( $args, $defaults );
    416606
    417                 // Ensure we have title and ID.
    418                 if ( ! $args['title'] || ! $args['id'] )
    419                         return false;
     607                // Ensure we have a title.
     608                if ( ! $args['title'] )
     609                        return;
     610
     611                // Create an id from the title if one is not provided.
     612                if ( ! $args['id'] )
     613                        $args['id'] = sanitize_html_class( $args['title'] );
    420614
    421615                $this->_help_tabs[] = $args;
    422                 return true;
    423616        }
    424617
    425618        /**
    426619         * Add a sidebar to the contextual help for the screen.
    427          * Use the 'add_screen_help_and_options' action to add a sidebar to the contextual help.
     620         * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add a sidebar to the contextual help.
    428621         *
    429622         * @since 3.3.0
     
    432625         */
    433626        public function add_help_sidebar( $content ) {
    434                 if ( empty($this->_help_sidebar) ) // add only one
    435                         $this->_help_sidebar = $content;
     627                $this->_help_sidebar = $content;
    436628        }
    437629
     
    445637        public function render_screen_meta() {
    446638                global $_wp_contextual_help;
    447 
    448                 // Intended for adding Help and Screen Options.
    449                 do_action('add_screen_help_and_options', $this);
    450639
    451640                // Call old contextual_help_list filter.
    452641                if ( ! isset( $_wp_contextual_help ) )
    453642                        $_wp_contextual_help = array();
    454 
    455                 // why are we filtering a global? $_wp_contextual_help = apply_filters( 'contextual_help_list', $_wp_contextual_help, $this );
     643                $_wp_contextual_help = apply_filters( 'contextual_help_list', $_wp_contextual_help, $this );
    456644
    457645                if ( isset( $_wp_contextual_help[ $this->id ] ) ) {
    458646                        // Call old contextual_help filter.
    459                         // why are we filtering the same global second time??
    460647                        $contextual_help = apply_filters( 'contextual_help', $_wp_contextual_help[ $this->id ], $this->id, $this );
    461648
    462649                        $this->add_help_tab( array(
    463                                 'title'         => __('Screen Info'),
    464                                 'id'            => 'screen-info',
    465                                 'content'       => $_wp_contextual_help[ $this->id ]
     650                                'title'   => __('Screen Info'),
     651                                'content' => $contextual_help,
     652                        ) );
     653                }
     654
     655                // Add screen options tab
     656                if ( $this->show_screen_options() ) {
     657                        $this->add_help_tab( array(
     658                                'title'    => __('Screen Options'),
     659                                'callback' => array( $this, 'render_screen_options' ),
    466660                        ) );
    467661                }
     
    474668                                <div class="contextual-help-tabs">
    475669                                        <ul>
    476                                         <?php
    477 
    478                                         if ( $this->_show_options ) {
    479                                                 $class = true;
     670                                        <?php foreach ( $this->_help_tabs as $i => $tab ):
     671                                                $link_id  = "tab-link-{$tab['id']}";
     672                                                $panel_id = "tab-panel-{$tab['id']}";
     673                                                $classes  = ( $i == 0 ) ? 'active' : '';
    480674                                                ?>
    481                                                 <li id="tab-link-screen-options" class="active">
    482                                                         <a href="#tab-panel-screen-options">
    483                                                                 <?php _e('Screen Options'); ?>
    484                                                         </a>
    485                                                 </li>
    486                                                 <?php
    487                                         }
    488 
    489                                         foreach ( $this->_help_tabs as $i => $tab ) {
    490                                                 $id = esc_attr($tab['id']);
    491                                                 $class = empty($class) && $i == 0 ? ' class="active"' : '';
    492                                                 ?>
    493                                                 <li id="<?php echo "tab-link-$id"; ?>"<?php echo $class; ?>>
    494                                                         <a href="<?php echo "#tab-panel-$id"; ?>">
     675
     676                                                <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     677                                                        <a href="<?php echo esc_url( "#$panel_id" ); ?>">
    495678                                                                <?php echo esc_html( $tab['title'] ); ?>
    496679                                                        </a>
    497680                                                </li>
    498                                         <?php } ?>
     681                                        <?php endforeach; ?>
    499682                                        </ul>
    500683                                </div>
    501                                 <?php
    502 
    503                                 if ( $this->_help_sidebar )
    504                                         echo '<div class="contextual-help-sidebar">' . $this->_help_sidebar . '</div>';
    505 
    506                                 ?>
     684
     685                                <div class="contextual-help-sidebar">
     686                                        <?php echo $this->_help_sidebar; ?>
     687                                </div>
     688
    507689                                <div class="contextual-help-tabs-wrap">
    508                                         <?php
    509 
    510                                         if ( $this->_show_options ) {
    511                                                 $class2 = true;
    512                                                 echo '<div id="tab-panel-screen-options" class="help-tab-content active">';
    513 
    514                                                 if ( !empty($this->_options['_context']) )
    515                                                         echo $this->_options['_context'];
    516 
    517                                                 $this->render_screen_options();
    518                                                 echo '</div>';
    519                                         }
    520 
    521                                         foreach ( $this->_help_tabs as $i => $tab ) {
    522                                                 $class2 = empty($class2) && $i == 0 ? ' active' : '';
     690                                        <?php foreach ( $this->_help_tabs as $i => $tab ):
     691                                                $panel_id = "tab-panel-{$tab['id']}";
     692                                                $classes  = ( $i == 0 ) ? 'active' : '';
     693                                                $classes .= ' help-tab-content';
    523694                                                ?>
    524695
    525                                                 <div id="<?php echo esc_attr( "tab-panel-{$tab['id']}" ); ?>" class="help-tab-content<?php echo $class2; ?>">
     696                                                <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     697                                                        <h3><?php echo esc_html( $tab['title'] ); ?></h3>
    526698                                                        <?php
    527                                                         if ( $tab['section'] )
    528                                                                 echo '<h3>' . esc_html( $tab['section'] ) . '</h3>';
    529 
    530699                                                        // Print tab content.
    531700                                                        echo $tab['content'];
     
    536705                                                        ?>
    537706                                                </div>
    538                                         <?php } ?>
     707                                        <?php endforeach; ?>
    539708                                </div>
    540709                        </div>
     
    543712        }
    544713
    545         /**
    546          * Render the screen options tab.
    547          *
    548          * @since 3.3.0
    549          */
    550         public function render_screen_options() {
    551 
    552                 $screen_settings = $this->_options['_screen_settings'];
    553 
    554                 // Default screen_settings for various screens.
    555                 // TODO: should probably be set on these screens, not here.
     714        public function show_screen_options() {
     715                global $wp_meta_boxes, $wp_list_table;
     716
     717                if ( is_bool( $this->_show_screen_options ) )
     718                        return $this->_show_screen_options;
     719
     720                $columns = get_column_headers( $this );
     721
     722                $show_screen = false;
     723                if ( ! empty( $wp_meta_boxes[ $this->id ] ) || ! empty( $columns ) )
     724                        $show_screen = true;
     725
     726                // Check if there are per-page options.
     727                $show_screen = $show_screen || isset( $this->_options['per_page'] );
     728
     729                $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
     730
    556731                switch ( $this->id ) {
    557732                        case 'widgets':
    558                                 $screen_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";
     733                                $this->_screen_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";
     734                                $show_screen = true;
    559735                                break;
    560736                }
    561737
    562                 // TODO: deprecate
    563                 $screen_settings = apply_filters( 'screen_settings', $screen_settings, $this );
    564 
    565                 echo '<form id="adv-settings" action="" method="post">';
    566 
    567                 $this->render_table_columns_prefs();
    568                 $this->render_metabox_prefs();
    569                 $this->render_screen_layout();
    570                 $this->render_per_page_options();
    571                 echo $screen_settings;
    572 
    573                 wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false );
    574                 echo '</form>';
    575 
    576         }
    577 
    578         /**
    579          * Render the option for hiding table columns on the page
    580          *
    581          * @since 3.3.0
    582          */
    583         function render_table_columns_prefs() {
     738                if ( ! empty( $this->_screen_settings ) )
     739                        $show_screen = true;
     740
     741                if ( ! empty( $this->_options ) )
     742                        $show_screen = true;
     743
     744                $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
     745                return $this->_show_screen_options;
     746        }
     747
     748        /**
     749         * Render the screen options tab.
     750         *
     751         * @since 3.3.0
     752         */
     753        public function render_screen_options() {
     754                global $wp_meta_boxes, $wp_list_table;
     755
    584756                $columns = get_column_headers( $this );
    585 
    586                 if ( ! empty( $columns ) ) {
    587                         $hidden = get_hidden_columns( $this );
    588                         ?>
     757                $hidden  = get_hidden_columns( $this );
     758
     759                ?>
     760                <form id="adv-settings" action="" method="post">
     761                <?php if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
     762                        <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
     763                        <div class="metabox-prefs">
     764                                <?php meta_box_prefs( $this ); ?>
     765                                <br class="clear" />
     766                        </div>
     767                        <?php endif;
     768                        if ( ! empty( $columns ) ) : ?>
    589769                        <h5><?php echo ( isset( $columns['_title'] ) ?  $columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
    590770                        <div class="metabox-prefs">
     
    601781                                        if ( 'comments' == $column )
    602782                                                $title = __( 'Comments' );
    603 
    604783                                        $id = "$column-hide";
    605784                                        echo '<label for="' . $id . '">';
     
    610789                                <br class="clear" />
    611790                        </div>
    612                 <?php }
    613         }
    614 
    615         /**
    616          * Render the option for hiding metaboxes on the page
    617          *
    618          * @since 3.3.0
    619          */
    620         function render_metabox_prefs() {
    621                 global $wp_meta_boxes;
    622 
    623                 if ( !empty( $wp_meta_boxes[ $this->id ] ) ) {
    624                         $hidden = get_hidden_meta_boxes($this);
    625                         ?>
    626                         <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
    627                         <div class="metabox-prefs">
    628                                 <?php
    629 
    630                                 foreach ( array_keys($wp_meta_boxes[$this->id]) as $context ) {
    631                                         foreach ( array_keys($wp_meta_boxes[$this->id][$context]) as $priority ) {
    632                                                 foreach ( $wp_meta_boxes[$this->id][$context][$priority] as $box ) {
    633                                                         if ( false == $box || ! $box['title'] )
    634                                                                 continue;
    635                                                         // Submit box cannot be hidden
    636                                                         if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
    637                                                                 continue;
    638                                                         $box_id = $box['id'];
    639                                                         echo '<label for="' . $box_id . '-hide">';
    640                                                         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"' : '') . ' />';
    641                                                         echo "{$box['title']}</label>\n";
    642                                                 }
    643                                         }
    644                                 }
    645 
    646                                 ?>
    647                                 <br class="clear" />
    648                         </div>
    649                         <?php
    650                 }
     791                <?php endif;
     792
     793                $this->render_screen_layout();
     794                $this->render_per_page_options();
     795                echo $this->_screen_settings;
     796
     797                ?>
     798                <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
     799                </form>
     800                <?php
    651801        }
    652802
     
    660810
    661811                // Back compat for plugins using the filter instead of add_screen_option()
    662                 // TODO: deprecate it
    663812                $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
    664813
    665814                if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
    666                         $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
     815                        add_screen_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
    667816
    668817                if ( ! isset( $this->_options['layout_columns'] ) ) {
     
    702851         */
    703852        function render_per_page_options() {
    704                 if ( empty( $this->_options['per_page'] ) )
     853                if ( ! isset( $this->_options['per_page'] ) )
    705854                        return;
    706855
     
    751900                <?php
    752901        }
    753        
    754         function get_screen_icon( $for = '' ) {
    755 
    756                 if ( !empty($for) && is_string($for) ) {
    757                         $name = $for;
    758                 } else {
    759                         if ( !empty($this->parent_base) )
    760                                 $name = $this->parent_base;
    761                         else
    762                                 $name = $this->base;
    763                 }
    764 
    765                 if ( 'edit' == $name && isset($this->post_type) && 'page' == $this->post_type )
    766                         $name = 'edit-pages';
    767 
    768                 $class = '';
    769                 if ( !empty( $this->post_type ) )
    770                         $class = ' ' . sanitize_html_class( 'icon32-posts-' . $this->post_type );
    771 
    772                 return '<div id="icon-' . esc_attr( $name ) . '" class="icon32' . $class . '"><br /></div>';
    773         }
    774 }
    775 
     902}
Note: See TracChangeset for help on using the changeset viewer.