Search moodle.org's
Developer Documentation

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
  • Differences Between: [Versions 310 and 34] [Versions 310 and 35] [Versions 310 and 36] [Versions 34 and 310] [Versions 35 and 310] [Versions 36 and 310] [Versions 37 and 310]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  /**
      18   * Generic plugin config manipulation script.
      19   *
      20   * @package    admin
      21   * @copyright  2017 Andrew Nicols <andrew@nicols.co.uk>
      22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      23   */
      24  
      25  define('NO_OUTPUT_BUFFERING', true);
      26  
      27  require_once('../config.php');
      28  require_once($CFG->libdir.'/adminlib.php');
      29  
      30  $action  = required_param('action', PARAM_ALPHANUMEXT);
      31  $plugin  = required_param('plugin', PARAM_PLUGIN);
      32  $type    = required_param('type', PARAM_PLUGIN);
      33  
      34  $PAGE->set_url('/admin/updatesetting.php');
      35  $PAGE->set_context(context_system::instance());
      36  
      37  require_admin();
      38  require_sesskey();
      39  
      40  $plugintypeclass = "\\core\\plugininfo\\{$type}";
      41  
      42  $plugins = \core_plugin_manager::instance()->get_plugins_of_type($type);
      43  $sortorder = array_values($plugintypeclass::get_enabled_plugins());
      44  
      45  $return = $plugintypeclass::get_manage_url();
      46  
      47  if (!array_key_exists($plugin, $plugins)) {
      48      redirect($return);
      49  }
      50  
      51  switch ($action) {
      52      case 'disable':
      53          $plugins[$plugin]->set_enabled(false);
      54          break;
      55  
      56      case 'enable':
      57          $plugins[$plugin]->set_enabled(true);
      58          break;
      59  
      60      case 'up':
      61          if (($pos = array_search($plugin, $sortorder)) > 0) {
      62              $tmp = $sortorder[$pos - 1];
      63              $sortorder[$pos - 1] = $sortorder[$pos];
      64              $sortorder[$pos] = $tmp;
      65              $plugintypeclass::set_enabled_plugins($sortorder);
      66          }
      67          break;
      68  
      69      case 'down':
      70          if ((($pos = array_search($plugin, $sortorder)) !== false) && ($pos < count($sortorder) - 1)) {
      71              $tmp = $sortorder[$pos + 1];
      72              $sortorder[$pos + 1] = $sortorder[$pos];
      73              $sortorder[$pos] = $tmp;
      74              $plugintypeclass::set_enabled_plugins($sortorder);
      75          }
      76          break;
      77  }
      78  
      79  redirect($return);