Make WordPress Core


Ignore:
Timestamp:
10/03/2006 03:40:26 PM (18 years ago)
Author:
ryan
Message:

Pageinate upload tabs. From the Paginator, mdawaffe. fixes #3193

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upload.php

    r4274 r4276  
    2525$all_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'");
    2626$post_atts = 0;
     27
    2728if ( $pid ) {
    28     $wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload');
     29    // 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args
     30    $wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0);
    2931    if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
    30         $wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse");
     32        $wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts);
    3133    if ( $post_atts < $all_atts )
    32         $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
     34        $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
    3335} else
    34     $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse');
     36    $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
    3537
    3638    $wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() ));
     
    5557foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check
    5658    $class = 'upload-tab';
    57     $href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '') );
    58     if ( isset($tab_array[3]) && is_array($tab_array[3]) )
    59         add_query_arg( $tab_array[3], $href );
     59    $href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '', 'paged' => '') );
     60    if ( isset($tab_array[4]) && is_array($tab_array[4]) )
     61        add_query_arg( $tab_array[4], $href );
    6062    $_href = wp_specialchars( $href, 1 );
    61     if ( $tab == $t )
     63    $page_links = '';
     64    if ( $tab == $t ) {
    6265        $class .= ' current';
    63     echo "\t<li class='$class left'><a href='$_href' title='{$tab_array[0]}'>{$tab_array[0]}</a></li>\n";
     66        if ( $tab_array[3] ) {
     67            if ( is_array($tab_array[3]) ) {
     68                $total = $tab_array[3][0];
     69                $per = $tab_array[3][1];
     70            } else {
     71                $total = $tab_array[3];
     72                $per = 10;
     73            }
     74            $page_links = paginate_links( array(
     75                'base' => add_query_arg( 'paged', '%#%' ),
     76                'format' => '',
     77                'total' => ceil($total / $per),
     78                'current' => $paged ? $paged : 1,
     79                'prev_text' => '&laquo;',
     80                'next_text' => '&raquo;'
     81            ));
     82            if ( $page_links )
     83                $page_links = "<span id='current-tab-nav'>: $page_links</span>";
     84        }
     85    }
     86
     87    echo "\t<li class='$class left'><div><a href='$_href' title='{$tab_array[0]}'>{$tab_array[0]}</a>$page_links</div></li>\n";
    6488}
     89unset($t, $tab_array, $href, $_href, $page_links, $total, $per, $class);
    6590echo "</ul>\n\n";
    6691
Note: See TracChangeset for help on using the changeset viewer.