Hook that's called on every moodle page

Re: Hook that's called on every moodle page

by Mark Sharp -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
There is the `page_init` callback, but this can't be used in local plugins. But you could use `extend_navigation`, and though it's primary use is to extend navigation, by this time all the relevant global settings have been initialised ($PAGE, $USER etc)

  1. In your plugin add a lib.php file.
  2. Assuming your plugin is a local plugin called myplugin, create the function local_myplugin_extend_navigation(global_navigation $nav)
  3. Do your stuff. You don't actually have to do anything with the navigation.

There's a bit about this in the /local/readme.txt file.

Don't use this if you're intending to output html.

If you want to catch events, then you need event observers: https://moodledev.io/general/development/policies/component-communication#event-observers. To view the list of events available go to /report/eventlist/index.php

Average of ratings: Useful (2)