Changeset 12532
- Timestamp:
- 04/12/2023 04:50:46 AM (22 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r12463 r12532 42 42 // Plugin headers that are stored in plugin meta 43 43 public $plugin_headers = array( 44 // Header => meta_key 45 'Name' => 'header_name', 46 'PluginURI' => 'header_plugin_uri', 47 'Author' => 'header_author', 48 'AuthorURI' => 'header_author_uri', 49 'TextDomain' => 'header_textdomain', 44 // Header => meta_key 45 'Name' => 'header_name', 46 'PluginURI' => 'header_plugin_uri', 47 'Author' => 'header_author', 48 'AuthorURI' => 'header_author_uri', 49 'TextDomain' => 'header_textdomain', 50 'RequiresPlugins' => 'requires_plugins' 50 51 51 52 // These headers are stored in these fields, but are handled separately. … … 723 724 * 724 725 * @param string $directory The directory of the plugin. 726 * @param int $max_depth The maximum depth to search for files. Default: current directory only. 725 727 * 726 728 * @return object The plugin headers. 727 729 */ 728 public static function find_plugin_headers( $directory ) {729 $files = Filesystem::list_files( $directory, false, '!\.php$!i');730 public static function find_plugin_headers( $directory, $max_depth = -1 ) { 731 $files = Filesystem::list_files( $directory, ( $max_depth > 0 ), '!\.php$!i', $max_depth ); 730 732 731 733 if ( ! function_exists( 'get_plugin_data' ) ) { … … 733 735 } 734 736 737 // Add any additional headers required. 738 add_filter( 'extra_plugin_headers', array( __CLASS__, 'add_extra_plugin_headers' ) ); 739 735 740 /* 736 741 * Sometimes plugins have multiple files which we detect as a plugin based on the headers. 737 * We'll returnimmediately if the file has a `Plugin Name:` header, otherwise742 * We'll break immediately if the file has a `Plugin Name:` header, otherwise 738 743 * simply return the last set of headers we come across. 739 744 */ 740 $ possible_headers = false;745 $headers = false; 741 746 foreach ( $files as $file ) { 742 747 $data = get_plugin_data( $file, false, false ); 743 748 if ( array_filter( $data ) ) { 744 if ( $data['Name'] ) { 745 return (object) $data; 746 } else { 747 $possible_headers = (object) $data; 748 } 749 } 750 } 751 752 if ( $possible_headers ) { 753 return $possible_headers; 754 } 755 756 return false; 749 $data['PluginFile'] = $file; 750 $headers = $data; 751 752 if ( $headers['Name'] ) { 753 break; 754 } 755 } 756 } 757 758 remove_filter( 'extra_plugin_headers', array( __CLASS__, 'add_extra_plugin_headers' ) ); 759 760 if ( ! $headers ) { 761 return false; 762 } 763 764 // The extra_plugin_headers filter doesn't let you set the key. 765 foreach ( self::add_extra_plugin_headers( [] ) as $key => $header ) { 766 if ( 767 $key != $header && 768 ! isset( $headers[ $key ] ) && 769 isset( $headers[ $header ] ) 770 ) { 771 $headers[ $key ] = $headers[ $header ]; 772 unset( $headers[ $header ] ); 773 } 774 } 775 776 return (object) $headers; 777 } 778 779 /** 780 * Add support for additional plugin headers prior to WordPress supporting it. 781 * 782 * @param array $headers The headers to look for in plugins. 783 * @return array 784 */ 785 public static function add_extra_plugin_headers( $headers ) { 786 // WordPress Plugin Dependencies - See https://meta.trac.wordpress.org/ticket/6921 787 if ( ! isset( $headers['RequiresPlugins'] ) ) { 788 $headers['RequiresPlugins'] = 'Requires Plugins'; 789 } 790 791 return $headers; 757 792 } 758 793 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php
r12526 r12532 2 2 namespace WordPressdotorg\Plugin_Directory\Shortcodes; 3 3 4 use WordPressdotorg\Plugin_Directory\CLI\Import; 4 5 use WordPressdotorg\Plugin_Directory\Readme\Parser; 5 6 use WordPressdotorg\Plugin_Directory\Plugin_Directory; … … 64 65 $this->plugin_dir = Filesystem::unzip( $zip_file ); 65 66 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'] ); 74 71 } 75 72 … … 262 259 263 260 // Check for a valid readme. 264 $readme = $this->find_readme_file();261 $readme = Import::find_readme_file( $this->plugin_root ); 265 262 if ( empty( $readme ) ) { 266 263 $error = __( 'Error: The plugin has no readme.', 'wporg-plugins' ); … … 381 378 'header_textdomain' => $this->plugin['TextDomain'], 382 379 'header_description' => $this->plugin['Description'], 380 'requires_plugins' => $this->plugin['RequiresPlugins'], 383 381 'assets_screenshots' => array(), 384 382 'assets_icons' => array(), … … 677 675 678 676 /** 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 /**699 677 * Sends a plugin through Plugin Check. 700 678 *
Note: See TracChangeset
for help on using the changeset viewer.