diff --git a/admin/filters.php b/admin/filters.php index 958fc6e16ca..a79c2ecf617 100644 --- a/admin/filters.php +++ b/admin/filters.php @@ -72,10 +72,8 @@ switch ($action) { case 'setstate': if (isset($filters[$filterpath]) and $newstate = optional_param('newstate', '', PARAM_INT)) { - filter_set_global_state($filterpath, $newstate); - if ($newstate == TEXTFILTER_DISABLED) { - filter_set_applies_to_strings($filterpath, false); - } + $class = \core_plugin_manager::resolve_plugininfo_class('filter'); + $class::enable_plugin($filterpath, $newstate); } break; @@ -83,12 +81,16 @@ switch ($action) { if (isset($filters[$filterpath])) { $applytostrings = optional_param('stringstoo', false, PARAM_BOOL); filter_set_applies_to_strings($filterpath, $applytostrings); + reset_text_filters_cache(); + core_plugin_manager::reset_caches(); } break; case 'down': if (isset($filters[$filterpath])) { filter_set_global_state($filterpath, $filters[$filterpath]->active, 1); + reset_text_filters_cache(); + core_plugin_manager::reset_caches(); } break; @@ -96,14 +98,14 @@ switch ($action) { if (isset($filters[$filterpath])) { $oldpos = $filters[$filterpath]->sortorder; filter_set_global_state($filterpath, $filters[$filterpath]->active, -1); + reset_text_filters_cache(); + core_plugin_manager::reset_caches(); } break; } -// Reset caches and return. +// Return. if ($action) { - reset_text_filters_cache(); - core_plugin_manager::reset_caches(); redirect(new moodle_url('/admin/filters.php')); } diff --git a/lib/classes/plugininfo/filter.php b/lib/classes/plugininfo/filter.php index 1921a96fc46..a9dcc47b381 100644 --- a/lib/classes/plugininfo/filter.php +++ b/lib/classes/plugininfo/filter.php @@ -58,6 +58,32 @@ class filter extends base { return $enabled; } + /** + * Enable or disable a plugin. + * When possible, the change will be stored into the config_log table, to let admins check when/who has modified it. + * + * @param string $pluginname The plugin name to enable/disable. + * @param int $enabled Whether the pluginname should be TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_DISABLED. + * + * @return bool It always return true because we don't know if the value has changed or not. That way, we guarantee any action + * required if it's changed will be executed. + */ + public static function enable_plugin(string $pluginname, int $enabled): bool { + global $CFG; + require_once("$CFG->libdir/filterlib.php"); + require_once("$CFG->libdir/weblib.php"); + + filter_set_global_state($pluginname, $enabled); + if ($enabled == TEXTFILTER_DISABLED) { + filter_set_applies_to_strings($filterpath, false); + } + + reset_text_filters_cache(); + \core_plugin_manager::reset_caches(); + + return true; + } + public function get_settings_section_name() { return 'filtersetting' . $this->name; }