Making WordPress.org


Ignore:
Timestamp:
02/03/2015 11:33:49 PM (11 years ago)
Author:
obenland
Message:

WP.org Themes: Make sure uploaded theme files are always deleted.

We were already at a state where files were always deleted, independent from
the outcome of automated checks. Hocking it to PHP shutdown let's us clean up
in one place, and we don't have to worry about remembering to add it in when
other checks are added or existing checks modified.

See #745.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r1150 r1216  
    9797                // First things first. Do we have something to work with?
    9898                if ( empty( $theme_files ) ) {
    99                         $this->remove_files( $this->tmp_dir );
    100 
    10199                        return __( 'The zip file was empty.', 'wporg-themes' );
    102100                }
     
    105103                $style_css = $this->get_style_css( $theme_files );
    106104                if ( empty( $style_css ) ) {
    107                         $this->remove_files( $this->tmp_dir );
    108 
    109105                        return sprintf( __( 'The zip file must include a file named %s.', 'wporg-themes' ), '<code>style.css</code>' );
    110106                }
     
    117113                // We need a screen shot. People love screen shots.
    118114                if ( ! $this->has_screen_shot( $theme_files ) ) {
    119                         $this->remove_files( $this->tmp_dir );
    120 
    121115                        return sprintf( __( 'The zip file must include a file named %1$s or %2$s.', 'wporg-themes' ), '<code>screenshot.png</code>', '<code>screenshot.jpg</code>' );
    122116                }
     
    125119
    126120                if ( ! $this->theme->get( 'Name' ) ) {
    127                         $this->remove_files( $this->tmp_dir );
    128 
    129121                        return __( "The theme has no name. Add it to style.css and upload the theme again. <a href='http://codex.wordpress.org/Theme_Development#Theme_Style_Sheet'>Theme Style Sheets</a>", 'wporg-themes' );
    130122                }
     
    132124                $theme_description = $this->strip_non_utf8( (string) $this->theme->get( 'Description' ) );
    133125                if ( empty( $theme_description ) ) {
    134                         $this->remove_files( $this->tmp_dir );
    135 
    136126                        return sprintf( __( 'The theme has no description. Add it to <code>style.css</code> and upload the theme again. <a href="%s">Theme Style Sheets</a>', 'wporg-themes' ), 'http://codex.wordpress.org/Theme_Development#Theme_Style_Sheet' );
    137127                }
    138128
    139129                if ( ! $this->theme->get( 'Tags' ) ) {
    140                         $this->remove_files( $this->tmp_dir );
    141 
    142130                        return __( 'The stylesheet has no tags. Add a Tags: line to your <code>style.css</code> file and upload the zip file again.', 'wporg-themes' );
    143131                }
    144132
    145133                if ( ! $this->theme->get( 'Version' ) ) {
    146                         $this->remove_files( $this->tmp_dir );
    147 
    148134                        return __( 'The stylesheet has no version. Add a Version: line to your <code>style.css</code> file and upload the zip file again.', 'wporg-themes' );
    149135                }
    150136
    151137                if ( preg_match( '|[^\d\.]|', $this->theme->get( 'Version' ) ) ) {
    152                         $this->remove_files( $this->tmp_dir );
    153 
    154138                        return __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix your Version: line in <code>style.css</code> and upload your theme again.', 'wporg-themes' );
    155139                }
     
    157141                // Make sure we have version that is higher than any previously uploaded version of this theme.
    158142                if ( ! empty( $this->theme_post ) && ! version_compare( $this->theme->get( 'Version' ), $this->theme_post->max_version, '>' ) ) {
    159                         $this->remove_files( $this->tmp_dir );
    160 
    161143                        return sprintf( __( 'You need to upload a version of %1$s higher than %2$s. Increase the theme version number in <code>style.css</code>, then upload your zip file again.', 'wporg-themes' ), $this->theme->display( 'Name' ), '<code>' . $this->theme->display( 'Version' ) . '</code>' );
    162144                }
     
    164146                // Prevent duplicate URLs.
    165147                if ( ! $this->theme->get( 'ThemeURI' ) && ! $this->theme->get( 'AuthorURI' ) && $this->theme->get( 'ThemeURI' ) == $this->theme->get( 'AuthorURI' ) ) {
    166                         $this->remove_files( $this->tmp_dir );
    167 
    168148                        return __( 'Duplicate theme and author URLs. A theme URL is a page/site the provides details about this specific theme. An author URL is a page/site that provides information about the author of the theme. You aren&rsquo;t required to provide both, so pick the one that best applies to your URL.', 'wporg-themes' );
    169149                }
     
    171151                // Check for child theme's parent in the directory (non-buddypress only)
    172152                if ( $this->theme->parent() && ! in_array( 'buddypress', $this->theme->get( 'Tags' ) ) && ! $this->is_parent_available() ) {
    173                         $this->remove_files( $this->tmp_dir );
    174 
    175153                        return sprintf( __( 'There is no theme called %s in the directory. For child themes, you must use a parent theme that already exists in the directory.', 'wporg-themes' ), '<code>' . $this->theme->parent() . '</code>' );
    176154                }
     
    178156                // Make sure it doesn't use a slug deemed not to be used by the public.
    179157                if ( $this->has_reserved_slug() ) {
    180                         $this->remove_files( $this->tmp_dir );
    181 
    182158                        return sprintf( __( 'Sorry, the theme name %s is reserved for use by WordPress Core. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme->get_stylesheet() . '</code>' );
    183159                }
     
    185161                // Is there already a theme with the name name by a different author?
    186162                if ( ! empty( $this->theme_post ) && $this->theme_post->post_author != $this->author->ID ) {
    187                         $this->remove_files( $this->tmp_dir );
    188 
    189163                        return sprintf( __( 'There is already a theme called %s by a different author. Please change the name of your theme in <code>style.css</code> and upload it again.', 'wporg-themes' ), '<code>' . $this->theme->get_stylesheet() . '</code>' );
    190164                }
     
    192166                // We know it's the correct author, now we can check if it's suspended.
    193167                if ( ! empty( $this->theme_post ) && 'trash' === $this->theme_post->post_status ) {
    194                         $this->remove_files( $this->tmp_dir );
    195 
    196168                        return sprintf( __( 'This theme is suspended from the Theme Repository and it can&rsquo;t be updated. If you have any questions about this please contact %s.', 'wporg-themes' ), '<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a>' );
    197169                }
     
    203175
    204176                        if ( ! $result ) {
    205                                 $this->remove_files( $this->tmp_dir );
    206 
    207177                                return sprintf( __( 'Your theme has failed the theme check. Please correct the problems with it and upload it again. You can also use the <a href="%1$s">Theme Check Plugin</a> to test your theme before uploading. If you have any questions about this please contact %2$s.', 'wporg-themes' ), '//wordpress.org/plugins/theme-check/', '<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a>' );
    208178                        }
     
    219189
    220190                if ( ! $ticket_id  ) {
    221                         $this->remove_files( $this->tmp_dir );
    222 
    223191                        return sprintf( __( 'There was an error creating a Trac ticket for your theme, please report this error to %s', 'wporg-themes' ), '<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a>' );
    224192                }
     
    232200                // Send theme author an email for peace of mind.
    233201                $this->send_email_notification( $ticket_id );
    234 
    235                 // Finally remove all temporary files.
    236                 $this->remove_files( $this->tmp_dir );
    237202
    238203                do_action( 'theme_upload', $this->theme );
     
    265230                $this->theme_dir = "{$this->tmp_dir}/{$base_name}";
    266231                mkdir( $this->theme_dir, 0777 );
     232
     233                // Make sure we clean up after ourselves.
     234                add_action( 'shutdown', array( $this, 'remove_files' ) );
    267235        }
    268236
     
    694662
    695663        /**
    696          * Deletes the passed files or directory.
    697          *
    698          * @param string $files
    699          */
    700         public function remove_files( $files ) {
     664         * Deletes the temporary directory.
     665         */
     666        public function remove_files() {
    701667                $rm    = escapeshellarg( self::RM );
    702                 $files = escapeshellarg( $files );
     668                $files = escapeshellarg( $this->tmp_dir );
    703669
    704670                exec( escapeshellcmd( "{$rm} -rf {$files}" ) );
Note: See TracChangeset for help on using the changeset viewer.