WordPress.org

Make WordPress Core

Ticket #29798: 29798.diff

File 29798.diff, 3.0 KB (added by mattyza, 5 years ago)

First pass at adding detection, and notices, if a theme is uploaded to the plugins uploader and visa versa.

  • wp-admin/includes/class-wp-upgrader.php

    diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php
    index 235df51..fa833de 100644
    a b class Plugin_Upgrader extends WP_Upgrader { 
    10441044         * @global WP_Filesystem_Base $wp_filesystem Subclass
    10451045         *
    10461046         * @param string $source The path to the downloaded package source.
     1047         * @param string $environment The environment in which the check is running (default, in-plugin-installer, etc).
    10471048         * @return string|WP_Error The source as passed, or a {@see WP_Error} object if no plugins were found.
    10481049         */
    1049         public function check_package($source) {
     1050        public function check_package($source, $environment = 'default') {
    10501051                global $wp_filesystem;
    10511052
    10521053                if ( is_wp_error($source) )
    class Plugin_Upgrader extends WP_Upgrader { 
    10561057                if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
    10571058                        return $source;
    10581059
     1060                if ( 'default' == $environment ) {
     1061                        // Check if we've got a theme here
     1062                        $theme_check = Theme_Upgrader::check_package( $source, 'in-theme-installer' );
     1063
     1064                        if ( ! is_a( $theme_check, 'WP_Error' ) ) {
     1065                                return new WP_Error( 'incompatible_archive_plugin_is_theme', $this->strings['incompatible_archive'], __( 'It looks like you\'re wanting to install a theme. Visit the theme installer to do this.' ) );
     1066                        }
     1067                }
     1068
    10591069                // Check the folder contains at least 1 valid plugin.
    10601070                $plugins_found = false;
    10611071                $files = glob( $working_directory . '*.php' );
    class Theme_Upgrader extends WP_Upgrader { 
    15781588         * @global WP_Filesystem_Base $wp_filesystem Subclass
    15791589         *
    15801590         * @param string $source The full path to the package source.
     1591         * @param string $environment The environment in which the check is running (default, in-theme-installer, etc).
    15811592         * @return string|WP_Error The source or a WP_Error.
    15821593         */
    1583         public function check_package( $source ) {
     1594        public function check_package( $source, $environment = 'default' ) {
    15841595                global $wp_filesystem;
    15851596
    15861597                if ( is_wp_error($source) )
    class Theme_Upgrader extends WP_Upgrader { 
    15911602                if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
    15921603                        return $source;
    15931604
     1605                if ( 'default' == $environment ) {
     1606                        // Check if we've got a plugin here
     1607                        $plugin_check = Plugin_Upgrader::check_package( $source, 'in-theme-installer' );
     1608
     1609                        if ( ! is_a( $plugin_check, 'WP_Error' ) ) {
     1610                                return new WP_Error( 'incompatible_archive_theme_is_plugin', $this->strings['incompatible_archive'], __( 'It looks like you\'re wanting to install a plugin. Visit the plugin installer to do this.' ) );
     1611                        }
     1612                }
     1613
    15941614                // A proper archive should have a style.css file in the single subdirectory
    15951615                if ( ! file_exists( $working_directory . 'style.css' ) )
    15961616                        return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>style.css</code> stylesheet.' ) );