Making WordPress.org

Changeset 6034


Ignore:
Timestamp:
10/16/2017 12:35:07 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Provide the ability to specify a reason when closing or disabling a plugin.

Props jdgrimes.
See #2860.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin
Files:
2 edited

Legend:

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

    r5997 r6034  
    4141        add_filter( 'wp_unique_post_slug', array( $this, 'check_existing_plugin_slug_on_inline_save' ), 10, 6 );
    4242
     43        add_action( 'save_post', array( $this, 'save_close_reason' ), 10, 2 );
     44
    4345        add_action( 'wp_ajax_replyto-comment', array( $this, 'save_custom_comment' ), 0 );
    4446        add_filter( 'comment_row_actions', array( $this, 'custom_comment_row_actions' ), 10, 2 );
     
    5153        add_filter( 'postbox_classes_plugin_internal-notes',      array( __NAMESPACE__ . '\Metabox\Internal_Notes', 'postbox_classes' ) );
    5254        add_filter( 'postbox_classes_plugin_plugin-committers',   array( __NAMESPACE__ . '\Metabox\Committers',     'postbox_classes' ) );
    53         add_filter( 'postbox_classes_plugin_plugin-support-reps', array( __NAMESPACE__ . '\Metabox\Support_Reps',     'postbox_classes' ) );
    54         add_filter( 'wp_ajax_add-committer',        array( __NAMESPACE__ . '\Metabox\Committers', 'add_committer'    ) );
     55        add_filter( 'postbox_classes_plugin_plugin-support-reps', array( __NAMESPACE__ . '\Metabox\Support_Reps',   'postbox_classes' ) );
     56        add_filter( 'wp_ajax_add-committer',        array( __NAMESPACE__ . '\Metabox\Committers', 'add_committer' ) );
    5557        add_filter( 'wp_ajax_delete-committer',     array( __NAMESPACE__ . '\Metabox\Committers', 'remove_committer' ) );
    5658        add_filter( 'wp_ajax_add-support-rep',      array( __NAMESPACE__ . '\Metabox\Support_Reps', 'add_support_rep' ) );
    5759        add_filter( 'wp_ajax_delete-support-rep',   array( __NAMESPACE__ . '\Metabox\Support_Reps', 'remove_support_rep' ) );
    5860        add_action( 'wp_ajax_plugin-author-lookup', array( __NAMESPACE__ . '\Metabox\Author', 'lookup_author' ) );
    59 
    6061    }
    6162
     
    378379
    379380    /**
     381     * Save the reason for closing or disabling a plugin.
     382     *
     383     * @param int      $post_id Post ID.
     384     * @param \WP_Post $post    Post object.
     385     */
     386    public function save_close_reason( $post_id, $post ) {
     387        if ( 'plugin' !== $post->post_type || ! isset( $_POST['close_reason'] ) ) {
     388            return;
     389        }
     390
     391        if ( ! current_user_can( 'plugin_approve', $post_id ) ) {
     392            return;
     393        }
     394
     395        if ( ! in_array( $post->post_status, array( 'closed', 'disabled' ) ) ) {
     396            return;
     397        }
     398
     399        update_post_meta( $post_id, '_close_reason', sanitize_key( $_POST['close_reason'] ) );
     400    }
     401
     402    /**
    380403     * Register the Admin metaboxes for the plugin management screens.
    381404     *
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-controls.php

    r5715 r6034  
    1515     */
    1616    static function display() {
    17         echo '<div class="submitbox" id="submitpost">';
    18             echo '<div id="misc-publishing-actions">';
     17        ?>
     18        <div class="submitbox" id="submitpost">
     19            <div id="misc-publishing-actions">
     20                <?php
    1921                self::display_post_status();
    2022
     
    2224                    self::display_tested_up_to();
    2325                }
    24             echo '</div>';
     26                ?>
     27            </div>
    2528
    26             echo '<div id="major-publishing-actions"><div id="publishing-action">';
    27                 echo '<span class="spinner"></span>';
    28                 printf( '<input type="submit" name="save_changes" id="publish" class="button button-primary button-large" value="%s">', __( 'Save Changes', 'wporg-plugins' ) );
    29             echo '</div><div class="clear"></div></div>';
    30         echo '</div>';
     29            <div id="major-publishing-actions">
     30                <div id="publishing-action">
     31                    <span class="spinner"></span>
     32                    <input type="submit" name="save_changes" id="publish" class="button button-primary button-large" value="<?php esc_attr_e( 'Save Changes', 'wporg-plugins' ); ?>">
     33                </div>
     34                <div class="clear"></div>
     35            </div>
     36        </div>
     37        <?php
    3138    }
    3239
     
    6673
    6774    /**
     75     * Get reasons for closing or disabling a plugin.
     76     *
     77     * @return array Close/disable reason labels.
     78     */
     79    public static function get_close_reasons() {
     80        return array(
     81            'security-issue'                => __( 'Security Issue', 'wporg-plugins' ),
     82            'author-request'                => __( 'Author Request', 'wporg-plugins' ),
     83            'guideline-violation'           => __( 'Guideline Violation', 'wporg-plugins' ),
     84            'licensing-trademark-violation' => __( 'Licensing/Trademark Violation', 'wporg-plugins' ),
     85            'merged-into-core'              => __( 'Merged into Core', 'wporg-plugins' ),
     86        );
     87    }
     88
     89    /**
    6890     * Displays the Plugin Status control in the Publish metabox.
    6991     */
     
    81103            $statuses = Status_Transitions::get_allowed_transitions( $post->post_status );
    82104        }
     105
     106        $close_reasons = self::get_close_reasons();
     107        $close_reason  = (string) get_post_meta( $post->ID, '_close_reason', true );
     108
     109        if ( isset( $close_reasons[ $close_reason ] ) ) {
     110            $reason_label   = $close_reasons[ $close_reason ];
     111            $reason_unknown = false;
     112        } else {
     113            $reason_label   = _x( 'Unknown', 'unknown close reason', 'wporg-plugins' );
     114            $reason_unknown = true;
     115        }
    83116        ?>
    84117        <div class="misc-pub-section misc-pub-plugin-status">
     
    86119            <strong id="plugin-status-display"><?php echo esc_html( get_post_status_object( $post->post_status )->label ); ?></strong>
    87120
     121            <?php if ( 'closed' === $post->post_status ) : ?>
     122
     123                <p><?php printf( __( 'Close Reason: %s', 'wporg-plugins' ), '<strong>' . $reason_label . '</strong>' ); ?></p>
     124
     125            <?php elseif ( 'disabled' === $post->post_status ) : ?>
     126
     127                <p><?php printf( __( 'Disable Reason: %s', 'wporg-plugins' ), '<strong>' . $reason_label . '</strong>' ); ?></p>
     128
     129            <?php endif; ?>
     130
     131            <?php if (
     132                    ( in_array( 'closed', $statuses, true ) || in_array( 'disabled', $statuses, true ) )
     133                &&
     134                    ! in_array( $post->post_status, array( 'closed', 'disabled' ) ) || $reason_unknown
     135                ) : ?>
     136
     137                <p>
     138                    <label for="close_reason"><?php _e( 'Close/Disable Reason:', 'wporg-plugins' ); ?></label>
     139                    <select name="close_reason" id="close_reason">
     140                        <?php foreach ( $close_reasons as $key => $label ) : ?>
     141                            <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $close_reason ); ?>><?php echo esc_html( $label ); ?></option>
     142                        <?php endforeach; ?>
     143                    </select>
     144                </p>
     145
     146            <?php endif; ?>
     147
    88148            <?php foreach ( $statuses as $status ) : ?>
     149
    89150                <p><button type="submit" name="post_status" value="<?php echo esc_attr( $status ); ?>" class="button set-plugin-status">
    90151                    <?php echo self::get_status_button_label( $status ); ?>
    91152                </button></p>
     153
    92154            <?php endforeach; ?>
    93155        </div><!-- .misc-pub-section --><?php
Note: See TracChangeset for help on using the changeset viewer.