Making WordPress.org


Ignore:
Timestamp:
03/30/2023 03:37:47 AM (16 months ago)
Author:
dd32
Message:

Plugin Directory: Administration: Add bulk actions for close/disable/open.

This streamlines administration of cases where a large group of plugins need to be disabled or re-opened.

Fixes #6903.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php

    r12325 r12517  
    8181        if ( current_user_can( 'plugin_reject' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'new', 'pending' ) ) ) ) {
    8282            $actions['plugin_reject'] = __( 'Reject', 'wporg-plugins' );
     83        }
     84
     85        if ( current_user_can( 'plugin_approve' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'closed', 'disabled' ) ) ) ) {
     86            $actions['plugin_open'] = __( 'Open', 'wporg-plugins' );
     87        }
     88
     89        if ( current_user_can( 'plugin_close' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'publish', 'approved', 'disabled' ) ) ) ) {
     90            $actions['plugin_close'] = __( 'Close', 'wporg-plugins' );
     91        }
     92
     93        if ( current_user_can( 'plugin_close' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'publish', 'approved', 'closed' ) ) ) ) {
     94            $actions['plugin_disable'] = __( 'Disable', 'wporg-plugins' );
    8395        }
    8496
     
    500512        return $status_links;
    501513    }
     514
     515    /**
     516     * Display the "actions" fields below the filters.
     517     */
     518    public function extra_tablenav( $which ) {
     519        parent::extra_tablenav( $which );
     520
     521        // TODO: This shouldn't have inline CSS/JS.
     522
     523        if ( 'top' === $which ) {
     524            ?>
     525            <fieldset class="alignleft actions hide-if-js bulk-plugin_close bulk-plugin_disable" disabled="disabled">
     526                <select name="close_reason" id="close_reason">
     527                    <option disabled="disabled" value='' selected="selected"><?php esc_html_e( 'Close/Disable Reason:', 'wporg-plugins' ); ?></option>
     528                    <?php foreach ( Template::get_close_reasons() as $key => $label ) : ?>
     529                        <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></option>
     530                    <?php endforeach; ?>
     531                </select>
     532            </fieldset>
     533            <style>
     534                #posts-filter fieldset.bulk-plugin_close {
     535                    margin: 0;
     536                }
     537            </style>
     538            <script>
     539            jQuery( function( $ ) {
     540                $( '.bulkactions' ).on( 'change', function() {
     541                    var $this = $( this ),
     542                        val = $this.find(':selected').val(),
     543                        $tablenav = $this.parents('form').find( '.tablenav.top' );
     544
     545                    $tablenav.find( '.actions.bulk-plugin_close, .actions.bulk-plugin_disable' ).prop( 'disabled', true ).hide();
     546                    $tablenav.find( '.actions.bulk-' + val ).prop( 'disabled', false ).show();
     547                } );
     548            } );
     549            </script>
     550            <?php
     551        }
     552    }
    502553}
Note: See TracChangeset for help on using the changeset viewer.