WordPress.org

Making WordPress.org

Changeset 6045


Ignore:
Timestamp:
10/19/17 00:06:14 (2 months ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Remove the upload form after a successful upload.

Make Upload_Handler::process_upload() return WP_Error on failure.

Fixes #2386.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes
Files:
2 edited

Legend:

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

    r6026 r6045  
    5555     * Runs various tests and creates plugin post. 
    5656     * 
    57      * @return string Failure or success message. 
     57     * @return string|WP_Error Confirmation message on success, WP_Error object on failure. 
    5858     */ 
    5959    public function process_upload() { 
     
    7676            $error = __( 'Error: The plugin has no name.', 'wporg-plugins' ); 
    7777 
    78             /* translators: 1: plugin header line, 2: Codex URL */ 
    79             return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ), 
     78            return new \WP_Error( 'no_name', $error . ' ' . sprintf( 
     79                /* translators: 1: plugin header line, 2: Codex URL */ 
     80                __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ), 
    8081                '<code>Plugin Name:</code>', 
    8182                __( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' ) 
    82             ); 
     83            ) ); 
    8384        } 
    8485 
     
    9293            $error = __( 'Error: The plugin has an unsupported name.', 'wporg-plugins' ); 
    9394 
    94             /* translators: %s: 'Plugin Name:' */ 
    95             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' ), 
     95            return new \WP_Error( 'unsupported_name', $error . ' ' . sprintf( 
     96                /* translators: %s: 'Plugin Name:' */ 
     97                __( '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' ), 
    9698                esc_html( $this->plugin['Name'] ), 
    9799                '<code>Plugin Name:</code>' 
    98             ); 
     100            ) ); 
    99101        } 
    100102 
     
    103105            $error = __( 'Error: The plugin has a reserved name.', 'wporg-plugins' ); 
    104106             
    105             /* translators: 1: plugin slug, 2: 'Plugin Name:' */ 
    106             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' ), 
     107            return new \WP_Error( 'reserved_name', $error . ' ' . sprintf( 
     108                /* translators: 1: plugin slug, 2: 'Plugin Name:' */ 
     109                __( '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' ), 
    107110                '<code>' . $this->plugin_slug . '</code>', 
    108111                '<code>Plugin Name:</code>' 
    109             ); 
     112            ) ); 
    110113        } 
    111114 
     
    116119            $error = __( 'Error: The plugin already exists.', 'wporg-plugins' ); 
    117120             
    118             /* translators: 1: plugin slug, 2: 'Plugin Name:' */ 
    119             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' ), 
     121            return new \WP_Error( 'already_exists', $error . ' ' . sprintf( 
     122                /* translators: 1: plugin slug, 2: 'Plugin Name:' */ 
     123                __( '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' ), 
    120124                '<code>' . $this->plugin_slug . '</code>', 
    121125                '<code>Plugin Name:</code>' 
    122             ); 
     126            ) ); 
    123127        } 
    124128 
     
    127131            $error = __( 'Error: The plugin has already been submitted.', 'wporg-plugins' ); 
    128132             
    129             /* translators: 1: plugin slug, 2: plugins@wordpress.org */ 
    130             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 <a href="mailto:%2$s">%2$s</a> and let us know.', 'wporg-plugins' ), 
     133            return new \WP_Error( 'already_submitted', $error . ' ' . sprintf( 
     134                /* translators: 1: plugin slug, 2: plugins@wordpress.org */ 
     135                __( '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 <a href="mailto:%2$s">%2$s</a> and let us know.', 'wporg-plugins' ), 
    131136                '<code>' . $this->plugin_slug . '</code>', 
    132137                'plugins@wordpress.org' 
    133             ); 
     138            ) ); 
    134139        } 
    135140 
     
    137142            $error = __( 'Error: The plugin has no description.', 'wporg-plugins' ); 
    138143 
    139             /* translators: 1: plugin header line, 2: Codex URL */ 
    140             return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ), 
     144            return new \WP_Error( 'no_description', $error . ' ' . sprintf( 
     145                /* translators: 1: plugin header line, 2: Codex URL */ 
     146                __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ), 
    141147                '<code>Description:</code>', 
    142148                __( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' ) 
    143             ); 
     149            ) ); 
    144150        } 
    145151 
     
    147153            $error = __( 'Error: The plugin has no version.', 'wporg-plugins' ); 
    148154 
    149             /* translators: 1: plugin header line, 2: Codex URL */ 
    150             return $error . ' ' . sprintf( __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ), 
     155            return new \WP_Error( 'no_version', $error . ' ' . sprintf( 
     156                /* translators: 1: plugin header line, 2: Codex URL */ 
     157                __( 'Add a %1$s line to your main plugin file and upload the plugin again. <a href="%2$s">Plugin Headers</a>', 'wporg-plugins' ), 
    151158                '<code>Version:</code>', 
    152159                __( 'https://codex.wordpress.org/File_Header', 'wporg-plugins' ) 
    153             ); 
     160            ) ); 
    154161        } 
    155162 
     
    157164            $error = __( 'Error: Plugin versions are expected to be numbers.', 'wporg-plugins' ); 
    158165             
    159             /* translators: %s: 'Version:' */ 
    160             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' ), 
     166            return new \WP_Error( 'invalid_version', $error . ' ' . sprintf( 
     167                /* translators: %s: 'Version:' */ 
     168                __( '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' ), 
    161169                '<code>Version:</code>' 
    162             ); 
     170            ) ); 
    163171        } 
    164172 
     
    167175            $error = __( 'Error: Your plugin and author URIs are the same.', 'wporg-plugins' ); 
    168176             
    169             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' ); 
     177            return new \WP_Error( 'plugin_author_uri', $error . ' ' . 
     178                __( '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' ) 
     179            ); 
    170180        } 
    171181 
     
    174184            $error = __( 'Error: The plugin has no readme.', 'wporg-plugins' ); 
    175185             
    176             /* translators: 1: readme.txt, 2: readme.md */ 
    177             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' ), 
     186            return new \WP_Error( 'no_readme', $error . ' ' . sprintf( 
     187                /* translators: 1: readme.txt, 2: readme.md */ 
     188                __( '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' ), 
    178189                '<code>readme.txt</code>', 
    179190                '<code>readme.md</code>' 
    180             ); 
     191            ) ); 
    181192        } 
    182193        $readme = new Parser( $readme ); 
     
    189200            $error = __( 'Error: The plugin has failed the automated checks.', 'wporg-plugins' ); 
    190201             
    191             /* translators: 1: Plugin Check Plugin URL, 2: make.wordpress.org/plugins */ 
    192             return $error . ' ' . sprintf( __( 'Please correct the problems with the plugin and upload it again. You can also use the <a href="%1$s">Plugin Check Plugin</a> to test your plugin before uploading. If you have any questions about this please post them to %2$s.', 'wporg-plugins' ), 
     202            return new \WP_Error( 'failed_checks', $error . ' ' . sprintf( 
     203                /* translators: 1: Plugin Check Plugin URL, 2: make.wordpress.org/plugins */ 
     204                __( 'Please correct the problems with the plugin and upload it again. You can also use the <a href="%1$s">Plugin Check Plugin</a> to test your plugin before uploading. If you have any questions about this please post them to %2$s.', 'wporg-plugins' ), 
    193205                '//wordpress.org/plugins/plugin-check/', 
    194206                '<a href="https://make.wordpress.org/plugins">https://make.wordpress.org/plugins</a>' 
    195             ); 
     207            ) ); 
    196208        } 
    197209 
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php

    r6025 r6045  
    4646            } 
    4747 
     48            $upload_result = false; 
     49 
    4850            if ( ! empty( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'wporg-plugins-upload' ) && 'upload' === $_POST['action'] ) : 
    4951                if ( UPLOAD_ERR_OK === $_FILES['zip_file']['error'] ) : 
    50                     $uploader = new Upload_Handler; 
    51                     $message  = $uploader->process_upload(); 
     52                    $uploader      = new Upload_Handler; 
     53                    $upload_result = $uploader->process_upload(); 
     54 
     55                    if ( is_wp_error( $upload_result ) ) { 
     56                        $message = $upload_result->get_error_message(); 
     57                    } else { 
     58                        $message = $upload_result; 
     59                    } 
    5260                else : 
    5361                    $message = __( 'Error in file upload.', 'wporg-plugins' ); 
     
    119127            <?php endif; // wp_verify_nonce() && 'upload' === $_POST['action'] ?> 
    120128 
    121             <?php if ( ! $submitted_counts->total ) : ?> 
     129            <?php if ( ! $upload_result && ! $submitted_counts->total || is_wp_error( $upload_result ) ) : ?> 
    122130 
    123131                <form id="upload_form" class="plugin-upload-form" enctype="multipart/form-data" method="POST" action=""> 
Note: See TracChangeset for help on using the changeset viewer.