0

Is there a way to override in a plugin a Moodle core function ?

For example, I would like to override the function get_max_upload_sizes that is called at /admin/settings/security.php:30. This function is located at /lib/moodlelib.php:6186.

In a more general way : what's the good practice when you need to perform that kind of stuff in Moodle (I don't want to hack the core file)?

ben.IT
  • 1,490
  • 2
  • 18
  • 37

1 Answers1

0

It depends a bit on the functionality you need. Since the mentioned function is part of the moodle core file, which is included over global config.php=>setup.php I see no direct way to change this function without touching the core.

Whats your intention behind the idea? Do you want to develop a plugin which allows uploads with larger filesizes? If so, you might try to modify the settings like ini_get('upload_max_filesize')) / ini_get('post_max_size')) during plugin usage, so that the core function will return the appropriate size

Bearzi
  • 538
  • 5
  • 18
  • I would like to change the value generated from this function for the admin part used at `/admin/settings.php?section=sitepolicies`. – ben.IT Mar 28 '17 at 07:28
  • At first glance I do not see a possibility to change the behaviour of this settings page with a plugin. If you don't want to touch the core you might consider writing a local plugin, which will allow you to set the setting there. But this would not affect the existing settings page, so everytime someone saves the original setting form your values will be overwritten. Or your clone the whole settings page into your plugin, and disallow usage of the original one, for example with a webserver redirect – Bearzi Mar 28 '17 at 07:55
  • I tried inside a local plugin to rewrite the function that I want to override but this causes a `Fatal error: Cannot redeclare get_max_upload_sizes() `. If overriding is not supported, I will stop here. – ben.IT Mar 28 '17 at 08:31
  • You may be able to override it *within a namespace* as described here: http://stackoverflow.com/a/12128017/708323 – Martin Greenaway Mar 29 '17 at 16:53