WordPress.org

Make WordPress Core

Changeset 1887


Ignore:
Timestamp:
11/26/2004 02:29:45 AM (13 years ago)
Author:
rboren
Message:

get_plugin_data() and get_plugins()

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r1886 r1887  
    840840}
    841841
     842function get_plugin_data($plugin_file) {
     843    $plugin_data = implode('', file($plugin_file));
     844    preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
     845    preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
     846    preg_match("|Description:(.*)|i", $plugin_data, $description);
     847    preg_match("|Author:(.*)|i", $plugin_data, $author_name);
     848    preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
     849    if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
     850        $version = $version[1];
     851    else
     852        $version ='';
     853
     854    $description = wptexturize($description[1]);
     855
     856    $name = $plugin_name[1];
     857    $name = trim($name);
     858    $plugin = $name;
     859    if ('' != $plugin_uri[1] && '' != $name) {
     860        $plugin = __("<a href='{$plugin_uri[1]}' title='Visit plugin homepage'>{$plugin}</a>");
     861    }
     862
     863    if ('' == $author_uri[1]) {
     864        $author = $author_name[1];
     865    } else {
     866        $author = __("<a href='{$author_uri[1]}' title='Visit author homepage'>{$author_name[1]}</a>");
     867    }
     868
     869    return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
     870}
     871
     872function get_plugins() {
     873    global $wp_plugins;
     874
     875    if (isset($wp_plugins)) {
     876        return $wp_plugins;
     877    }
     878
     879    $wp_plugins = array();
     880    $plugin_loc = 'wp-content/plugins';
     881    $plugin_root = ABSPATH . $plugin_loc;
     882
     883    // Files in wp-content/plugins directory
     884    $plugins_dir = @ dir($plugin_root);
     885    if ($plugins_dir) {
     886        while(($file = $plugins_dir->read()) !== false) {
     887            if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
     888                $plugin_files[] = $file;
     889        }
     890    }
     891
     892    if (!$plugins_dir || !$plugin_files) {
     893        return $wp_plugins;
     894    }
     895
     896    sort($plugin_files);
     897
     898    foreach($plugin_files as $plugin_file) {
     899        $plugin_data = get_plugin_data("$plugin_root/$plugin_file");
     900     
     901        if (empty($plugin_data['Name'])) {
     902            continue;
     903        }
     904
     905        $wp_plugins[basename($plugin_file)] = $plugin_data;
     906    }
     907
     908    return $wp_plugins;
     909}
     910
    842911?>
  • trunk/wp-admin/plugins.php

    r1818 r1887  
    5252<p><?php _e('Plugins are files you usually download separately from WordPress that add functionality. To install a plugin you generally just need to put the plugin file into your <code>wp-content/plugins</code> directory. Once a plugin is installed, you may activate it or deactivate it here. If something goes wrong with a plugin and you can&#8217;t use WordPress, delete that plugin from the <code>wp-content/plugins</code> directory and it will be automatically deactivated.'); ?></p>
    5353<?php
    54 // Files in wp-content/plugins directory
    55 $plugins_dir = @ dir(ABSPATH . 'wp-content/plugins');
    56 if ($plugins_dir) {
    57     while(($file = $plugins_dir->read()) !== false) {
    58       if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
    59         $plugin_files[] = $file;
    60     }
    61 }
    6254
    6355if ( get_settings('active_plugins') )
    6456    $current_plugins = get_settings('active_plugins');
    6557
    66 if (!$plugins_dir || !$plugin_files) {
     58$plugins = get_plugins();
     59
     60if (empty($plugins)) {
    6761    _e("<p>Couldn't open plugins directory or there are no plugins available.</p>"); // TODO: make more helpful
    6862} else {
     
    7771    </tr>
    7872<?php
    79     sort($plugin_files); // Alphabetize by filename. Better way?
    8073    $style = '';
    81     foreach($plugin_files as $plugin_file) {
    82         $plugin_data = implode('', file(ABSPATH . '/wp-content/plugins/' . $plugin_file));
    83         preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
    84         preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
    85         preg_match("|Description:(.*)|i", $plugin_data, $description);
    86         preg_match("|Author:(.*)|i", $plugin_data, $author_name);
    87         preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
    88         if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
    89             $version = $version[1];
    90         else
    91             $version ='';
    92 
    93         $description = wptexturize($description[1]);
    94 
    95         if ('' == $plugin_uri) {
    96             $plugin = $plugin_name[1];
    97         } else {
    98             $plugin = __("<a href='{$plugin_uri[1]}' title='Visit plugin homepage'>{$plugin_name[1]}</a>");
    99         }
    100 
    101         if ('' == $author_uri) {
    102             $author = $author_name[1];
    103         } else {
    104             $author = __("<a href='{$author_uri[1]}' title='Visit author homepage'>{$author_name[1]}</a>");
    105         }
    106 
    107 
    108 
     74    foreach($plugins as $plugin_file => $plugin_data) {
    10975        $style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
    11076
     
    11783        echo "
    11884    <tr $style>
    119         <td>$plugin</td>
    120         <td>$version</td>
    121         <td>$author</td>
    122         <td>$description</td>
     85        <td>{$plugin_data['Title']}</td>
     86        <td>{$plugin_data['Version']}</td>
     87        <td>{$plugin_data['Author']}</td>
     88        <td>{$plugin_data['Description']}</td>
    12389        <td>$action</td>
    12490    </tr>";
Note: See TracChangeset for help on using the changeset viewer.