Make WordPress Core


Ignore:
Timestamp:
08/09/2004 07:17:54 AM (22 years ago)
Author:
saxmatt
Message:

Use array storage for plugins list.

File:
1 edited

Legend:

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

    r1429 r1522  
    11<?php
    22
    3 if (isset($_GET['action'])) {
     3if ( isset($_GET['action']) ) {
    44        $standalone = 1;
    55        require_once('admin-header.php');
     
    88
    99        if ('activate' == $_GET['action']) {
    10                 $current = "\n" . get_settings('active_plugins') . "\n";
    11                 $current = preg_replace("|(\n)+\s*|", "\n", $current);
    12                 $current = trim($current) . "\n " . trim($_GET['plugin']);
    13                 $current = trim($current);
    14                 $current = preg_replace("|\n\s*|", "\n", $current); // I don't know where this is coming from
     10                $current = get_settings('active_plugins');
     11                $current[] = trim( $_GET['plugin'] );
     12                sort($current);
    1513                update_option('active_plugins', $current);
    1614                header('Location: plugins.php?activate=true');
     
    1816       
    1917        if ('deactivate' == $_GET['action']) {
    20                 $current = "\n" . get_settings('active_plugins') . "\n";
    21                 $current = str_replace("\n" . $_GET['plugin'], '', $current);
    22                 $current = preg_replace("|(\n)+\s*|", "\n", $current);
    23                 update_option('active_plugins', trim($current));
     18                $current = get_settings('active_plugins');
     19                array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu!
     20                update_option('active_plugins', $current);
    2421                header('Location: plugins.php?deactivate=true');
    2522        }
     
    3128
    3229if ($user_level < 9) // Must be at least level 9
    33         die (__("Sorry, you must be at least a level 8 user to modify plugins."));
     30        die (__('Sorry, you must be at least a level 8 user to modify plugins.'));
    3431
    3532// Clean up options
    36 // if any files are in the option that don't exist, axe 'em
     33// If any plugins don't exist, axe 'em
    3734
    38 $check_plugins = explode("\n", (get_settings('active_plugins')));
     35$check_plugins = get_settings('active_plugins');
    3936foreach ($check_plugins as $check_plugin) {
    4037        if (!file_exists(ABSPATH . 'wp-content/plugins/' . $check_plugin)) {
    41                         $current = get_settings('active_plugins') . "\n";
    42                         $current = str_replace($check_plugin . "\n", '', $current);
    43                         $current = preg_replace("|\n+|", "\n", $current);
    44                         update_option('active_plugins', trim($current));
     38                        $current = get_settings('active_plugins');
     39                        unset($current[$_GET['plugin']]);
     40                        update_option('active_plugins', $current);
    4541        }
    4642}
    47 
    48 
    49 
    5043?>
    5144
     
    6154<div class="wrap">
    6255<h2><?php _e('Plugin Management'); ?></h2>
    63 <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.'); ?></p>
     56<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>
    6457<?php
    6558// Files in wp-content/plugins directory
     
    7265}
    7366
    74 if ('' != trim(get_settings('active_plugins'))) {
    75         $current_plugins = explode("\n", (get_settings('active_plugins')));
    76 }
     67if ( get_settings('active_plugins') )
     68        $current_plugins = get_settings('active_plugins');
    7769
    7870if (!$plugins_dir || !$plugin_files) {
Note: See TracChangeset for help on using the changeset viewer.