Changeset 10022
- Timestamp:
- 07/07/2020 03:35:12 AM (4 years ago)
- 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 3 3 4 4 use WordPressdotorg\Plugin_Directory\CLI\Block_Plugin_Checker; 5 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 5 6 6 7 class Block_Validator { … … 28 29 29 30 <?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' ) ) { 31 32 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 } 32 48 } 33 49 ?> … … 39 55 <?php endif; 40 56 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 ); 41 67 } 42 68 … … 63 89 } 64 90 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 65 112 $results_by_type = array(); 66 113 foreach ( $results as $item ) { … … 73 120 $output .= '<h3>' . __( 'Success', 'wporg-plugins' ) . '</h3>'; 74 121 $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 } 76 127 $output .= "</div>\n"; 77 128 } else {
Note: See TracChangeset
for help on using the changeset viewer.