Make WordPress Core

Changeset 53105

Timestamp:
04/08/2022 06:24:32 AM (2 years ago)
Author:
peterwilsoncc
Message:

Users: Prevent author changes in bulk editor on large sites.

On large sites (with over 1000 users), include a hidden post_author field in the bulk editing interface to preven unexpected authorship changes.

Follow up to [53011], [53049].

Props georgestephanis, tobifjellner, peterwilsoncc, spacedmonkey, jb510.
Fixes #38741.

File:
1 edited

Legend:

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

    r53096 r53105  
    16541654
    16551655                <?php
    1656                 if ( post_type_supports( $screen->post_type, 'author' ) && ! wp_is_large_user_count() ) {
     1656                if ( post_type_supports( $screen->post_type, 'author' ) ) {
    16571657                    $authors_dropdown = '';
    16581658
    16591659                    if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) {
    1660                         $users_opt = array(
    1661                             'hide_if_only_one_author' => false,
    1662                             'capability'              => array( $post_type_object->cap->edit_posts ),
    1663                             'name'                    => 'post_author',
    1664                             'class'                   => 'authors',
    1665                             'multi'                   => 1,
    1666                             'echo'                    => 0,
    1667                             'show'                    => 'display_name_with_login',
    1668                         );
    1669 
    1670                         if ( $bulk ) {
    1671                             $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
    1672                         }
    1673 
    1674                         /**
    1675                          * Filters the arguments used to generate the Quick Edit authors drop-down.
    1676                          *
    1677                          * @since 5.6.0
    1678                          *
    1679                          * @see wp_dropdown_users()
    1680                          *
    1681                          * @param array $users_opt An array of arguments passed to wp_dropdown_users().
    1682                          * @param bool  $bulk      A flag to denote if it's a bulk action.
    1683                          */
    1684                         $users_opt = apply_filters( 'quick_edit_dropdown_authors_args', $users_opt, $bulk );
    1685 
    1686                         $authors = wp_dropdown_users( $users_opt );
    1687 
    1688                         if ( $authors ) {
    1689                             $authors_dropdown  = '<label class="inline-edit-author">';
    1690                             $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
    1691                             $authors_dropdown .= $authors;
    1692                             $authors_dropdown .= '</label>';
     1660                        $dropdown_name  = 'post_author';
     1661                        $dropdown_class = 'authors';
     1662                        if ( wp_is_large_user_count() ) {
     1663                            $authors_dropdown = sprintf( '<select name="%s" class="%s hidden"></select>', esc_attr( $dropdown_name ), esc_attr( $dropdown_class ) );
     1664                        } else {
     1665                            $users_opt = array(
     1666                                'hide_if_only_one_author' => false,
     1667                                'capability'              => array( $post_type_object->cap->edit_posts ),
     1668                                'name'                    => $dropdown_name,
     1669                                'class'                   => $dropdown_class,
     1670                                'multi'                   => 1,
     1671                                'echo'                    => 0,
     1672                                'show'                    => 'display_name_with_login',
     1673                            );
     1674
     1675                            if ( $bulk ) {
     1676                                $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
     1677                            }
     1678
     1679                            /**
     1680                             * Filters the arguments used to generate the Quick Edit authors drop-down.
     1681                             *
     1682                             * @since 5.6.0
     1683                             *
     1684                             * @see wp_dropdown_users()
     1685                             *
     1686                             * @param array $users_opt An array of arguments passed to wp_dropdown_users().
     1687                             * @param bool $bulk A flag to denote if it's a bulk action.
     1688                             */
     1689                            $users_opt = apply_filters( 'quick_edit_dropdown_authors_args', $users_opt, $bulk );
     1690
     1691                            $authors = wp_dropdown_users( $users_opt );
     1692
     1693                            if ( $authors ) {
     1694                                $authors_dropdown  = '<label class="inline-edit-author">';
     1695                                $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
     1696                                $authors_dropdown .= $authors;
     1697                                $authors_dropdown .= '</label>';
     1698                            }
    16931699                        }
    16941700                    } // current_user_can( 'edit_others_posts' )
     
    17491755
    17501756                <?php
    1751                 if ( post_type_supports( $screen->post_type, 'author' ) && ! wp_is_large_user_count() && $bulk ) {
     1757                if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) {
    17521758                    echo $authors_dropdown;
    17531759                }
Note: See TracChangeset for help on using the changeset viewer.