]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/plugins.php
Wordpress 2.0.4
[autoinstalls/wordpress.git] / wp-admin / plugins.php
1 <?php
2 require_once('admin.php');
3
4 if ( isset($_GET['action']) ) {
5         if ('activate' == $_GET['action']) {
6                 check_admin_referer('activate-plugin_' . $_GET['plugin']);
7                 $current = get_settings('active_plugins');
8                 if (!in_array($_GET['plugin'], $current)) {
9                         $current[] = trim( $_GET['plugin'] );
10                         sort($current);
11                         update_option('active_plugins', $current);
12                         include(ABSPATH . 'wp-content/plugins/' . trim( $_GET['plugin'] ));
13                         do_action('activate_' . trim( $_GET['plugin'] ));
14                 }
15                 wp_redirect('plugins.php?activate=true');
16         } else if ('deactivate' == $_GET['action']) {
17                 check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
18                 $current = get_settings('active_plugins');
19                 array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu!
20                 update_option('active_plugins', $current);
21                 do_action('deactivate_' . trim( $_GET['plugin'] ));
22                 wp_redirect('plugins.php?deactivate=true');
23         }
24         exit;
25 }
26
27 $title = __('Manage Plugins');
28 require_once('admin-header.php');
29
30 // Clean up options
31 // If any plugins don't exist, axe 'em
32
33 $check_plugins = get_settings('active_plugins');
34
35 // Sanity check.  If the active plugin list is not an array, make it an
36 // empty array.
37 if ( !is_array($check_plugins) ) {
38         $check_plugins = array();
39         update_option('active_plugins', $check_plugins);        
40 }
41
42 // If a plugin file does not exist, remove it from the list of active
43 // plugins.
44 foreach ($check_plugins as $check_plugin) {
45         if (!file_exists(ABSPATH . 'wp-content/plugins/' . $check_plugin)) {
46                         $current = get_settings('active_plugins');
47                         $key = array_search($check_plugin, $current);
48                         if ( false !== $key && NULL !== $key ) {
49                                 unset($current[$key]);
50                                 update_option('active_plugins', $current);
51                         }
52         }
53 }
54 ?>
55
56 <?php if (isset($_GET['activate'])) : ?>
57 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p>
58 </div>
59 <?php endif; ?>
60 <?php if (isset($_GET['deactivate'])) : ?>
61 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p>
62 </div>
63 <?php endif; ?>
64
65 <div class="wrap">
66 <h2><?php _e('Plugin Management'); ?></h2>
67 <p><?php _e('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.'); ?></p>
68 <?php
69
70 if ( get_settings('active_plugins') )
71         $current_plugins = get_settings('active_plugins');
72
73 $plugins = get_plugins();
74
75 if (empty($plugins)) {
76         echo '<p>';
77         _e("Couldn't open plugins directory or there are no plugins available."); // TODO: make more helpful
78         echo '</p>';
79 } else {
80 ?>
81 <table width="100%" cellpadding="3" cellspacing="3">
82         <tr>
83                 <th><?php _e('Plugin'); ?></th>
84                 <th><?php _e('Version'); ?></th>
85                 <th><?php _e('Description'); ?></th>
86                 <th><?php _e('Action'); ?></th>
87         </tr>
88 <?php
89         $style = '';
90
91         function sort_plugins($plug1, $plug2) {
92                 return strnatcasecmp($plug1['Name'], $plug2['Name']);
93         }
94         
95         uksort($plugins, 'sort_plugins');
96
97         foreach($plugins as $plugin_file => $plugin_data) {
98                 $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate';
99
100                 if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
101                         $action = "<a href='" . wp_nonce_url("plugins.php?action=deactivate&amp;plugin=$plugin_file", 'deactivate-plugin_' . $plugin_file) . "' title='".__('Deactivate this plugin')."' class='delete'>".__('Deactivate')."</a>";
102                         $plugin_data['Title'] = "<strong>{$plugin_data['Title']}</strong>";
103                         $style .= $style == 'alternate' ? ' active' : 'active';
104                 } else {
105                         $action = "<a href='" . wp_nonce_url("plugins.php?action=activate&amp;plugin=$plugin_file", 'activate-plugin_' . $plugin_file) . "' title='".__('Activate this plugin')."' class='edit'>".__('Activate')."</a>";
106                 }
107                 $plugin_data['Description'] = wp_kses($plugin_data['Description'], array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()) ); ;
108                 if ($style != '') $style = 'class="' . $style . '"';
109                 echo "
110         <tr $style>
111                 <td class='name'>{$plugin_data['Title']}</td>
112                 <td class='vers'>{$plugin_data['Version']}</td>
113                 <td class='desc'>{$plugin_data['Description']} <cite>".sprintf(__('By %s'), $plugin_data['Author']).".</cite></td>
114                 <td class='togl'>$action</td>
115         </tr>";
116         }
117 ?>
118
119 </table>
120 <?php
121 }
122 ?>
123
124 <p><?php _e('If something goes wrong with a plugin and you can&#8217;t use WordPress, delete or rename that file in the <code>wp-content/plugins</code> directory and it will be automatically deactivated.'); ?></p>
125
126 <h2><?php _e('Get More Plugins'); ?></h2>
127 <p><?php _e('You can find additional plugins for your site in the <a href="http://wordpress.org/extend/plugins/">WordPress plugin directory</a>. To install a plugin you generally just need to upload the plugin file into your <code>wp-content/plugins</code> directory. Once a plugin is uploaded, you may activate it here.'); ?></p>
128
129 </div>
130
131 <?php
132 include('admin-footer.php');
133 ?>