WordPress.org

Make WordPress Core

Changeset 34360


Ignore:
Timestamp:
09/20/2015 05:27:35 PM (6 years ago)
Author:
johnbillion
Message:

Implement a 'Mine' link on post listing screens in the admin area for all users who have authored posts. This feature was previously only available to users who cannot edit other users' posts (namely Authors and Contributors).

Props linuxologos, wonderboymusic
Fixes #19609

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r34331 r34360  
    7878        ) );
    7979
    80         $post_type = $this->screen->post_type;
     80        $post_type        = $this->screen->post_type;
    8181        $post_type_object = get_post_type_object( $post_type );
    82 
    83         if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
    84             $exclude_states = get_post_stati( array( 'show_in_admin_all_list' => false ) );
    85             $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
    86                 SELECT COUNT( 1 ) FROM $wpdb->posts
    87                 WHERE post_type = %s AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
    88                 AND post_author = %d
    89             ", $post_type, get_current_user_id() ) );
    90 
    91             if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
    92                 $_GET['author'] = get_current_user_id();
     82        $exclude_states   = get_post_stati( array(
     83            'show_in_admin_all_list' => false,
     84        ) );
     85        $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
     86            SELECT COUNT( 1 )
     87            FROM $wpdb->posts
     88            WHERE post_type = %s
     89            AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
     90            AND post_author = %d
     91        ", $post_type, get_current_user_id() ) );
     92
     93        if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
     94            $_GET['author'] = get_current_user_id();
    9395        }
    9496
     
    263265        $current_user_id = get_current_user_id();
    264266        $all_args = array( 'post_type' => $post_type );
     267        $mine = '';
    265268
    266269        if ( $this->user_posts_count ) {
     
    284287            );
    285288
    286             $status_links['mine'] = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
     289            $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
    287290
    288291            $all_args['all_posts'] = 1;
     
    311314
    312315        $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
     316        if ( $mine ) {
     317            $status_links['mine'] = $mine;
     318        }
    313319
    314320        foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
Note: See TracChangeset for help on using the changeset viewer.