WordPress.org

Make WordPress Core

Ticket #9532: 9532.diff

File 9532.diff, 3.2 KB (added by Denis-de-Bernardy, 9 years ago)
  • 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 * @since 2.8
     137 *
     138 * @param string $plugin_file Path to the plugin file (not the readme file)
     139 * @return array See above for description, or false on failure
     140 */
     141function get_plugin_readme_data( $plugin_file ) {
     142        $dir = dirname($plugin_file);
     143        if ( $dir === WP_PLUGIN_DIR )
     144                return false;
     145
     146        $file = "$dir/readme.txt";
     147        if ( !is_file($file) )
     148                return false;
     149
     150        $fp = fopen($file, 'r');                // Open just for reading.
     151        if ( !$fp )
     152                return false;
     153
     154        $data = fread( $fp, 8192 );             // Pull the first 8kiB of the file in.
     155        fclose($fp);                                    // Close the file.     
     156
     157        preg_match( '|Contributors:(.*)$|mi', $data, $contributors );
     158        preg_match( '|Donate link:(.*)$|mi', $data, $donate_uri );
     159        preg_match( '|Tags:(.*)|i', $data, $tags );
     160        preg_match( '|Requires at least:(.*)$|mi', $data, $required );
     161        preg_match( '|Tested up to:(.*)$|mi', $data, $tested );
     162        preg_match( '|Stable tag:(.*)$|mi', $data, $stable );
     163
     164        foreach ( array( 'contributors', 'donate_uri', 'tags', 'required', 'tested', 'stable' ) as $field ) {
     165                if ( !empty( ${$field} ) ) {
     166                        ${$field} = _cleanup_header_comment(${$field}[1]);
     167                } else {
     168                        ${$field} = '';
     169                }
     170        }
     171
     172        $readme_data = array(   
     173                'Contributors' => array_map('trim', explode(',', $contributors)),
     174                'Tags' => array_map('trim', explode(',', $tags)),
     175                'Donate URI' => trim($donate_uri),
     176                'Requires' => trim($required),
     177                'Tested' => trim($tested),
     178                'Stable' => trim($stable),
     179        );
     180
     181        return $readme_data;
     182}
     183
    105184function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) {
    106185
    107186        //Translate fields