PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/2.2/wp-admin/plugins.php

#
PHP | 173 lines | 141 code | 25 blank | 7 comment | 29 complexity | 4bb5519521836b6b6ee45afcdf7e0baf MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. require_once('admin.php');
  3. if ( isset($_GET['action']) ) {
  4. if ('activate' == $_GET['action']) {
  5. check_admin_referer('activate-plugin_' . $_GET['plugin']);
  6. $current = get_option('active_plugins');
  7. $plugin = trim($_GET['plugin']);
  8. if ( validate_file($plugin) )
  9. wp_die(__('Invalid plugin.'));
  10. if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
  11. wp_die(__('Plugin file does not exist.'));
  12. if (!in_array($plugin, $current)) {
  13. wp_redirect('plugins.php?error=true'); // we'll override this later if the plugin can be included without fatal error
  14. ob_start();
  15. @include(ABSPATH . PLUGINDIR . '/' . $plugin);
  16. $current[] = $plugin;
  17. sort($current);
  18. update_option('active_plugins', $current);
  19. do_action('activate_' . $plugin);
  20. ob_end_clean();
  21. }
  22. wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
  23. } else if ('deactivate' == $_GET['action']) {
  24. check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
  25. $current = get_option('active_plugins');
  26. array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu!
  27. update_option('active_plugins', $current);
  28. do_action('deactivate_' . trim( $_GET['plugin'] ));
  29. wp_redirect('plugins.php?deactivate=true');
  30. } elseif ($_GET['action'] == 'deactivate-all') {
  31. check_admin_referer('deactivate-all');
  32. $current = get_option('active_plugins');
  33. foreach ($current as $plugin) {
  34. array_splice($current, array_search($plugin, $current), 1);
  35. do_action('deactivate_' . $plugin);
  36. }
  37. update_option('active_plugins', array());
  38. wp_redirect('plugins.php?deactivate-all=true');
  39. }
  40. exit;
  41. }
  42. $title = __('Manage Plugins');
  43. require_once('admin-header.php');
  44. // Clean up options
  45. // If any plugins don't exist, axe 'em
  46. $check_plugins = get_option('active_plugins');
  47. // Sanity check. If the active plugin list is not an array, make it an
  48. // empty array.
  49. if ( !is_array($check_plugins) ) {
  50. $check_plugins = array();
  51. update_option('active_plugins', $check_plugins);
  52. }
  53. // If a plugin file does not exist, remove it from the list of active
  54. // plugins.
  55. foreach ($check_plugins as $check_plugin) {
  56. if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) {
  57. $current = get_option('active_plugins');
  58. $key = array_search($check_plugin, $current);
  59. if ( false !== $key && NULL !== $key ) {
  60. unset($current[$key]);
  61. update_option('active_plugins', $current);
  62. }
  63. }
  64. }
  65. ?>
  66. <?php if ( isset($_GET['error']) ) : ?>
  67. <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p></div>
  68. <?php elseif ( isset($_GET['activate']) ) : ?>
  69. <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
  70. <?php elseif ( isset($_GET['deactivate']) ) : ?>
  71. <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
  72. <?php elseif (isset($_GET['deactivate-all'])) : ?>
  73. <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div>
  74. <?php endif; ?>
  75. <div class="wrap">
  76. <h2><?php _e('Plugin Management'); ?></h2>
  77. <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>
  78. <?php
  79. if ( get_option('active_plugins') )
  80. $current_plugins = get_option('active_plugins');
  81. $plugins = get_plugins();
  82. if (empty($plugins)) {
  83. echo '<p>';
  84. _e("Couldn&#8217;t open plugins directory or there are no plugins available."); // TODO: make more helpful
  85. echo '</p>';
  86. } else {
  87. ?>
  88. <table class="widefat plugins">
  89. <thead>
  90. <tr>
  91. <th><?php _e('Plugin'); ?></th>
  92. <th style="text-align: center"><?php _e('Version'); ?></th>
  93. <th><?php _e('Description'); ?></th>
  94. <th style="text-align: center"<?php if ( current_user_can('edit_plugins') ) echo ' colspan="2"'; ?>><?php _e('Action'); ?></th>
  95. </tr>
  96. </thead>
  97. <?php
  98. $style = '';
  99. foreach($plugins as $plugin_file => $plugin_data) {
  100. $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate';
  101. if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
  102. $toggle = "<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>";
  103. $plugin_data['Title'] = "<strong>{$plugin_data['Title']}</strong>";
  104. $style .= $style == 'alternate' ? ' active' : 'active';
  105. } else {
  106. $toggle = "<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>";
  107. }
  108. $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
  109. // Sanitize all displayed data
  110. $plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags);
  111. $plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags);
  112. $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
  113. $plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags);
  114. if ( $style != '' )
  115. $style = 'class="' . $style . '"';
  116. if ( is_writable(ABSPATH . PLUGINDIR . '/' . $plugin_file) )
  117. $edit = "<a href='plugin-editor.php?file=$plugin_file' title='".__('Open this file in the Plugin Editor')."' class='edit'>".__('Edit')."</a>";
  118. else
  119. $edit = '';
  120. echo "
  121. <tr $style>
  122. <td class='name'>{$plugin_data['Title']}</td>
  123. <td class='vers'>{$plugin_data['Version']}</td>
  124. <td class='desc'><p>{$plugin_data['Description']} <cite>".sprintf(__('By %s'), $plugin_data['Author']).".</cite></p></td>
  125. <td class='togl'>$toggle</td>";
  126. if ( current_user_can('edit_plugins') )
  127. echo "
  128. <td>$edit</td>";
  129. echo"
  130. </tr>";
  131. }
  132. ?>
  133. <tr>
  134. <td colspan="3">&nbsp;</td>
  135. <td colspan="2" style="width:12em;"><a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a></td>
  136. </tr>
  137. </table>
  138. <?php
  139. }
  140. ?>
  141. <p><?php printf(__('If something goes wrong with a plugin and you can&#8217;t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated.'), PLUGINDIR); ?></p>
  142. <h2><?php _e('Get More Plugins'); ?></h2>
  143. <p><?php _e('You can find additional plugins for your site in the <a href="http://wordpress.org/extend/plugins/">WordPress plugin directory</a>.'); ?></p>
  144. <p><?php printf(__('To install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory. Once a plugin is uploaded, you may activate it here.'), PLUGINDIR); ?></p>
  145. </div>
  146. <?php
  147. include('admin-footer.php');
  148. ?>