PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

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          $result = activate_plugin($_GET['plugin']);
   8          if( is_wp_error( $result ) )
   9              wp_die( $result->get_error_message() );
  10          wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
  11      } elseif ('error_scrape' == $_GET['action']) {
  12          $plugin = trim($_GET['plugin']);
  13          check_admin_referer('plugin-activation-error_' . $plugin);
  14          if ( validate_file($plugin) )
  15              wp_die(__('Invalid plugin.'));
  16          if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
  17              wp_die(__('Plugin file does not exist.'));
  18          include(ABSPATH . PLUGINDIR . '/' . $plugin);
  19      } elseif ('deactivate' == $_GET['action']) {
  20          check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
  21          deactivate_plugins($_GET['plugin']);
  22          wp_redirect('plugins.php?deactivate=true');
  23      } elseif ($_GET['action'] == 'deactivate-all') {
  24          check_admin_referer('deactivate-all');
  25          deactivate_all_plugins();
  26          wp_redirect('plugins.php?deactivate-all=true');
  27      }
  28      exit;
  29  }
  30  
  31  $title = __('Manage Plugins');
  32  require_once ('admin-header.php');
  33  
  34  // Clean up options
  35  // If any plugins don't exist, axe 'em
  36  
  37  $check_plugins = get_option('active_plugins');
  38  
  39  // Sanity check.  If the active plugin list is not an array, make it an
  40  // empty array.
  41  if ( !is_array($check_plugins) ) {
  42      $check_plugins = array();
  43      update_option('active_plugins', $check_plugins);
  44  }
  45  
  46  // If a plugin file does not exist, remove it from the list of active
  47  // plugins.
  48  foreach ($check_plugins as $check_plugin) {
  49      if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) {
  50              $current = get_option('active_plugins');
  51              $key = array_search($check_plugin, $current);
  52              if ( false !== $key && NULL !== $key ) {
  53                  unset($current[$key]);
  54                  update_option('active_plugins', $current);
  55              }
  56      }
  57  }
  58  ?>
  59  
  60  <?php if ( isset($_GET['error']) ) : ?>
  61      <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
  62      <?php
  63          $plugin = trim($_GET['plugin']);
  64          if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) && 1 == strtolower(ini_get('display_errors'))) { ?>
  65      <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo attribute_escape($plugin); ?>&amp;_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>
  66      <?php
  67          }
  68      ?>
  69      </div>
  70  <?php elseif ( isset($_GET['activate']) ) : ?>
  71      <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
  72  <?php elseif ( isset($_GET['deactivate']) ) : ?>
  73      <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
  74  <?php elseif (isset($_GET['deactivate-all'])) : ?>
  75      <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div>
  76  <?php endif; ?>
  77  
  78  <div class="wrap">
  79  <h2><?php _e('Plugin Management'); ?></h2>
  80  <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>
  81  <?php
  82  
  83  if ( get_option('active_plugins') )
  84      $current_plugins = get_option('active_plugins');
  85  
  86  $plugins = get_plugins();
  87  
  88  if (empty($plugins)) {
  89      echo '<p>';
  90      _e("Couldn&#8217;t open plugins directory or there are no plugins available."); // TODO: make more helpful
  91      echo '</p>';
  92  } else {
  93  ?>
  94  <table class="widefat plugins">
  95      <thead>
  96      <tr>
  97          <th><?php _e('Plugin'); ?></th>
  98          <th style="text-align: center"><?php _e('Version'); ?></th>
  99          <th><?php _e('Description'); ?></th>
 100          <th style="text-align: center"<?php if ( current_user_can('edit_plugins') ) echo ' colspan="2"'; ?>><?php _e('Action'); ?></th>
 101      </tr>
 102      </thead>
 103  <?php
 104      $style = '';
 105  
 106      foreach($plugins as $plugin_file => $plugin_data) {
 107          $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate';
 108  
 109          if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
 110              $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>";
 111              $plugin_data['Title'] = "<strong>{$plugin_data['Title']}</strong>";
 112              $style .= $style == 'alternate' ? ' active' : 'active';
 113          } else {
 114              $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>";
 115          }
 116  
 117          $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
 118  
 119          // Sanitize all displayed data
 120          $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
 121          $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
 122          $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
 123          $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
 124  
 125          if ( $style != '' )
 126              $style = 'class="' . $style . '"';
 127          if ( is_writable(ABSPATH . PLUGINDIR . '/' . $plugin_file) )
 128              $edit = "<a href='plugin-editor.php?file=$plugin_file' title='".__('Open this file in the Plugin Editor')."' class='edit'>".__('Edit')."</a>";
 129          else
 130              $edit = '';
 131  
 132          $author = ( empty($plugin_data['Author']) ) ? '' :  ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
 133  
 134          echo "
 135      <tr $style>
 136          <td class='name'>{$plugin_data['Title']}</td>
 137          <td class='vers'>{$plugin_data['Version']}</td>
 138          <td class='desc'><p>{$plugin_data['Description']}$author</p></td>
 139          <td class='togl'>$toggle</td>";
 140          if ( current_user_can('edit_plugins') )
 141          echo "
 142          <td>$edit</td>";
 143          echo"
 144      </tr>";
 145      do_action( 'after_plugin_row', $plugin_file );
 146      }
 147  ?>
 148  
 149  <tr>
 150      <td colspan="3">&nbsp;</td>
 151      <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>
 152  </tr>
 153  
 154  </table>
 155  <?php
 156  }
 157  ?>
 158  
 159  <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>
 160  
 161  <h2><?php _e('Get More Plugins'); ?></h2>
 162  <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>
 163  <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>
 164  
 165  </div>
 166  
 167  <?php
 168  include ('admin-footer.php');
 169  ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt