The function local_template_import_before_standard_top_of_body_html() is executed on every single page load. It is essential that is performs effectively without adding unnecessary load to the server.
For that reason, I would suggest to re-order the early-exit checks so that first are evaluated those that do not need any further processing. For example the if (!strpos($PAGE->url, '/course/view.php')) should be evaluated as a very first one probably, followed by the $COURSE->id check and only then checks involving the capabilities.
Additionally, you may consider to display the popup only if the editing mode is enabled, effectively checking for $PAGE->user_is_editing().
The function
local_template_import_before_standard_top_of_body_html()is executed on every single page load. It is essential that is performs effectively without adding unnecessary load to the server.For that reason, I would suggest to re-order the early-exit checks so that first are evaluated those that do not need any further processing. For example the
if (!strpos($PAGE->url, '/course/view.php'))should be evaluated as a very first one probably, followed by the$COURSE->idcheck and only then checks involving the capabilities.Additionally, you may consider to display the popup only if the editing mode is enabled, effectively checking for
$PAGE->user_is_editing().