Making WordPress.org

Ticket #5303: 5303-self-service-add-remove-plugin.diff

File 5303-self-service-add-remove-plugin.diff, 2.9 KB (added by tellyworth, 3 years ago)

Allow plugin committers to add or remove their plugins from the block directory

  • shortcodes/class-block-validator.php

     
    33
    44use WordPressdotorg\Plugin_Directory\CLI\Block_Plugin_Checker;
    55use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     6use WordPressdotorg\Plugin_Directory\Tools;
    67
    78class Block_Validator {
    89
     
    3233                        } elseif ( $_POST && ! empty( $_POST['block-directory-edit'] ) ) {
    3334                                $post = get_post( intval( $_POST['plugin-id'] ) );
    3435                                if ( $post && wp_verify_nonce( $_POST['block-directory-nonce'], 'block-directory-edit-' . $post->ID ) ) {
    35                                         if ( current_user_can( 'edit_post', $post->ID ) ) {
     36                                        if ( current_user_can( 'edit_post', $post->ID ) || current_user_can( 'plugin_admin_edit', $post->ID ) ) {
    3637                                                $terms = wp_list_pluck( get_the_terms( $post->ID, 'plugin_section' ), 'slug' );
    3738                                                if ( 'add' === $_POST['block-directory-edit'] ) {
    3839                                                        $terms[] = 'block';
     
    100101                if ( $checker->slug ) {
    101102                        $plugin = Plugin_Directory::get_plugin_post( $checker->slug );
    102103                        if ( current_user_can( 'edit_post', $plugin->ID ) ) {
     104                                // Plugin reviewers etc
    103105                                echo '<form method="post">';
    104106                                echo '<h3>' . __( 'Plugin Review Tools', 'wporg-plugins' ) . '</h3>';
    105107                                echo wp_nonce_field( 'block-directory-edit-' . $plugin->ID, 'block-directory-nonce' );
     
    120122                                echo '<ul><li><a href="' . get_edit_post_link( $plugin->ID ) . '">' . __( 'Edit plugin', 'wporg-plugins' ) . '</a></li>';
    121123                                echo '<li><a href="' . esc_url( 'https://plugins.trac.wordpress.org/browser/' . $checker->slug . '/trunk' ) . '">' . __( 'Trac browser', 'wporg-plugins' ) . '</a></li></ul>';
    122124                                echo '</form>';
     125                        } elseif ( current_user_can( 'plugin_admin_edit', $plugin->ID ) ) {
     126                                // Plugin committers
     127                                echo '<form method="post">';
     128                                echo '<h3>' . __( 'Committer Tools', 'wporg-plugins' ) . '</h3>';
     129                                echo wp_nonce_field( 'block-directory-edit-' . $plugin->ID, 'block-directory-nonce' );
     130                                echo '<input type="hidden" name="plugin-id" value="' . esc_attr( $plugin->ID ) . '" />';
     131                                echo '<p>';
     132                                if ( ! empty( $results_by_type['error'] ) ) {
     133                                        // translators: %s plugin title.
     134                                        printf( __( "%s can't be added to the block directory, due to errors in validation.", 'wporg-plugins' ), $plugin->post_title );
     135                                } else if ( self::plugin_is_in_block_directory( $checker->slug ) ) {
     136                                        // translators: %s plugin title.
     137                                        echo '<button type="submit" name="block-directory-edit" value="remove">' . sprintf( __( 'Remove %s from Block Directory', 'wporg-plugins' ), $plugin->post_title ) . '</button>';
     138                                } else {
     139                                        // translators: %s plugin title.
     140                                        echo '<button type="submit" name="block-directory-edit" value="add">' . sprintf( __( 'Add %s to Block Directory', 'wporg-plugins' ), $plugin->post_title ) . '</button>';
     141                                }
     142                                echo '</p>';
     143
    123144                        }
    124145                }
    125146