Make WordPress Core


Ignore:
Timestamp:
10/01/2011 12:24:44 AM (14 years ago)
Author:
koopersmith
Message:

Make screen options a help tab. Move screen option functions into WP_Screen. see #18690, #18785.

File:
1 edited

Legend:

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

    r18808 r18853  
    237237}
    238238
    239 function screen_meta($screen) {
    240     global $wp_meta_boxes, $_wp_contextual_help, $wp_list_table, $wp_current_screen_options;
     239function screen_meta( $screen ) {
     240    $current_screen = get_current_screen();
     241    $current_screen->render_screen_meta();
     242}
     243
     244/**
     245 * Add contextual help text for a page.
     246 *
     247 * Creates a 'Screen Info' help tab.
     248 *
     249 * @since 2.7.0
     250 *
     251 * @param string    $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
     252 * @param string    $help   The content of a 'Screen Info' help tab.
     253 *
     254 * @todo: deprecate?
     255 */
     256function add_contextual_help($screen, $help) {
     257    global $_wp_contextual_help;
    241258
    242259    if ( is_string($screen) )
    243260        $screen = convert_to_screen($screen);
    244261
    245     $columns = get_column_headers( $screen );
    246     $hidden = get_hidden_columns( $screen );
    247 
    248     $meta_screens = array('index' => 'dashboard');
    249 
    250     if ( isset($meta_screens[$screen->id]) ) {
    251         $screen->id = $meta_screens[$screen->id];
    252         $screen->base = $screen->id;
    253     }
    254 
    255     $show_screen = false;
    256     if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) )
    257         $show_screen = true;
    258 
    259     $screen_options = screen_options($screen);
    260     if ( $screen_options )
    261         $show_screen = true;
    262 
    263262    if ( !isset($_wp_contextual_help) )
    264263        $_wp_contextual_help = array();
    265264
    266     $settings = apply_filters('screen_settings', '', $screen);
    267 
    268     switch ( $screen->id ) {
    269         case 'widgets':
    270             $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";
    271             $show_screen = true;
    272             break;
    273     }
    274     if ( ! empty( $settings ) )
    275         $show_screen = true;
    276 
    277     if ( !empty($wp_current_screen_options) )
    278         $show_screen = true;
    279 
    280     $show_screen = apply_filters('screen_options_show_screen', $show_screen, $screen);
    281 
    282     // If we have screen options, add the menu to the admin bar.
    283     if ( $show_screen )
    284         add_action( 'admin_bar_menu', 'wp_admin_bar_screen_options_menu', 80 );
    285 
    286 
    287 ?>
    288 <div id="screen-meta">
    289 <?php if ( $show_screen ) : ?>
    290 <div id="screen-options-wrap" class="hidden">
    291     <form id="adv-settings" action="" method="post">
    292     <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
    293         <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
    294         <div class="metabox-prefs">
    295             <?php meta_box_prefs($screen); ?>
    296             <br class="clear" />
    297         </div>
    298         <?php endif;
    299         if ( ! empty($columns) ) : ?>
    300         <h5><?php echo ( isset( $columns['_title'] ) ?  $columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
    301         <div class="metabox-prefs">
    302 <?php
    303     $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
    304 
    305     foreach ( $columns as $column => $title ) {
    306         // Can't hide these for they are special
    307         if ( in_array( $column, $special ) )
    308             continue;
    309         if ( empty( $title ) )
    310             continue;
    311 
    312         if ( 'comments' == $column )
    313             $title = __( 'Comments' );
    314         $id = "$column-hide";
    315         echo '<label for="' . $id . '">';
    316         echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
    317         echo "$title</label>\n";
    318     }
    319 ?>
    320             <br class="clear" />
    321         </div>
    322     <?php endif;
    323     echo screen_layout($screen);
    324 
    325     if ( !empty( $screen_options ) ) {
    326         ?>
    327         <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
    328         <?php
    329     }
    330 
    331     echo $screen_options;
    332     echo $settings; ?>
    333     <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
    334     </form>
    335 </div>
    336 
    337 <?php endif; // $show_screen
    338 
    339     $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
    340     ?>
    341     <div id="contextual-help-wrap" class="hidden">
    342     <?php
    343     $contextual_help = '';
    344     if ( isset($_wp_contextual_help[$screen->id]) && is_array($_wp_contextual_help[$screen->id]) ) {
    345 
    346         /*
    347          * Loop through ['contextual-help-tabs']
    348          *   - It's a nested array where $key=>$value >> $title=>$content
    349          * Has no output so can only loop the array once
    350          */
    351         $contextual_help_links = ''; // store looped content for later
    352         $contextual_help_panels = ''; // store looped content for later
    353 
    354         $tab_active = true;
    355 
    356         foreach ( $_wp_contextual_help[$screen->id]['tabs'] as $tab ) {
    357             list( $id, $title, $content ) = $tab;
    358 
    359             // Generate IDs
    360             $id = sanitize_html_class( $id );
    361             $link_id  = "tab-link-$id";
    362             $panel_id = "tab-panel-$id";
    363 
    364             $link_classes  = '';
    365             $panel_classes = 'help-tab-content';
    366 
    367             if ( $tab_active ) {
    368                 $link_classes  .= ' active';
    369                 $panel_classes .= ' active';
    370             }
    371 
    372             $link_classes = ( $tab_active ) ? 'active' : '';
    373 
    374             $contextual_help_links .= '<li id="' . esc_attr( $link_id ) . '" class="' . esc_attr( $link_classes ) . '">';
    375             $contextual_help_links .= '<a href="' . esc_url( "#$panel_id" ) . '">' . esc_html( $title ) . '</a>';
    376             $contextual_help_links .= '</li>';
    377 
    378             $contextual_help_panels .= '<div id="' . esc_attr( $panel_id ) . '" class="' . esc_attr( $panel_classes ) . '">';
    379             $contextual_help_panels .= '<h3>' . esc_html( $title ) . '</h3>';
    380             $contextual_help_panels .= $content;
    381             $contextual_help_panels .= "</div>";
    382 
    383             $tab_active = false;
    384         }
    385 
    386         // Start output from loop: Tabbed help content
    387         $contextual_help .= '<ul class="contextual-help-tabs">' . "\n";
    388         $contextual_help .= $contextual_help_links;
    389         $contextual_help .= '</ul>' ."\n";
    390 
    391         // Sidebar to right of tabs
    392         $contextual_help .= '<div class="contextual-help-sidebar">' . "\n";
    393         $contextual_help .= $_wp_contextual_help[$screen->id]['sidebar'];
    394         $contextual_help .= "</div>\n";
    395 
    396         // Panel content
    397         $contextual_help .= '<div class="contextual-help-tabs-wrap">' . "\n";
    398         $contextual_help .= $contextual_help_panels;
    399         $contextual_help .= "</div>\n";
    400 
    401     } elseif ( isset( $_wp_contextual_help[ $screen->id ] ) ) {
    402         $contextual_help .= $_wp_contextual_help[ $screen->id ];
    403 
    404     } else {
    405         $default_help  = __( '<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>' );
    406         $default_help .= '<br />';
    407         $default_help .= __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' );
    408 
    409         $contextual_help .= apply_filters( 'default_contextual_help', $default_help );
    410     }
    411 
    412     $contextual_help = "<div class='metabox-prefs'>$contextual_help</div>";
    413 
    414     echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
    415     ?>
    416     </div>
    417 
    418 </div> <?php // #screen-meta
    419 }
    420 
    421 /**
    422  * Add contextual help text for a page
    423  *
    424  * The array $help takes the following format:
    425  *  array( 'contextual-help-tabs'   => array( $tab1_title => $tab1_value [, $tab2_title => $tab2_value, ...] ),
    426  *      'contextual-help-sidebar' => $help_links_as_string )
    427  *
    428  * For backwards compatability, a string is also accepted.
    429  *
    430  * @since 2.7.0
    431  *
    432  * @param string    $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
    433  * @param array|string  $help   Creates tabs & links columns within help text in array.
    434  *
    435  */
    436 function add_contextual_help($screen, $help) {
    437     global $_wp_contextual_help;
    438 
    439     if ( is_string($screen) )
    440         $screen = convert_to_screen($screen);
    441 
    442     if ( !isset($_wp_contextual_help) )
    443         $_wp_contextual_help = array();
    444 
    445265    $_wp_contextual_help[$screen->id] = $help;
    446266}
    447267
     268/**
     269 * Returns the screen layout options.
     270 *
     271 * @todo: deprecate?
     272 */
    448273function screen_layout($screen) {
    449     global $screen_layout_columns, $wp_current_screen_options;
    450 
    451     if ( is_string($screen) )
    452         $screen = convert_to_screen($screen);
    453 
    454     // Back compat for plugins using the filter instead of add_screen_option()
    455     $columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen);
    456     if ( !empty($columns) && isset($columns[$screen->id]) )
    457         add_screen_option('layout_columns', array('max' => $columns[$screen->id]) );
    458 
    459     if ( !isset($wp_current_screen_options['layout_columns']) ) {
    460         $screen_layout_columns = 0;
     274    $current_screen = get_current_screen();
     275
     276    if ( ! $current_screen )
    461277        return '';
    462     }
    463 
    464     $screen_layout_columns = get_user_option("screen_layout_$screen->id");
    465     $num = $wp_current_screen_options['layout_columns']['max'];
    466 
    467     if ( ! $screen_layout_columns ) {
    468         if ( isset($wp_current_screen_options['layout_columns']['default']) )
    469             $screen_layout_columns = $wp_current_screen_options['layout_columns']['default'];
    470         else
    471             $screen_layout_columns = 'auto';
    472     }
    473 
    474     $i = 1;
    475     $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
    476     while ( $i <= $num ) {
    477         $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
    478         ++$i;
    479     }
    480     $return .= "<label><input type='radio' id='wp_auto_columns' name='screen_columns' value='auto'" . ( ($screen_layout_columns == 'auto') ? " checked='checked'" : "" ) . " /> " . __('Auto') . "</label>\n";
    481     $return .= "</div>\n";
    482     return $return;
     278
     279    ob_start();
     280    $current_screen->render_screen_layout();
     281    $screen_layout = ob_get_clean();
     282
     283    return $screen_layout;
    483284}
    484285
     
    493294 */
    494295function add_screen_option( $option, $args = array() ) {
    495     global $wp_current_screen_options;
    496 
    497     if ( !isset($wp_current_screen_options) )
    498         $wp_current_screen_options = array();
    499 
    500     $wp_current_screen_options[$option] = $args;
    501 }
    502 
     296    $current_screen = get_current_screen();
     297
     298    if ( ! $current_screen )
     299        return;
     300
     301    return $current_screen->add_option( $option, $args );
     302}
     303
     304
     305/**
     306 * Returns the screen's per-page options.
     307 *
     308 * @todo: deprecate?
     309 */
    503310function screen_options($screen) {
    504     global $wp_current_screen_options;
    505 
    506     if ( is_string($screen) )
    507         $screen = convert_to_screen($screen);
    508 
    509     if ( !isset($wp_current_screen_options['per_page']) )
     311    $current_screen = get_current_screen();
     312
     313    if ( ! $current_screen )
    510314        return '';
    511315
    512     $per_page_label = $wp_current_screen_options['per_page']['label'];
    513 
    514     if ( empty($wp_current_screen_options['per_page']['option']) ) {
    515         $option = str_replace( '-', '_', "{$screen->id}_per_page" );
    516     } else {
    517         $option = $wp_current_screen_options['per_page']['option'];
    518     }
    519 
    520     $per_page = (int) get_user_option( $option );
    521     if ( empty( $per_page ) || $per_page < 1 ) {
    522         if ( isset($wp_current_screen_options['per_page']['default']) )
    523             $per_page = $wp_current_screen_options['per_page']['default'];
    524         else
    525             $per_page = 20;
    526     }
    527 
    528     if ( 'edit_comments_per_page' == $option )
    529         $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
    530     elseif ( 'categories_per_page' == $option )
    531         $per_page = apply_filters( 'edit_categories_per_page', $per_page );
    532     else
    533         $per_page = apply_filters( $option, $per_page );
    534 
    535     // Back compat
    536     if ( isset( $screen->post_type ) )
    537         $per_page = apply_filters( 'edit_posts_per_page', $per_page, $screen->post_type );
    538 
    539     $return = "<div class='screen-options'>\n";
    540     if ( !empty($per_page_label) )
    541         $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";
    542     $return .= get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false );
    543     $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
    544     $return .= "</div>\n";
    545     return $return;
     316    ob_start();
     317    $current_screen->render_per_page_options();
     318    $per_page_options = ob_get_clean();
     319
     320    return $per_page_options;
    546321}
    547322
     
    706481     */
    707482    public $taxonomy;
     483
     484    /**
     485     * The help tab data associated with the screen, if any.
     486     *
     487     * @since 3.3.0
     488     * @var array
     489     * @access private
     490     */
     491    public $help_tabs = array();
     492
     493    /**
     494     * The help sidebar data associated with the screen, if any.
     495     *
     496     * @since 3.3.0
     497     * @var string
     498     * @access private
     499     */
     500    public $help_sidebar = '';
     501
     502    /**
     503     * The screen options associated with the screen, if any.
     504     *
     505     * @since 3.3.0
     506     * @var array
     507     * @access private
     508     */
     509    public $options = array();
     510
     511
     512    /**
     513     * Stores the result of the public show_screen_options function.
     514     *
     515     * @since 3.3.0
     516     * @var bool
     517     * @access private
     518     */
     519    private $_show_screen_options;
     520
     521    /**
     522     * Stores the 'screen_settings' section of screen options.
     523     *
     524     * @since 3.3.0
     525     * @var string
     526     * @access private
     527     */
     528    private $_screen_settings;
    708529
    709530    /**
     
    801622     */
    802623    public function add_option( $option, $args = array() ) {
    803         return add_screen_option( $option, $args );
     624        $this->options[ $option ] = $args;
    804625    }
    805626
     
    810631     * @since 3.3.0
    811632     *
    812      * @param string $id Tab ID
    813      * @param string $title Title for the tab
    814      * @param string $content Help tab content in plain text or HTML.
    815      */
    816     public function add_help_tab( $id, $title, $content) {
    817         global $_wp_contextual_help;
    818 
    819         $_wp_contextual_help[$this->id]['tabs'][] = array( $id, $title, $content );
     633     * @param array $args
     634     * - string   - title    - Title for the tab.
     635     * - string   - id       - Tab ID. Optional.
     636     * - string   - content  - Help tab content in plain text or HTML. Optional.
     637     * - callback - callback - A callback to generate the tab content. Optional.
     638     *
     639     */
     640    public function add_help_tab( $args ) {
     641        $defaults = array(
     642            'title'    => false,
     643            'id'       => false,
     644            'content'  => '',
     645            'callback' => false,
     646        );
     647        $args = wp_parse_args( $args, $defaults );
     648
     649        // Ensure we have a title.
     650        if ( ! $args['title'] )
     651            return;
     652
     653        // Create an id from the title if one is not provided.
     654        if ( ! $args['id'] )
     655            $args['id'] = sanitize_html_class( $args['title'] );
     656
     657        $this->help_tabs[] = $args;
    820658    }
    821659
     
    829667     */
    830668    public function add_help_sidebar( $content ) {
     669        $this->help_sidebar = $content;
     670    }
     671
     672    /**
     673     * Render the screen's help section.
     674     *
     675     * This will trigger the deprecated filters for backwards compatibility.
     676     *
     677     * @since 3.3.0
     678     */
     679    public function render_screen_meta() {
    831680        global $_wp_contextual_help;
    832681
    833         $_wp_contextual_help[$this->id]['sidebar'] = $content;
    834     }
    835 }
     682        // Call old contextual_help_list filter.
     683        if ( ! isset( $_wp_contextual_help ) )
     684            $_wp_contextual_help = array();
     685        $_wp_contextual_help = apply_filters( 'contextual_help_list', $_wp_contextual_help, $this );
     686
     687        if ( isset( $_wp_contextual_help[ $this->id ] ) ) {
     688            // Call old contextual_help filter.
     689            $contextual_help = apply_filters( 'contextual_help', $_wp_contextual_help[ $this->id ], $this->id, $this );
     690
     691            $this->add_help_tab( array(
     692                'title'   => __('Screen Info'),
     693                'content' => $contextual_help,
     694            ) );
     695        }
     696
     697        // Add screen options tab
     698        if ( $this->show_screen_options() ) {
     699            $this->add_help_tab( array(
     700                'title'    => __('Screen Options'),
     701                'callback' => array( $this, 'render_screen_options' ),
     702            ) );
     703        }
     704
     705        // Time to render!
     706        ?>
     707        <div id="screen-meta" class='metabox-prefs'>
     708            <div id="contextual-help-wrap" class="hidden">
     709                <ul class="contextual-help-tabs">
     710                    <?php foreach ( $this->help_tabs as $i => $tab ):
     711                        $link_id  = "tab-link-{$tab['id']}";
     712                        $panel_id = "tab-panel-{$tab['id']}";
     713                        $classes  = ( $i == 0 ) ? 'active' : '';
     714                        ?>
     715
     716                        <li id="<?php echo esc_attr( $link_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     717                            <a href="<?php echo esc_url( "#$panel_id" ); ?>">
     718                                <?php echo esc_html( $tab['title'] ); ?>
     719                            </a>
     720                        </li>
     721                    <?php endforeach; ?>
     722                </ul>
     723
     724                <div class="contextual-help-sidebar">
     725                    <?php echo $this->help_sidebar; ?>
     726                </div>
     727
     728                <div class="contextual-help-tabs-wrap">
     729                    <?php foreach ( $this->help_tabs as $i => $tab ):
     730                        $panel_id = "tab-panel-{$tab['id']}";
     731                        $classes  = ( $i == 0 ) ? 'active' : '';
     732                        $classes .= ' help-tab-content';
     733                        ?>
     734
     735                        <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     736                            <h3><?php echo esc_html( $tab['title'] ); ?></h3>
     737                            <?php
     738                            // Print tab content.
     739                            echo $tab['content'];
     740
     741                            // If it exists, fire tab callback.
     742                            if ( ! empty( $tab['callback'] ) )
     743                                call_user_func( $tab['callback'], $this );
     744                            ?>
     745                        </div>
     746                    <?php endforeach; ?>
     747                </div>
     748            </div>
     749        </div>
     750        <?php
     751    }
     752
     753    public function show_screen_options() {
     754        global $wp_meta_boxes, $wp_list_table;
     755
     756        if ( is_bool( $this->_show_screen_options ) )
     757            return $this->_show_screen_options;
     758
     759        $columns = get_column_headers( $this );
     760
     761        $show_screen = false;
     762        if ( ! empty( $wp_meta_boxes[ $this->id ] ) || ! empty( $columns ) )
     763            $show_screen = true;
     764
     765        // Check if there are per-page options.
     766        $show_screen = $show_screen || isset( $this->options['per_page'] );
     767
     768        $this->_screen_settings = apply_filters( 'screen_settings', '', $this );
     769
     770        switch ( $this->id ) {
     771            case 'widgets':
     772                $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";
     773                $show_screen = true;
     774                break;
     775        }
     776
     777        if ( ! empty( $this->_screen_settings ) )
     778            $show_screen = true;
     779
     780        if ( ! empty( $this->options ) )
     781            $show_screen = true;
     782
     783        $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
     784        return $this->_show_screen_options;
     785    }
     786
     787    /**
     788     * Render the screen options tab.
     789     *
     790     * @since 3.3.0
     791     */
     792    public function render_screen_options() {
     793        global $wp_meta_boxes, $wp_list_table;
     794
     795        $columns = get_column_headers( $this );
     796        $hidden  = get_hidden_columns( $this );
     797
     798        ?>
     799        <form id="adv-settings" action="" method="post">
     800        <?php if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?>
     801            <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
     802            <div class="metabox-prefs">
     803                <?php meta_box_prefs( $this ); ?>
     804                <br class="clear" />
     805            </div>
     806            <?php endif;
     807            if ( ! empty( $columns ) ) : ?>
     808            <h5><?php echo ( isset( $columns['_title'] ) ?  $columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
     809            <div class="metabox-prefs">
     810                <?php
     811                $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
     812
     813                foreach ( $columns as $column => $title ) {
     814                    // Can't hide these for they are special
     815                    if ( in_array( $column, $special ) )
     816                        continue;
     817                    if ( empty( $title ) )
     818                        continue;
     819
     820                    if ( 'comments' == $column )
     821                        $title = __( 'Comments' );
     822                    $id = "$column-hide";
     823                    echo '<label for="' . $id . '">';
     824                    echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
     825                    echo "$title</label>\n";
     826                }
     827                ?>
     828                <br class="clear" />
     829            </div>
     830        <?php endif;
     831
     832        $this->render_screen_layout();
     833        $this->render_per_page_options();
     834        echo $this->_screen_settings;
     835
     836        ?>
     837        <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
     838        </form>
     839        <?php
     840    }
     841
     842    function render_screen_layout() {
     843        global $screen_layout_columns;
     844
     845        // Back compat for plugins using the filter instead of add_screen_option()
     846        $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
     847
     848        if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
     849            add_screen_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
     850
     851        if ( ! isset( $this->options['layout_columns'] ) ) {
     852            $screen_layout_columns = 0;
     853            return;
     854        }
     855
     856        $screen_layout_columns = get_user_option("screen_layout_$this->id");
     857        $num = $this->options['layout_columns']['max'];
     858
     859        if ( ! $screen_layout_columns ) {
     860            if ( isset( $this->options['layout_columns']['default'] ) )
     861                $screen_layout_columns = $this->options['layout_columns']['default'];
     862            else
     863                $screen_layout_columns = 'auto';
     864        }
     865
     866        ?>
     867        <h5><?php _e('Screen Layout'); ?></h5>
     868        <div class='columns-prefs'><?php
     869            _e('Number of Columns:');
     870            for ( $i = 1; $i <= $num; ++$i ):
     871                ?>
     872                <label>
     873                    <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
     874                        <?php checked( $screen_layout_columns, $i ); ?> />
     875                    <?php echo esc_html( $i ); ?>
     876                </label>
     877                <?php
     878            endfor; ?>
     879            <label>
     880                <input type='radio' id='wp_auto_columns' name='screen_columns' value='auto'
     881                    <?php checked( $screen_layout_columns, 'auto' ); ?> />
     882                <?php esc_html_e('Auto'); ?>
     883            </label>
     884        </div>
     885        <?php
     886    }
     887
     888    function render_per_page_options() {
     889        if ( ! isset( $this->options['per_page'] ) )
     890            return;
     891
     892        $per_page_label = $this->options['per_page']['label'];
     893
     894        if ( empty( $this->options['per_page']['option'] ) ) {
     895            $option = str_replace( '-', '_', "{$this->id}_per_page" );
     896        } else {
     897            $option = $this->options['per_page']['option'];
     898        }
     899
     900        $per_page = (int) get_user_option( $option );
     901        if ( empty( $per_page ) || $per_page < 1 ) {
     902            if ( isset($this->options['per_page']['default']) )
     903                $per_page = $this->options['per_page']['default'];
     904            else
     905                $per_page = 20;
     906        }
     907
     908        if ( 'edit_comments_per_page' == $option ) {
     909            $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
     910            $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
     911        } elseif ( 'categories_per_page' == $option ) {
     912            $per_page = apply_filters( 'edit_categories_per_page', $per_page );
     913        } else {
     914            $per_page = apply_filters( $option, $per_page );
     915        }
     916
     917        // Back compat
     918        if ( isset( $this->post_type ) )
     919            $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
     920
     921        ?>
     922        <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
     923        <div class='screen-options'>
     924            <?php if ( !empty($per_page_label) ): ?>
     925                <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>
     926            <?php endif;
     927
     928            echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
     929            <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' />
     930        </div>
     931        <?php
     932    }
     933}
Note: See TracChangeset for help on using the changeset viewer.