I'm new to moodle plugin development and am trying to create a plugin that displays a page to the admin where I can add my on php code.
In brief, what I want the plugin to do I have already achieved in a standard php file that I upload to the moodle root. From here you can call the file e.g. yourdomain.co.uk/moodlelocation/myfile.php and it will run as expected.
The problem with this is it isn't secure since anyone can load the myfile.php and in turn run the scripts on the page. It also means any one else using this script (it will be given away for free when complete) would need to FTP into their hosting and upload two php files to their moodle install.
Due to this, I thought a plugin (a very very basic plugin) may be the best solution. They could then load the page in the admin via the "site administration". e.g. site administration > Development > MyPlugin. I am assuming I could then also restrict the plugin's main page to admins only (??).
So to recap, I can create a php page that has my script all rocking and rolling BUT I need to make this into a plugin.
I did some reading and I think a "local" plugin was the easiest way to go (??).
I have managed to get the local plugin up and running using the below in local/webguides/inex.php :
// Standard config file and local library.
require_once(__DIR__ . '/../../config.php');
// Setting up the page.
// Ouput the page header.
echo 'MY php CODE here etc';
This works fine but with two problems:
- Anyone can access it via http://domain.com/local/webguides/index.php
- There is no link to it in the site administration (so the user would need to type the URL in).
Can anyone shed any light how I would achieve the two steps above?
Thanks in advance