Making WordPress.org

Changeset 14966


Ignore:
Timestamp:
07/13/2026 08:07:13 PM (2 weeks ago)
Author:
obenland
Message:

Theme Directory: Guard against repopackage posts missing _status meta

Closes https://github.com/WordPress/wordpress.org/pull/705.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
Files:
4 added
2 edited

Legend:

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

    r14689 r14966  
    867867                        $phil->versions = array();
    868868
    869                         foreach ( array_keys( get_post_meta( $theme->ID, '_status', true ) ) as $version ) {
     869                        $status   = get_post_meta( $theme->ID, '_status', true );
     870                        $versions = is_array( $status ) ? array_keys( $status ) : array();
     871                        foreach ( $versions as $version ) {
    870872                                $phil->versions[ $version ] = $repo_package->download_url( $version );
    871873                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r14931 r14966  
    788788
    789789                                if ( $is_new_upload && $this->theme_post ) {
    790                                         wp_delete_post( $this->theme_post->ID, true );
     790                                        $this->delete_theme_post();
    791791                                }
    792792
     
    13161316                 */
    13171317                if ( in_array( $prev_status, [ 'new', 'approved' ], true ) ) {
    1318                         $ticket_id = (int) $this->theme_post->_ticket_id[ $this->theme_post->max_version ];
     1318                        $ticket_id = (int) ( $this->theme_post->_ticket_id[ $this->theme_post->max_version ] ?? 0 );
    13191319                        $ticket    = $this->trac->ticket_get( $ticket_id );
    13201320
     
    14481448                        $this->update_versioned_meta( $meta_key, $meta_value );
    14491449                }
     1450        }
     1451
     1452        /**
     1453         * Deletes the theme post.
     1454         *
     1455         * Used to clean up a freshly created post when a new upload fails.
     1456         * Temporarily detaches the fail-safe that prevents repopackages from
     1457         * being deleted, which would otherwise wp_die() before the post is
     1458         * removed, leaving an orphaned post without versioned meta behind.
     1459         *
     1460         * @return WP_Post|false|null Post data on success, false or null on failure.
     1461         */
     1462        public function delete_theme_post() {
     1463                remove_filter( 'before_delete_post', 'wporg_theme_no_delete_repopackage' );
     1464                $result = wp_delete_post( $this->theme_post->ID, true );
     1465                add_filter( 'before_delete_post', 'wporg_theme_no_delete_repopackage' );
     1466
     1467                return $result;
    14501468        }
    14511469
     
    17531771         */
    17541772        public function populate_post_with_meta( $theme ) {
    1755                 foreach ( get_post_custom_keys( $theme->ID ) as $meta_key ) {
     1773                foreach ( (array) get_post_custom_keys( $theme->ID ) as $meta_key ) {
    17561774                        $theme->$meta_key = get_post_meta( $theme->ID, $meta_key, true );
    17571775
     
    17621780
    17631781                // Save the highest recorded version number.
    1764                 $uploaded_versions  = array_keys( $theme->_status );
     1782                $uploaded_versions  = is_array( $theme->_status ) ? array_keys( $theme->_status ) : array();
    17651783                $theme->max_version = end( $uploaded_versions );
    17661784
Note: See TracChangeset for help on using the changeset viewer.