Make WordPress Core

Changeset 11843


Ignore:
Timestamp:
08/19/2009 10:37:51 PM (15 years ago)
Author:
azaozz
Message:

Show My Posts as default view on the Edit Posts screen for users without 'edit_others_posts' cap.

File:
1 edited

Legend:

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

    r11807 r11843  
    113113wp_enqueue_script('inline-edit-post');
    114114
     115$user_posts = false;
     116if ( !current_user_can('edit_others_posts') ) {
     117    $user_posts_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(1) FROM $wpdb->posts WHERE post_type = 'post' AND post_status != 'trash' AND post_author = %d", $current_user->ID) );
     118    $user_posts = true;
     119    if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) )
     120        $_GET['author'] = $current_user->ID;
     121}
     122
    115123list($post_stati, $avail_post_stati) = wp_edit_posts_query();
    116124
     
    180188$status_links = array();
    181189$num_posts = wp_count_posts( 'post', 'readable' );
     190$class = '';
     191$allposts = '';
     192
     193if ( $user_posts ) {
     194    if ( $_GET['author'] == $current_user->ID )
     195        $class = ' class="current"';
     196    $status_links[] = "<li><a href='edit.php?author=$current_user->ID'$class>" . sprintf( _nx( 'My Posts <span class="count">(%s)</span>', 'My Posts <span class="count">(%s)</span>', $user_posts_count, 'posts' ), number_format_i18n( $user_posts_count ) ) . '</a>';
     197    $allposts = '?all_posts=1';
     198}
     199
    182200$total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
    183 $class = empty( $_GET['post_status'] ) ? ' class="current"' : '';
    184 $status_links[] = "<li><a href='edit.php' $class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
    185 
     201$class = empty($class) && empty($_GET['post_status']) ? ' class="current"' : '';
     202$status_links[] = "<li><a href='edit.php{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
    186203
    187204foreach ( $post_stati as $status => $label ) {
     
    193210    if ( empty( $num_posts->$status ) )
    194211        continue;
     212
    195213    if ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
    196214        $class = ' class="current"';
    197215
    198     $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>';
     216    $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>';
    199217}
    200218echo implode( " |</li>\n", $status_links ) . '</li>';
     
    340358<?php } else { // have_posts() ?>
    341359<div class="clear"></div>
    342 <p><?php _e('No posts found') ?></p>
     360<p><?php
     361if ( 'trash' == $_GET['post_status'] )
     362    _e('No posts found in the trash');
     363else
     364    _e('No posts found');
     365?></p>
    343366<?php } ?>
    344367
     
    348371
    349372<div id="ajax-response"></div>
    350 
    351373<br class="clear" />
    352 
    353374</div>
    354375
Note: See TracChangeset for help on using the changeset viewer.