Making WordPress.org

Changeset 13233


Ignore:
Timestamp:
02/22/2024 04:55:11 AM (10 months ago)
Author:
dd32
Message:

Plugin Directory: Dependencies: Don't import plugins which specify invalid dependencies.

See #6921.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r13018 r13233  
    102102            }
    103103        }
     104
     105        $_requires_plugins = array_filter( array_map( 'trim', explode( ',', $headers->RequiresPlugins ) ) );
     106        $requires_plugins     = [];
     107        $unmet_dependencies   = [];
     108        foreach ( $_requires_plugins as $requires_plugin_slug ) {
     109            $requires_plugin_post = Plugin_Directory::get_plugin_post( $requires_plugin_slug );
     110
     111            // get_plugin_post() will resolve some edge-cases, but we only want exact slug-matches, anything else is wrong.
     112            if (
     113                $requires_plugin_post &&
     114                $requires_plugin_slug === $requires_plugin_post->post_name &&
     115                'publish' === $requires_plugin_post->post_status
     116            ) {
     117                $requires_plugins[] = $requires_plugin_post->post_name;
     118            } else {
     119                $unmet_dependencies[] = $requires_plugin_slug;
     120            }
     121        }
     122
     123        if ( $unmet_dependencies ) {
     124            throw new Exception( 'Invalid plugin dependencies specified. The following dependencies could not be resolved: ' . implode( ', ', $requires_plugins_unmet ) );
     125        }
     126        unset( $_requires_plugins, $unmet_dependencies );
    104127
    105128        // Release confirmation
     
    312335        }
    313336
    314         // Validate whether the dependencies are met by WordPress.org-hosted plugins.
    315         $requires_plugins       = array_filter( array_map( 'trim', explode( ',', $headers->RequiresPlugins ) ) );
    316         $requires_plugins_unmet = false;
    317         foreach ( $requires_plugins as $requires_plugin_slug ) {
    318             // TODO: Add support for premium plugins.
    319             $requires_plugin_post = Plugin_Directory::get_plugin_post( $requires_plugin_slug );
    320             if (
    321                 ! $requires_plugin_post ||
    322                 // get_plugin_post() will resolve some edge-cases, but we only want exact slug-matches.
    323                 $requires_plugin_slug !== $requires_plugin_post->post_name ||
    324                 'publish' !== $requires_plugin_post->post_status
    325             ) {
    326                 $requires_plugins_unmet = true;
    327                 break;
    328             }
    329         }
    330 
    331         update_post_meta( $plugin->ID, 'requires_plugins', wp_slash( $requires_plugins ) );
    332         if ( $requires_plugins_unmet ) {
    333             update_post_meta( $plugin->ID, '_requires_plugins_unmet', true );
    334         } else {
    335             delete_post_meta( $plugin->ID, '_requires_plugins_unmet' );
    336         }
    337 
     337        update_post_meta( $plugin->ID, 'requires_plugins',   wp_slash( $requires_plugins ) );
    338338        update_post_meta( $plugin->ID, 'requires',           wp_slash( $requires ) );
    339339        update_post_meta( $plugin->ID, 'requires_php',       wp_slash( $requires_php ) );
Note: See TracChangeset for help on using the changeset viewer.