Making WordPress.org


Ignore:
Timestamp:
04/12/2023 04:50:46 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Import the Requires Plugins header on plugin import.

At present this is not used for anything, and is for future purposes.

See #6921, https://core.trac.wordpress.org/ticket/22316.

File:
1 edited

Legend:

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

    r12526 r12532  
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
    33
     4use WordPressdotorg\Plugin_Directory\CLI\Import;
    45use WordPressdotorg\Plugin_Directory\Readme\Parser;
    56use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     
    6465        $this->plugin_dir = Filesystem::unzip( $zip_file );
    6566
    66         $plugin_files = Filesystem::list_files( $this->plugin_dir, true /* Recursive */, '!\.php$!i', 1 /* Depth */ );
    67         foreach ( $plugin_files as $plugin_file ) {
    68             $plugin_data = get_plugin_data( $plugin_file, false, false ); // No markup/translation needed.
    69             if ( ! empty( $plugin_data['Name'] ) ) {
    70                 $this->plugin      = $plugin_data;
    71                 $this->plugin_root = dirname( $plugin_file );
    72                 break;
    73             }
     67        $plugin_data = (array) Import::find_plugin_headers( $this->plugin_dir, 1 /* Max Depth to search */ );
     68        if ( ! empty( $plugin_data['Name'] ) ) {
     69            $this->plugin      = $plugin_data;
     70            $this->plugin_root = dirname( $plugin_data['PluginFile'] );
    7471        }
    7572
     
    262259
    263260        // Check for a valid readme.
    264         $readme = $this->find_readme_file();
     261        $readme = Import::find_readme_file( $this->plugin_root );
    265262        if ( empty( $readme ) ) {
    266263            $error = __( 'Error: The plugin has no readme.', 'wporg-plugins' );
     
    381378                    'header_textdomain'        => $this->plugin['TextDomain'],
    382379                    'header_description'       => $this->plugin['Description'],
     380                    'requires_plugins'         => $this->plugin['RequiresPlugins'],
    383381                    'assets_screenshots'       => array(),
    384382                    'assets_icons'             => array(),
     
    677675
    678676    /**
    679      * Find the plugin readme file.
    680      *
    681      * Looks for either a readme.txt or readme.md file, prioritizing readme.txt.
    682      *
    683      * @return string The plugin readme.txt or readme.md filename.
    684      */
    685     protected function find_readme_file() {
    686         $files = Filesystem::list_files( $this->plugin_root, false /* non-recursive */, '!^readme\.(txt|md)$!i' );
    687 
    688         // Prioritize readme.txt file.
    689         foreach ( $files as $file ) {
    690             if ( '.txt' === strtolower( substr( $file, -4 ) ) ) {
    691                 return $file;
    692             }
    693         }
    694 
    695         return reset( $files );
    696     }
    697 
    698     /**
    699677     * Sends a plugin through Plugin Check.
    700678     *
Note: See TracChangeset for help on using the changeset viewer.