Make WordPress Core

Ticket #9532: plugin.php.patch

File plugin.php.patch, 3.0 KB (added by Txanny, 16 years ago)

function get_plugin_readme_data()

  • wp-admin/includes/plugin.php

     
    102102        return $plugin_data;
    103103}
    104104
     105/**
     106 * Parse the plugin readme.txt file to retrieve plugin's metadata.
     107 *
     108 * The metadata of the plugin's readme searches for the following in the readme.txt
     109 * header. All metadata must be on its own line. The below is formatted for printing.
     110 *
     111 * <code>
     112 * Contributors: contributors nicknames, comma delimited
     113 * Donate link: Link to plugin donate page
     114 * Tags: Plugin tags, comma delimited
     115 * Requires at least: Minimum WordPress version required
     116 * Tested up to: Higher WordPress version the plugin has been tested.
     117 * Stable tag: Latest stable tag in repository.
     118 * </code>
     119 *
     120 * Readme data returned array cointains the following:
     121 *              - 'Contributors' - An array with all contributors nicknames.
     122 *              - 'Tags' - An array with all plugin tags.
     123 *              - 'DonateURI' - The donations page address.
     124 *      - 'Required' - Minimum required WordPress version.
     125 *      - 'Tested' - Higher WordPress version this plugin has been tested.
     126 *      - 'Stable' - Last stable tag when this was released.
     127 *     
     128 * The first 8kiB of the file will be pulled in and if the readme data is not
     129 * within that first 8kiB, then the plugin author should correct their plugin
     130 * and move the plugin data headers to the top.
     131 *
     132 * The readme file is assumed to have permissions to allow for scripts to read
     133 * the file. This is not checked however and the file is only opened for
     134 * reading.
     135 *
     136 * @param string $plugin_file Path to the plugin file (not the readme file)
     137 * @return array See above for description.
     138 */
     139function get_plugin_readme_data( $plugin_file ) {
     140       
     141        $file = dirname($plugin_file) . '/readme.txt';
     142       
     143        $fp = fopen($file, 'r');        // Open just for reading.
     144        $data = fread( $fp, 8192 );     // Pull the first 8kiB of the file in.
     145        fclose($fp);                            // Close the file.     
     146
     147        preg_match( '|Contributors:(.*)$|mi', $data, $contributors );
     148        preg_match( '|Donate link:(.*)$|mi', $data, $uri );
     149        preg_match( '|Tags:(.*)|i', $data, $tags );
     150        preg_match( '|Requires at least:(.*)$|mi', $data, $required );
     151        preg_match( '|Tested up to:(.*)$|mi', $data, $tested );
     152        preg_match( '|Stable tag:(.*)$|mi', $data, $stable );
     153
     154        foreach ( array( 'contributors', 'uri', 'tags', 'required', 'tested', 'stable' ) as $field ) {
     155                if ( !empty( ${$field} ) ) {
     156                        ${$field} = trim(${$field}[1]);
     157                } else {
     158                        ${$field} = '';
     159                }
     160        }
     161
     162        $readme_data = array(   
     163                'Contributors' => array_map('trim', explode(',', $contributors)),
     164                'Tags' => array_map('trim', explode(',', $tags)),
     165                'DonateURI' => trim($uri),
     166                'Requires' => trim($required),
     167                'Tested' => trim($tested),
     168                'Stable' => trim($stable) );
     169
     170        return $readme_data;
     171}
     172
    105173function _get_plugin_data_markup_translate($plugin_data, $markup = true, $translate = true) {
    106174
    107175        //Translate fields