Make WordPress Core

Ticket #3047: 3047.r9125.diff

File 3047.r9125.diff, 2.9 KB (added by jacobsantos, 17 years ago)

Updated westi patch for r9125 and new get_plugin_data() function.

  • plugin.php

     
    9797}
    9898
    9999/**
     100 * Retrieve plugin data by name from plugin file.
     101 *
     102 * @since 2.7.0
     103 * @link http://trac.wordpress.org/ticket/3047 Reason for function.
     104 *
     105 * @param string $name Lowercase string of plugin data name.
     106 * @param string $file Plugin path for retrieving plugin info.
     107 * @return string
     108 */
     109function get_plugin_info($name, $file) {
     110        global $wp_active_plugins, $plugins_allowedtags;
     111
     112        if ( ! isset($wp_active_plugins) ) {
     113                $wp_active_plugins = array();
     114        }
     115
     116        $plugin_filename = plugin_basename($filename);
     117
     118        if ( ! isset($wp_active_plugins[$plugin_filename]) )
     119        {
     120                //Lazy Load the information
     121                $plugin_data = get_plugin_data($filename);
     122               
     123                $plugin_data['Title'] = $plugin_data['Name'];
     124                if ( !empty($plugin_data['PluginURI']) && !empty($plugin_data['Name']) )
     125                        $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="'.__( 'Visit plugin homepage' ).'">' . $plugin_data['Name'] . '</a>';
     126
     127                if ( ! empty($plugin_data['AuthorURI']) )
     128                        $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="'.__( 'Visit author homepage' ).'">' . $plugin_data['Author'] . '</a>';
     129
     130                $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
     131
     132                // Sanitize all displayed data
     133                $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
     134                $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
     135                $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
     136                $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
     137
     138                if( ! empty($plugin_data['Author']) )
     139                        $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
     140
     141                if ( ! empty($plugin_data['Name']) ) {
     142                        $wp_active_plugins[$plugin_filename] = $plugin_data;
     143                } else {
     144                        return '';
     145                }
     146        }
     147
     148        switch( $name ) {
     149                case 'url':
     150                        return $wp_active_plugins[$plugin_filename]['URL'];
     151                        break;
     152                case 'version':
     153                        return $wp_active_plugins[$plugin_filename]['Version'];
     154                        break;
     155                case 'name':
     156                        return $wp_active_plugins[$plugin_filename]['Name'];
     157                        break;
     158                case 'title':
     159                        return $wp_active_plugins[$plugin_filename]['Title'];
     160                        break;
     161                case 'description':
     162                        return $wp_active_plugins[$plugin_filename]['Description'];
     163                        break;
     164                case 'author':
     165                        return $wp_active_plugins[$plugin_filename]['Author'];
     166                        break;
     167                case 'authoruri':
     168                        return $wp_active_plugins[$plugin_filename]['AuthorURI'];
     169                        break;
     170                case 'pluginuri':
     171                        return $wp_active_plugins[$plugin_filename]['PluginURI'];
     172                        break;
     173        }
     174}
     175
     176/**
    100177 * Check the plugins directory and retrieve all plugin files with plugin data.
    101178 *
    102179 * WordPress only supports plugin files in the base plugins directory