Making WordPress.org

Changeset 10051


Ignore:
Timestamp:
07/10/2020 03:49:36 AM (4 years ago)
Author:
tellyworth
Message:

Plugin directory: add self-service support to the block plugin validator.

This lets plugin committers add or remove their plugins from the Block Directory.

See #5303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php

    r10049 r10051  
    44use WordPressdotorg\Plugin_Directory\CLI\Block_Plugin_Checker;
    55use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     6use WordPressdotorg\Plugin_Directory\Tools;
    67
    78class Block_Validator {
     
    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'] ) {
     
    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>';
     
    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        }
Note: See TracChangeset for help on using the changeset viewer.