Changeset 13109 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php
- Timestamp:
- 01/15/2024 05:23:52 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php
r12793 r13109 52 52 ob_start(); 53 53 54 $uploader = new Upload_Handler();55 56 54 include_once ABSPATH . 'wp-admin/includes/template.php'; 57 55 56 $uploader = new Upload_Handler(); 57 $upload_result = false; 58 58 59 list( $submitted_plugins, $submitted_counts ) = self::get_submitted_plugins(); 59 60 60 $upload_result = false;61 62 61 if ( 63 ! empty( $_POST['_wpnonce'] ) 64 && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' ) 65 && 'upload' === $_POST['action'] 66 && ! $submitted_counts->total 67 && ! empty( $_FILES['zip_file'] ) 62 ! empty( $_POST['_wpnonce'] ) && 63 ! empty( $_FILES['zip_file'] ) && 64 ( 65 // New submission. 66 ! $submitted_counts->total && 67 empty( $_POST['plugin_id'] ) && 68 wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' ) && 69 'upload' === $_POST['action'] 70 ) || ( 71 // Existing submission 72 ! empty( $_POST['plugin_id'] ) && 73 'upload-additional' === $_POST['action'] && 74 wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload-' . $_POST['plugin_id'] ) 75 ) 68 76 ) { 69 $upload_result = $uploader->process_upload(); 77 $for_plugin = absint( $_POST['plugin_id'] ?? 0 ); 78 $upload_result = $uploader->process_upload( $for_plugin ); 70 79 71 80 if ( is_wp_error( $upload_result ) ) { 81 $type = 'error'; 72 82 $message = $upload_result->get_error_message(); 73 83 } else { 84 $type = 'success'; 74 85 $message = $upload_result; 75 86 } … … 79 90 80 91 if ( ! empty( $message ) ) { 81 echo "<div class='notice notice- warningnotice-alt'><p>{$message}</p></div>\n";92 echo "<div class='notice notice-{$type} notice-alt'><p>{$message}</p></div>\n"; 82 93 } 83 94 } 84 95 85 if ( ! is_wp_error( $upload_result ) ) :96 if ( ! is_wp_error( $upload_result ) || $submitted_counts->total ) : 86 97 $plugins = wp_count_posts( 'plugin', 'readable' ); 87 98 $oldest_plugin = get_posts( [ 'post_type' => 'plugin', 'post_status' => 'new', 'order' => 'ASC', 'orderby' => 'post_date_gmt', 'numberposts' => 1 ] ); … … 183 194 // List of all plugins in progress. 184 195 foreach ( $submitted_plugins as $plugin ) { 185 $can_change_slug = ( 'new' === $plugin->post_status && ! $plugin->{'_wporg_plugin_original_slug'} ); 196 $can_change_slug = ( 'new' === $plugin->post_status && ! $plugin->{'_wporg_plugin_original_slug'} ); 197 $can_upload_extras = in_array( $plugin->post_status, array( 'new', /* 'pending' */ ), true ); 186 198 187 199 echo '<li>'; … … 258 270 endif; // $can_change_slug 259 271 echo '</li>'; 272 273 echo '<li>'; 274 $attached_media = get_attached_media( 'application/zip', $plugin ); 275 276 echo '<strong>' . __( 'Submitted files:', 'wporg' ) . '</strong><ol>'; 277 foreach ( $attached_media as $upload ) { 278 echo '<li><ul>'; 279 $filename = $upload->submitted_name ?: preg_replace( '!^[0-9-_]+!', '', basename( get_attached_file( $upload->ID ) ) ); 280 $version = $upload->version ?: $plugin->version; 281 282 echo '<li><code>' . esc_html( $filename ) . '</code></li>'; 283 echo '<li>' . sprintf( __( 'Version: %s', 'wporg-plugins' ), '<code>' . esc_html( $version ) . '</code>' ) . '</li>'; 284 echo '<li>' . sprintf( __( 'Upload Date: %s', 'wporg-plugins' ), date_i18n( get_option( 'date_format' ), strtotime( $upload->post_date ) ) ) . '</li>'; 285 echo '</ul></li>'; 286 } 287 if ( $can_upload_extras ) { 288 echo '<li class="unmarked-list"><a href="#" class="show-upload-additional hide-if-no-js">' . sprintf( __( 'Upload new version of %s for review.', 'wporg-plugins' ), esc_html( $plugin->post_title ) ) . '</a>'; 289 } 290 echo '</ol>'; 291 292 if ( $can_upload_extras ) { 293 ?> 294 <form class="plugin-upload-form hidden" enctype="multipart/form-data" method="POST" action=""> 295 <?php wp_nonce_field( 'wporg-plugins-upload-' . $plugin->ID ); ?> 296 <input type="hidden" name="action" value="upload-additional"/> 297 <input type="hidden" name="plugin_id" value="<?php echo esc_attr( $plugin->ID ); ?>" /> 298 299 <label class="button button-secondary zip-file"> 300 <input type="file" class="plugin-file" name="zip_file" size="25" accept=".zip" required data-maxbytes="<?php echo esc_attr( wp_max_upload_size() ); ?>" /> 301 <span><?php _e( 'Select File', 'wporg-plugins' ); ?></span> 302 </label> 303 304 <input class="upload-button button button-primary" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ) ?>"/> 305 </form> 306 <?php 307 } 308 echo '</li>'; 260 309 echo '</ul>'; 261 262 310 echo "</li>\n"; 263 311 } … … 306 354 </ul> 307 355 </fieldset> */ 308 ?> 309 310 <input type="file" id="zip_file" class="plugin-file" name="zip_file" size="25" accept=".zip" required data-maxbytes="<?php echo esc_attr( wp_max_upload_size() ); ?>" /> 311 <label class="button button-secondary" for="zip_file"><?php _e( 'Select File', 'wporg-plugins' ); ?></label> 356 ?> 357 358 <label class="button button-secondary zip-file"> 359 <input type="file" class="plugin-file" name="zip_file" size="25" accept=".zip" required data-maxbytes="<?php echo esc_attr( wp_max_upload_size() ); ?>" /> 360 <span><?php _e( 'Select File', 'wporg-plugins' ); ?></span> 361 </label> 312 362 313 363 <p> … … 357 407 <input id="upload_button" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Upload', 'wporg-plugins' ); ?>"/> 358 408 </form> 359 360 <?php361 $upload_script = '362 ( function ( $ ) {363 var $label = $( "label.button" ),364 labelText = $label.text();365 $( "#zip_file" )366 .on( "change", function( event ) {367 var fileName = event.target.value.split( "\\\\" ).pop(),368 fileSize = event.target.files[0].size || 0;369 370 if ( fileSize > $(this).data( "maxbytes" ) ) {371 event.target.value = "";372 fileName = false;373 }374 375 fileName ? $label.text( fileName ) : $label.text( labelText );376 } )377 .on( "focus", function() { $label.addClass( "focus" ); } )378 .on( "blur", function() { $label.removeClass( "focus" ); } );379 } ( window.jQuery ) );';380 381 if ( ! wp_script_is( 'jquery', 'done' ) ) {382 wp_enqueue_script( 'jquery' );383 wp_add_inline_script( 'jquery-migrate', $upload_script );384 } else {385 printf( '<script>%s</script>', $upload_script );386 }387 ?>388 389 409 <?php endif; // ! $submitted_counts->total 390 410
Note: See TracChangeset
for help on using the changeset viewer.