Make WordPress Core

Ticket #9582: edit_posts_links.patch

File edit_posts_links.patch, 10.4 KB (added by scribu, 17 years ago)

Use wp_filter_links() on edit.php, edit-pages.php

  • home/cristi/svn/wp/wp-admin/includes/post.php

     
    789789                $q = $_GET;
    790790        $q['m']   = isset($q['m']) ? (int) $q['m'] : 0;
    791791        $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
    792         $post_stati  = array(   //      array( adj, noun )
    793                                 'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
    794                                 'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
    795                                 'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
    796                                 'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
    797                                 'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
    798                         );
     792        $post_statuses  = array(        //      array( adj, noun )
     793                'publish' => array(_x('Published', 'post'), __('Published posts')),
     794                'future' => array(_x('Scheduled', 'post'), __('Scheduled posts')),
     795                'pending' => array(_x('Pending Review', 'post'), __('Pending posts')),
     796                'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header')),
     797                'private' => array(_x('Private', 'post'), __('Private posts')),
     798        );
    799799
    800         $post_stati = apply_filters('post_stati', $post_stati);
     800        $post_statuses = apply_filters('post_statuses', $post_statuses);
    801801
    802         $avail_post_stati = get_available_post_statuses('post');
     802        $avail_post_statuses = get_available_post_statuses('post');
    803803
    804804        $post_status_q = '';
    805         if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_stati) ) ) {
     805        if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_statuses) ) ) {
    806806                $post_status_q = '&post_status=' . $q['post_status'];
    807807                $post_status_q .= '&perm=readable';
    808808        }
     
    825825
    826826        wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby");
    827827
    828         return array($post_stati, $avail_post_stati);
     828        return array($post_statuses, $avail_post_statuses);
    829829}
    830830
    831831/**
  • home/cristi/svn/wp/wp-admin/includes/template.php

     
    37153715<?php
    37163716}
    37173717
     3718/**
     3719 * Generates filter links for various admin pages.
     3720 *
     3721 * @since 2.8.0
     3722 */
     3723function wp_filter_links($links) {
     3724        $tmp = array();
     3725
     3726        foreach ( $links as $link => $link_format ) {
     3727                $class = $link_format['cond'] ? 'class="current"' : '';
     3728
     3729                if ( isset($link_format['count']) )
     3730                        $count = sprintf(" <span class='count'>(%s)</span>", number_format_i18n($link_format['count']) );
     3731                else
     3732                        $count = '';
     3733
     3734                $tmp[] = sprintf("<li><a href='$link' $class>%s</a>", $link_format['title'] . $count );
     3735        }
     3736
     3737        return implode( " |</li>\n", $tmp ) . '</li>';
     3738}
     3739
    37183740?>
  • home/cristi/svn/wp/wp-admin/edit.php

     
    8282$parent_file = 'edit.php';
    8383wp_enqueue_script('inline-edit-post');
    8484
    85 list($post_stati, $avail_post_stati) = wp_edit_posts_query();
    86 
    8785require_once('admin-header.php');
    8886
    8987if ( !isset( $_GET['paged'] ) )
     
    137135<ul class="subsubsub">
    138136<?php
    139137if ( empty($locked_post_status) ) :
    140 $status_links = array();
     138$edit_posts_links = array();
    141139$num_posts = wp_count_posts( 'post', 'readable' );
    142 $total_posts = array_sum( (array) $num_posts );
    143 $class = empty( $_GET['post_status'] ) ? ' class="current"' : '';
    144 $status_links[] = "<li><a href='edit.php' $class>" . sprintf( _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts ), number_format_i18n( $total_posts ) ) . '</a>';
     140$edit_posts_links['edit.php'] = array(
     141        'title' => __( 'All' ),
     142        'count' => array_sum( (array) $num_posts ),
     143        'cond' => ( count( $_GET ) <= 1 )
     144);
    145145
     146global $user_ID, $wpdb;
     147$my_posts_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_author = $user_ID");
     148$edit_posts_links["edit.php?author=$user_ID"] = array(
     149        'title' => __('My posts'),
     150        'count' => $my_posts_count,
     151        'cond' => ( isset($_GET['author']) && $user_ID == $_GET['author'] )
     152);
    146153
    147 foreach ( $post_stati as $status => $label ) {
    148         $class = '';
     154list($post_statuses, $avail_post_statuses) = wp_edit_posts_query();
    149155
    150         if ( !in_array( $status, $avail_post_stati ) )
     156foreach ( $post_statuses as $status => $label ) {
     157        if ( !in_array( $status, $avail_post_statuses ) )
    151158                continue;
    152159
    153160        if ( empty( $num_posts->$status ) )
    154161                continue;
    155         if ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
    156                 $class = ' class="current"';
    157162
    158         $status_links[] = "<li><a href='edit.php?post_status=$status' $class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
     163        $edit_posts_links["edit.php?post_status=$status"] = array(
     164                'title' => $label[0],
     165                'count' => $num_posts->$status,
     166                'cond' => ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
     167        );
    159168}
    160 echo implode( " |</li>\n", $status_links ) . '</li>';
    161 unset( $status_links );
     169
     170$edit_posts_links = apply_filters('edit_posts_links', $edit_posts_links);
     171
     172echo wp_filter_links($edit_posts_links);
     173
    162174endif;
    163175?>
    164176</ul>
  • home/cristi/svn/wp/wp-admin/edit-pages.php

     
    7474$parent_file = 'edit-pages.php';
    7575wp_enqueue_script('inline-edit-post');
    7676
    77 $post_stati  = array(   //      array( adj, noun )
    78                 'publish' => array(_x('Published', 'page'), __('Published pages'), _nx_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>', 'page')),
    79                 'future' => array(_x('Scheduled', 'page'), __('Scheduled pages'), _nx_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>', 'page')),
    80                 'pending' => array(_x('Pending Review', 'page'), __('Pending pages'), _nx_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>', 'page')),
    81                 'draft' => array(_x('Draft', 'page'), _x('Drafts', 'manage posts header'), _nx_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>', 'page')),
    82                 'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', 'page'))
    83         );
     77$post_statuses  = array(        //      array( adj, noun )
     78        'publish' => array(_x('Published', 'page'), __('Published pages')),
     79        'future' => array(_x('Scheduled', 'page'), __('Scheduled pages')),
     80        'pending' => array(_x('Pending Review', 'page'), __('Pending pages')),
     81        'draft' => array(_x('Draft', 'page'), _x('Drafts', 'manage posts header')),
     82        'private' => array(_x('Private', 'page'), __('Private pages'))
     83);
    8484
     85$post_statuses = apply_filters('page_statuses', $post_statuses);
     86
    8587$query = array('post_type' => 'page', 'orderby' => 'menu_order title', 'what_to_show' => 'posts',
    8688        'posts_per_page' => -1, 'posts_per_archive_page' => -1, 'order' => 'asc');
    8789
    8890$post_status_label = __('Pages');
    89 if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
    90         $post_status_label = $post_stati[$_GET['post_status']][1];
     91if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_statuses) ) ) {
     92        $post_status_label = $post_statuses[$_GET['post_status']][1];
    9193        $query['post_status'] = $_GET['post_status'];
    9294        $query['perm'] = 'readable';
    9395}
     
    141143endif; ?>
    142144
    143145<form id="posts-filter" action="" method="get">
     146
    144147<ul class="subsubsub">
    145148<?php
    146 
    147 $avail_post_stati = get_available_post_statuses('page');
    148149if ( empty($locked_post_status) ) :
    149 $status_links = array();
    150 $num_posts = wp_count_posts('page', 'readable');
    151 $total_posts = array_sum( (array) $num_posts );
    152 $class = empty($_GET['post_status']) ? ' class="current"' : '';
    153 $status_links[] = "<li><a href='edit-pages.php'$class>" . sprintf( _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts ), number_format_i18n( $total_posts ) ) . '</a>';
    154 foreach ( $post_stati as $status => $label ) {
    155         $class = '';
     150$edit_posts_links = array();
     151$num_posts = wp_count_posts( 'page', 'readable' );
     152$edit_posts_links['edit-pages.php'] = array(
     153        'title' => __( 'All' ),
     154        'count' => array_sum( (array) $num_posts ),
     155        'cond' => ( count( $_GET ) == 0 )
     156);
    156157
    157         if ( !in_array($status, $avail_post_stati) )
     158global $user_ID, $wpdb;
     159$my_posts_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_author = $user_ID");
     160$edit_posts_links["edit-pages.php?author=$user_ID"] = array(
     161        'title' => __('My pages'),
     162        'count' => $my_posts_count,
     163        'cond' => ( isset($_GET['author']) && $user_ID == $_GET['author'] )
     164);
     165
     166$avail_post_statuses = get_available_post_statuses('page');
     167
     168foreach ( $post_statuses as $status => $label ) {
     169        if ( !in_array( $status, $avail_post_statuses ) )
    158170                continue;
    159171
    160         if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] )
    161                 $class = ' class="current"';
     172        if ( empty( $num_posts->$status ) )
     173                continue;
    162174
    163         $status_links[] = "<li><a href='edit-pages.php?post_status=$status'$class>" . sprintf( _nx( $label[2][0], $label[2][1], $num_posts->$status, $label[2][2] ), number_format_i18n( $num_posts->$status ) ) . '</a>';
     175        $edit_posts_links["edit-pages.php?post_status=$status"] = array(
     176                'title' => $label[0],
     177                'count' => $num_posts->$status,
     178                'cond' => ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
     179        );
    164180}
    165 echo implode( " |</li>\n", $status_links ) . '</li>';
    166 unset($status_links);
     181
     182$edit_posts_links = apply_filters('edit_posts_links', $edit_posts_links);
     183
     184echo wp_filter_links($edit_posts_links);
     185
    167186endif;
    168187?>
    169188</ul>