Index: /sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php (revision 6044)
+++ /sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php (revision 6045)
@@ -55,5 +55,5 @@
* Runs various tests and creates plugin post.
*
- * @return string Failure or success message.
+ * @return string|WP_Error Confirmation message on success, WP_Error object on failure.
*/
public function process_upload() {
@@ -76,9 +76,10 @@
$error = __( 'Error: The plugin has no name.', 'wporg-plugins' );
- /* translators: 1: plugin header line, 2: Codex URL */
- return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. Plugin Headers', 'wporg-plugins' ),
+ return new \WP_Error( 'no_name', $error . ' ' . sprintf(
+ /* translators: 1: plugin header line, 2: Codex URL */
+ __( 'Add a %1$s line to your main plugin file and upload the plugin again. Plugin Headers', 'wporg-plugins' ),
'Plugin Name:
',
__( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' )
- );
+ ) );
}
@@ -92,9 +93,10 @@
$error = __( 'Error: The plugin has an unsupported name.', 'wporg-plugins' );
- /* translators: %s: 'Plugin Name:' */
- return $error . ' ' . sprintf( __( 'Plugin names can only contain latin letters (A-z), numbers, spaces, and hyphens. Please change the %s line in your main plugin file and upload it again.', 'wporg-plugins' ),
+ return new \WP_Error( 'unsupported_name', $error . ' ' . sprintf(
+ /* translators: %s: 'Plugin Name:' */
+ __( 'Plugin names can only contain latin letters (A-z), numbers, spaces, and hyphens. Please change the %s line in your main plugin file and upload it again.', 'wporg-plugins' ),
esc_html( $this->plugin['Name'] ),
'Plugin Name:
'
- );
+ ) );
}
@@ -103,9 +105,10 @@
$error = __( 'Error: The plugin has a reserved name.', 'wporg-plugins' );
- /* translators: 1: plugin slug, 2: 'Plugin Name:' */
- return $error . ' ' . sprintf( __( 'Your chosen plugin name - %1$s - has been reserved for use by WordPress. Please change the %2$s line in your main plugin file and upload it again.', 'wporg-plugins' ),
+ return new \WP_Error( 'reserved_name', $error . ' ' . sprintf(
+ /* translators: 1: plugin slug, 2: 'Plugin Name:' */
+ __( 'Your chosen plugin name - %1$s - has been reserved for use by WordPress. Please change the %2$s line in your main plugin file and upload it again.', 'wporg-plugins' ),
'' . $this->plugin_slug . '
',
'Plugin Name:
'
- );
+ ) );
}
@@ -116,9 +119,10 @@
$error = __( 'Error: The plugin already exists.', 'wporg-plugins' );
- /* translators: 1: plugin slug, 2: 'Plugin Name:' */
- return $error . ' ' . sprintf( __( 'There is already a plugin called %1$s by a different author. Please change the %2$s line in your main plugin file and upload it again.', 'wporg-plugins' ),
+ return new \WP_Error( 'already_exists', $error . ' ' . sprintf(
+ /* translators: 1: plugin slug, 2: 'Plugin Name:' */
+ __( 'There is already a plugin called %1$s by a different author. Please change the %2$s line in your main plugin file and upload it again.', 'wporg-plugins' ),
'' . $this->plugin_slug . '
',
'Plugin Name:
'
- );
+ ) );
}
@@ -127,9 +131,10 @@
$error = __( 'Error: The plugin has already been submitted.', 'wporg-plugins' );
- /* translators: 1: plugin slug, 2: plugins@wordpress.org */
- return $error . ' ' . sprintf( __( 'You have already submitted a plugin called %1$s. Please be patient and wait for a review. If you have made a mistake, please email %2$s and let us know.', 'wporg-plugins' ),
+ return new \WP_Error( 'already_submitted', $error . ' ' . sprintf(
+ /* translators: 1: plugin slug, 2: plugins@wordpress.org */
+ __( 'You have already submitted a plugin called %1$s. Please be patient and wait for a review. If you have made a mistake, please email %2$s and let us know.', 'wporg-plugins' ),
'' . $this->plugin_slug . '
',
'plugins@wordpress.org'
- );
+ ) );
}
@@ -137,9 +142,10 @@
$error = __( 'Error: The plugin has no description.', 'wporg-plugins' );
- /* translators: 1: plugin header line, 2: Codex URL */
- return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. Plugin Headers', 'wporg-plugins' ),
+ return new \WP_Error( 'no_description', $error . ' ' . sprintf(
+ /* translators: 1: plugin header line, 2: Codex URL */
+ __( 'Add a %1$s line to your main plugin file and upload the plugin again. Plugin Headers', 'wporg-plugins' ),
'Description:
',
__( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' )
- );
+ ) );
}
@@ -147,9 +153,10 @@
$error = __( 'Error: The plugin has no version.', 'wporg-plugins' );
- /* translators: 1: plugin header line, 2: Codex URL */
- return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. Plugin Headers', 'wporg-plugins' ),
+ return new \WP_Error( 'no_version', $error . ' ' . sprintf(
+ /* translators: 1: plugin header line, 2: Codex URL */
+ __( 'Add a %1$s line to your main plugin file and upload the plugin again. Plugin Headers', 'wporg-plugins' ),
'Version:
',
__( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' )
- );
+ ) );
}
@@ -157,8 +164,9 @@
$error = __( 'Error: Plugin versions are expected to be numbers.', 'wporg-plugins' );
- /* translators: %s: 'Version:' */
- return $error . ' ' . sprintf( __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix the %s line in your main plugin file and upload the plugin again.', 'wporg-plugins' ),
+ return new \WP_Error( 'invalid_version', $error . ' ' . sprintf(
+ /* translators: %s: 'Version:' */
+ __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix the %s line in your main plugin file and upload the plugin again.', 'wporg-plugins' ),
'Version:
'
- );
+ ) );
}
@@ -167,5 +175,7 @@
$error = __( 'Error: Your plugin and author URIs are the same.', 'wporg-plugins' );
- return $error . ' ' . __( 'A plugin URL is a page/site that provides details about this specific plugin. An author URL is a page/site that provides information about the author of the plugin. You are not required to provide both, so pick the one that best applies to your URL.', 'wporg-plugins' );
+ return new \WP_Error( 'plugin_author_uri', $error . ' ' .
+ __( 'A plugin URL is a page/site that provides details about this specific plugin. An author URL is a page/site that provides information about the author of the plugin. You are not required to provide both, so pick the one that best applies to your URL.', 'wporg-plugins' )
+ );
}
@@ -174,9 +184,10 @@
$error = __( 'Error: The plugin has no readme.', 'wporg-plugins' );
- /* translators: 1: readme.txt, 2: readme.md */
- return $error . ' ' . sprintf( __( 'The zip file must include a file named %1$s or %2$s. We recommend using %1$s as it will allow you to fully utilize our directory.', 'wporg-plugins' ),
+ return new \WP_Error( 'no_readme', $error . ' ' . sprintf(
+ /* translators: 1: readme.txt, 2: readme.md */
+ __( 'The zip file must include a file named %1$s or %2$s. We recommend using %1$s as it will allow you to fully utilize our directory.', 'wporg-plugins' ),
'readme.txt
',
'readme.md
'
- );
+ ) );
}
$readme = new Parser( $readme );
@@ -189,9 +200,10 @@
$error = __( 'Error: The plugin has failed the automated checks.', 'wporg-plugins' );
- /* translators: 1: Plugin Check Plugin URL, 2: make.wordpress.org/plugins */
- return $error . ' ' . sprintf( __( 'Please correct the problems with the plugin and upload it again. You can also use the Plugin Check Plugin to test your plugin before uploading. If you have any questions about this please post them to %2$s.', 'wporg-plugins' ),
+ return new \WP_Error( 'failed_checks', $error . ' ' . sprintf(
+ /* translators: 1: Plugin Check Plugin URL, 2: make.wordpress.org/plugins */
+ __( 'Please correct the problems with the plugin and upload it again. You can also use the Plugin Check Plugin to test your plugin before uploading. If you have any questions about this please post them to %2$s.', 'wporg-plugins' ),
'//wordpress.org/plugins/plugin-check/',
'https://make.wordpress.org/plugins'
- );
+ ) );
}
Index: /sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php
===================================================================
--- /sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php (revision 6044)
+++ /sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php (revision 6045)
@@ -46,8 +46,16 @@
}
+ $upload_result = false;
+
if ( ! empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' ) && 'upload' === $_POST['action'] ) :
if ( UPLOAD_ERR_OK === $_FILES['zip_file']['error'] ) :
- $uploader = new Upload_Handler;
- $message = $uploader->process_upload();
+ $uploader = new Upload_Handler;
+ $upload_result = $uploader->process_upload();
+
+ if ( is_wp_error( $upload_result ) ) {
+ $message = $upload_result->get_error_message();
+ } else {
+ $message = $upload_result;
+ }
else :
$message = __( 'Error in file upload.', 'wporg-plugins' );
@@ -119,5 +127,5 @@
- total ) : ?>
+ total || is_wp_error( $upload_result ) ) : ?>