Making WordPress.org

Changeset 10022


Ignore:
Timestamp:
07/07/2020 03:35:12 AM (6 years ago)
Author:
tellyworth
Message:

Plugin directory: add initial tool for plugin reviewers to add blocks to directory.

Props tellyworth, dd32, dufresnesteven.
See #5306.

File:
1 edited

Legend:

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

    r10011 r10022  
    33
    44use WordPressdotorg\Plugin_Directory\CLI\Block_Plugin_Checker;
     5use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    56
    67class Block_Validator {
    … …  
    2829
    2930                        <?php
    30                         if ( $_POST && wp_verify_nonce( $_POST['block-nonce'], 'validate-block-plugin' ) ) {
     31                        if ( $_POST && !empty( $_POST['plugin_url'] ) && wp_verify_nonce( $_POST['block-nonce'], 'validate-block-plugin' ) ) {
    3132                                self::validate_block( $_POST['plugin_url'] );
     33                        } elseif ( $_POST && !empty( $_POST['block-directory-edit'] ) ) {
     34                                $post = get_post( intval( $_POST['plugin-id'] ) );
     35                                if ( $post && wp_verify_nonce( $_POST['block-directory-nonce'], 'block-directory-edit-' . $post->ID ) ) {
     36                                        if ( current_user_can( 'edit_post', $post->ID ) ) {
     37                                                $terms = wp_list_pluck( get_the_terms( $post->ID, 'plugin_section' ), 'slug' );
     38                                                if ( 'add' === $_POST['block-directory-edit'] ) {
     39                                                        $terms[] = 'block';
     40                                                } elseif ( 'remove' === $_POST['block-directory-edit'] ) {
     41                                                        $terms = array_diff( $terms, array( 'block' ) );
     42                                                }
     43                                                wp_set_object_terms( $post->ID, $terms, 'plugin_section' );
     44                                        }
     45
     46                                        self::validate_block( $post->post_name );
     47                                }
    3248                        }
    3349                        ?>
    … …  
    3955                <?php endif;
    4056                return ob_get_clean();
     57        }
     58
     59        protected static function plugin_is_in_block_directory( $slug ) {
     60                $plugin = Plugin_Directory::get_plugin_post( $slug );
     61
     62                return (
     63                        $plugin &&
     64                        $plugin->post_name === $slug &&
     65                        has_term( 'block', 'plugin_section', $plugin )
     66                );
    4167        }
    4268
    … …  
    6389                }
    6490
     91                if ( $checker->slug ) {
     92                        $plugin = Plugin_Directory::get_plugin_post( $checker->slug );
     93                        if ( current_user_can( 'edit_post', $plugin->ID ) ) {
     94                                echo '<form method="post">';
     95                                echo '<fieldset>';
     96                                echo '<legend>' . __( 'Plugin Review Tools', 'wporg-plugins' ) . '</legend>';
     97                                echo wp_nonce_field( 'block-directory-edit-' . $plugin->ID, 'block-directory-nonce' );
     98                                echo '<input type="hidden" name="plugin-id" value="' . esc_attr( $plugin->ID ) . '" />';
     99                                if ( self::plugin_is_in_block_directory( $checker->slug ) ) {
     100                                        echo '<button type="submit" name="block-directory-edit" value="remove">' . __( 'Remove from Block Directory', 'wporg-plugins' ) . '</button>';
     101                                } else {
     102                                        echo '<button type="submit" name="block-directory-edit" value="add">' . __( 'Add to Block Directory', 'wporg-plugins' ) . '</button>';
     103                                }
     104       
     105                                echo '<ul><li><a href="' . get_edit_post_link( $plugin->ID ) . '">' . __( 'Edit plugin', 'wporg-plugins' ) . '</a></li>';
     106                                echo '<li><a href="' . esc_url( 'https://plugins.trac.wordpress.org/browser/' . $checker->slug . '/trunk' ) .'">' . __( 'Trac browser', 'wporg-plugins' ) . '</a></li></ul>';
     107                                echo '</fieldset>';
     108                                echo '</form>';
     109                        }
     110                }
     111
    65112                $results_by_type = array();
    66113                foreach ( $results as $item ) {
    … …  
    73120                        $output .= '<h3>' . __( 'Success', 'wporg-plugins' ) . '</h3>';
    74121                        $output .= "<div class='notice notice-success notice-alt'>\n";
    75                         $output .= __( 'No problems were found. Your plugin has passed the first step towards being included in the Block Directory.', 'wporg-plugins' );
     122                        if ( $checker->slug && self::plugin_is_in_block_directory( $checker->slug ) ) {
     123                                $output .= __( 'No problems were found. This plugin is already in the Block Directory.', 'wporg-plugins' );
     124                        } else {
     125                                $output .= __( 'No problems were found. Your plugin has passed the first step towards being included in the Block Directory.', 'wporg-plugins' );
     126                        }
    76127                        $output .= "</div>\n";
    77128                } else {
Note: See TracChangeset for help on using the changeset viewer.