[ Index ]

WordPress Source Cross Reference

title

Body

[close]

/wp-admin/ -> plugins.php (source)

   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 class="widefat">
  82      <thead>
  83      <tr>
  84          <th style="text-align: left"><?php _e('Plugin'); ?></th>
  85          <th><?php _e('Version'); ?></th>
  86          <th style="text-align: left"><?php _e('Description'); ?></th>
  87          <th><?php _e('Action'); ?></th>
  88      </tr>
  89      </thead>
  90  <?php
  91      $style = '';
  92  
  93  	function sort_plugins($plug1, $plug2) {
  94          return strnatcasecmp($plug1['Name'], $plug2['Name']);
  95      }
  96  
  97      uksort($plugins, 'sort_plugins');
  98  
  99      foreach($plugins as $plugin_file => $plugin_data) {
 100          $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate';
 101  
 102          if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
 103              $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>";
 104              $plugin_data['Title'] = "<strong>{$plugin_data['Title']}</strong>";
 105              $style .= $style == 'alternate' ? ' active' : 'active';
 106          } else {
 107              $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>";
 108          }
 109          $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()) ); ;
 110          if ($style != '') $style = 'class="' . $style . '"';
 111          echo "
 112      <tr $style>
 113          <td class='name'>{$plugin_data['Title']}</td>
 114          <td class='vers'>{$plugin_data['Version']}</td>
 115          <td class='desc'>{$plugin_data['Description']} <cite>".sprintf(__('By %s'), $plugin_data['Author']).".</cite></td>
 116          <td class='togl'>$action</td>
 117      </tr>";
 118      }
 119  ?>
 120  
 121  </table>
 122  <?php
 123  }
 124  ?>
 125  
 126  <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>
 127  
 128  <h2><?php _e('Get More Plugins'); ?></h2>
 129  <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>
 130  
 131  </div>
 132  
 133  <?php
 134  include ('admin-footer.php');
 135  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sat Jul 15 11:57:04 2006 Courtesy of Taragana